Skip to content

Commit bd2b906

Browse files
committed
test: add test for dynamic CSS imports
1 parent f4f57f5 commit bd2b906

File tree

11 files changed

+53
-3
lines changed

11 files changed

+53
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-remove-empty-scripts",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Webpack plugin removes empty JavaScript files generated when using styles.",
55
"keywords": [
66
"webpack",

package.npm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-remove-empty-scripts",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Webpack plugin removes empty JavaScript files generated when using styles.",
55
"keywords": [
66
"webpack",
@@ -23,7 +23,7 @@
2323
"url": "https://patreon.com/biodiscus"
2424
},
2525
"repository": "webdiscus/webpack-remove-empty-scripts",
26-
"main": "src/index.js",
26+
"main": "index.js",
2727
"engines": {
2828
"node": ">=12.14"
2929
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vendor {
2+
color: red;
3+
}

test/cases/css-import-dynamic/expected/main.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
html,
2+
body {
3+
width: 100%;
4+
height: 100%;
5+
}
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Note: for dynamic CSS imports, in addition to using RemoveEmptyScriptsPlugin(), you must specify webpackMode: "eager"
2+
import(/* webpackMode: "eager" */ './vendor.css');
3+
console.log('main');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
html,
2+
body {
3+
width: 100%;
4+
height: 100%;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vendor {
2+
color: red;
3+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const path = require('path');
2+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3+
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
4+
5+
module.exports = {
6+
mode: 'production',
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
},
10+
entry: {
11+
main: ['./src/main.js' ],
12+
style: ['./src/style.css'],
13+
},
14+
module: {
15+
rules: [
16+
{
17+
test: /\.css$/,
18+
use: [MiniCssExtractPlugin.loader, 'css-loader'],
19+
},
20+
],
21+
},
22+
plugins: [
23+
new RemoveEmptyScriptsPlugin(),
24+
new MiniCssExtractPlugin({
25+
filename: '[name].css',
26+
}),
27+
],
28+
};

test/integration.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('options tests', () => {
1616
describe('common use case tests', () => {
1717
test('css-entry-only', () => compareFiles( 'css-entry-only'));
1818
test('css-import', () => compareFiles( 'css-import'));
19+
test('css-import-dynamic', () => compareFiles( 'css-import-dynamic'));
1920
test('css-entry-with-ignored-hmr', () => compareFiles( 'css-entry-with-ignored-hmr', false));
2021
test('css-entry-with-query', () => compareFiles( 'css-entry-with-query'));
2122
test('multi-configuration', () => compareFiles( 'multi-configuration'));

0 commit comments

Comments
 (0)