Skip to content

Commit 236e2ec

Browse files
committed
test: add test for order css imported in js and using split chunks
1 parent 3244e63 commit 236e2ec

10 files changed

Lines changed: 104 additions & 5 deletions

File tree

package-lock.json

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link href="main.bundle.css" rel="stylesheet">
5+
<script src="main.bundle.js" defer></script>
6+
</head>
7+
<body>
8+
<h1>Hello World!</h1>
9+
</body>
10+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
h1 {
2+
color: red;
3+
}h2 {
4+
color: green;
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()=>{"use strict";console.log(">> main.js")})();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="./main.js" defer></script>
5+
</head>
6+
<body>
7+
<h1>Hello World!</h1>
8+
</body>
9+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './style1.css';
2+
import './style2.css';
3+
4+
console.log('>> main.js');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h2 {
2+
color: green;
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const path = require('path');
2+
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');
3+
4+
module.exports = {
5+
mode: 'production',
6+
7+
output: {
8+
path: path.join(__dirname, 'dist/'),
9+
},
10+
11+
plugins: [
12+
new HtmlBundlerPlugin({
13+
entry: {
14+
index: './src/index.html',
15+
},
16+
js: {
17+
filename: '[name].bundle.js',
18+
},
19+
css: {
20+
filename: '[name].bundle.css',
21+
},
22+
}),
23+
],
24+
25+
module: {
26+
rules: [
27+
{
28+
test: /\.(css|sass|scss)$/,
29+
use: ['css-loader'],
30+
},
31+
],
32+
},
33+
34+
optimization: {
35+
splitChunks: {
36+
chunks: 'all',
37+
cacheGroups: {
38+
style1: {
39+
test: /style1/,
40+
enforce: true,
41+
},
42+
style2: {
43+
test: /style2/,
44+
enforce: true,
45+
},
46+
defaultVendors: {
47+
test: /[\\/]node_modules[\\/]/,
48+
priority: -10,
49+
reuseExistingChunk: true,
50+
},
51+
default: {
52+
minChunks: 2,
53+
priority: -20,
54+
reuseExistingChunk: true,
55+
},
56+
},
57+
},
58+
},
59+
};

test/integration.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ describe('split chunks', () => {
405405
test('resolve assets, production', () => compareFiles('split-chunk-resolve-assets-prod'));
406406
test('load vendor scripts from node module', () => compareFiles('split-chunk-vendor'));
407407

408+
test('order css using split chunks ', () => compareFiles('split-chunk-css-order'));
409+
408410
// ATTENTION: this test doesn't work and never will be works.
409411
// This is just to demonstrate how a split of CSS files cannot be used. CSS files cannot be split.
410-
// test('extract css from split chunks ', () => compareFiles('split-chunk-css');
412+
// test('extract css from split chunks ', () => compareFiles('split-chunk-css'));
411413
});
412414

413415
describe('real content hash', () => {

0 commit comments

Comments
 (0)