Skip to content

Commit 60ec319

Browse files
authored
feat: add css chunking plugin demo (#306)
1 parent 337ceff commit 60ec319

File tree

9 files changed

+310
-140
lines changed

9 files changed

+310
-140
lines changed

pnpm-lock.yaml

Lines changed: 234 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
</body>
12+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "example-css-chunking-plugin",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "MIT",
6+
"main": "index.js",
7+
"scripts": {
8+
"build": "rspack build",
9+
"dev": "rspack serve"
10+
},
11+
"devDependencies": {
12+
"@rspack/cli": "1.4.0-rc.0",
13+
"@rspack/core": "1.4.0-rc.0"
14+
}
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { rspack } = require('@rspack/core');
2+
3+
/** @type {import('@rspack/cli').Configuration} */
4+
const config = {
5+
entry: './src/index.js',
6+
plugins: [
7+
new rspack.HtmlRspackPlugin({
8+
template: './index.html',
9+
}),
10+
// Without using CssChunkingPlugin, the current splitChunks configuration will split CSS modules into multiple chunks, causing CSS style errors
11+
new rspack.experiments.CssChunkingPlugin({
12+
// options
13+
}),
14+
],
15+
experiments: {
16+
css: true,
17+
},
18+
optimization: {
19+
minimize: false,
20+
splitChunks: {
21+
maxSize: 100,
22+
minSize: 0,
23+
}
24+
}
25+
};
26+
27+
module.exports = config;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import("./page");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import "./styles/global.css";
2+
import "./styles/theme.css";
3+
import "./styles/component.css";
4+
5+
document.addEventListener
6+
const button = document.createElement('button');
7+
button.className = 'btn';
8+
button.style.width = '200px';
9+
button.style.height = '50px';
10+
button.textContent = 'background should be black';
11+
document.body.appendChild(button);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.btn {
2+
background-color: black;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.btn {
2+
background-color: red;
3+
color: white;
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.btn {
2+
background-color: blue;
3+
}

0 commit comments

Comments
 (0)