Skip to content

Commit

Permalink
test: add test for order css imported in js and using split chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Aug 19, 2024
1 parent 3244e63 commit 236e2ec
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 5 deletions.
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions test/cases/split-chunk-css-order/expected/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<link href="main.bundle.css" rel="stylesheet">
<script src="main.bundle.js" defer></script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
5 changes: 5 additions & 0 deletions test/cases/split-chunk-css-order/expected/main.bundle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h1 {
color: red;
}h2 {
color: green;
}
1 change: 1 addition & 0 deletions test/cases/split-chunk-css-order/expected/main.bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(()=>{"use strict";console.log(">> main.js")})();
9 changes: 9 additions & 0 deletions test/cases/split-chunk-css-order/src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script src="./main.js" defer></script>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
4 changes: 4 additions & 0 deletions test/cases/split-chunk-css-order/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './style1.css';
import './style2.css';

console.log('>> main.js');
3 changes: 3 additions & 0 deletions test/cases/split-chunk-css-order/src/style1.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: red;
}
3 changes: 3 additions & 0 deletions test/cases/split-chunk-css-order/src/style2.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2 {
color: green;
}
59 changes: 59 additions & 0 deletions test/cases/split-chunk-css-order/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const path = require('path');
const HtmlBundlerPlugin = require('@test/html-bundler-webpack-plugin');

module.exports = {
mode: 'production',

output: {
path: path.join(__dirname, 'dist/'),
},

plugins: [
new HtmlBundlerPlugin({
entry: {
index: './src/index.html',
},
js: {
filename: '[name].bundle.js',
},
css: {
filename: '[name].bundle.css',
},
}),
],

module: {
rules: [
{
test: /\.(css|sass|scss)$/,
use: ['css-loader'],
},
],
},

optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
style1: {
test: /style1/,
enforce: true,
},
style2: {
test: /style2/,
enforce: true,
},
defaultVendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10,
reuseExistingChunk: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
};
4 changes: 3 additions & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,11 @@ describe('split chunks', () => {
test('resolve assets, production', () => compareFiles('split-chunk-resolve-assets-prod'));
test('load vendor scripts from node module', () => compareFiles('split-chunk-vendor'));

test('order css using split chunks ', () => compareFiles('split-chunk-css-order'));

// ATTENTION: this test doesn't work and never will be works.
// This is just to demonstrate how a split of CSS files cannot be used. CSS files cannot be split.
// test('extract css from split chunks ', () => compareFiles('split-chunk-css');
// test('extract css from split chunks ', () => compareFiles('split-chunk-css'));
});

describe('real content hash', () => {
Expand Down

0 comments on commit 236e2ec

Please sign in to comment.