@lynx-js/css-extract-webpack-plugin-canary 0.8.0 → 0.9.0-canary-20260715-2b5d83a4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/lib/CssExtractRspackPlugin.js +52 -5
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @lynx-js/css-extract-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.9.0-canary-20260715145040-2b5d83a4b8e3c1f5329de9d9fe7539d38e33e420
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Stop injecting `webpackChunkName` into dynamic imports so lazy bundle intermediate files stay inside the output directory. ([#2961](https://github.com/lynx-family/lynx-stack/pull/2961))
|
|
8
|
+
|
|
9
|
+
The ReactLynx transform injected `webpackChunkName: "<request>-react__<layer>"`, so a dynamic import resolving above the compiler context (e.g. `import('../../Foo.js')`) leaked `../` into `[name]`/`[id]` and the intermediate js/css/hmr files escaped the output directory. Async chunks now keep rspack's own ids, `__webpack_require__.lynx_aci` maps them by chunk id, and each lazy bundle's intermediate JS and CSS are emitted under `.rspeedy/async/<bundle-name>/<layer>.js` and `<layer>.css` next to its other intermediate outputs (`tasm.json`, `debug-metadata.json`, CSS hot-update files). Explicit `webpackChunkName` comments written by users are still honored and keep the user-controlled `[name]` placement. Main-thread chunks no longer emit CSS hot-update files — CSS only exists on the background thread, and the main-thread HMR runtime receives updates from it.
|
|
10
|
+
|
|
11
|
+
These packages release together and must be upgraded together: `@lynx-js/react-webpack-plugin` and `@lynx-js/css-extract-webpack-plugin` require `@lynx-js/template-webpack-plugin` `^0.13.0`, and `@lynx-js/react-rsbuild-plugin` requires `@lynx-js/react` `^0.123.0`.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Widen the `@lynx-js/template-webpack-plugin` peer range to `^0.13.0` to accept the ([#2584](https://github.com/lynx-family/lynx-stack/pull/2584))
|
|
16
|
+
minor that ships the FetchBundle chunk encoding.
|
|
17
|
+
- Updated dependencies [[`2b5d83a`](https://github.com/lynx-family/lynx-stack/commit/2b5d83a4b8e3c1f5329de9d9fe7539d38e33e420), [`2b5d83a`](https://github.com/lynx-family/lynx-stack/commit/2b5d83a4b8e3c1f5329de9d9fe7539d38e33e420), [`fec4237`](https://github.com/lynx-family/lynx-stack/commit/fec4237b2257455a40a68f33864fb713c147f7d4)]:
|
|
18
|
+
- @lynx-js/template-webpack-plugin@0.13.0-canary-20260715145040-2b5d83a4b8e3c1f5329de9d9fe7539d38e33e420
|
|
19
|
+
|
|
3
20
|
## 0.8.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -96,9 +96,29 @@ class CssExtractRspackPluginImpl {
|
|
|
96
96
|
this.name = 'CssExtractRspackPlugin';
|
|
97
97
|
this.hash = null;
|
|
98
98
|
this.hotUpdateFiles = new Map();
|
|
99
|
+
// Route a lazy bundle's CSS chunk to `.rspeedy/async/<name>/<layer>.css`,
|
|
100
|
+
// co-located with the bundle's other intermediate outputs. Non-lazy
|
|
101
|
+
// chunks keep the configured template.
|
|
102
|
+
let currentCompilation;
|
|
103
|
+
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
104
|
+
currentCompilation = compilation;
|
|
105
|
+
});
|
|
106
|
+
const userChunkFilename = options.chunkFilename;
|
|
107
|
+
const chunkFilename = userChunkFilename === undefined
|
|
108
|
+
? ''
|
|
109
|
+
: (pathData) => {
|
|
110
|
+
const id = pathData.chunk?.id;
|
|
111
|
+
if (currentCompilation !== undefined && id !== undefined && id !== null) {
|
|
112
|
+
const layoutName = LynxTemplatePlugin.getAsyncChunkLayoutName(currentCompilation, id);
|
|
113
|
+
if (layoutName !== undefined) {
|
|
114
|
+
return `.rspeedy/async/${layoutName}.css`;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return userChunkFilename;
|
|
118
|
+
};
|
|
99
119
|
new compiler.webpack.CssExtractRspackPlugin({
|
|
100
120
|
filename: options.filename ?? '[name].css',
|
|
101
|
-
chunkFilename
|
|
121
|
+
chunkFilename,
|
|
102
122
|
ignoreOrder: options.ignoreOrder ?? false,
|
|
103
123
|
insert: options.insert ?? '',
|
|
104
124
|
attributes: options.attributes ?? {},
|
|
@@ -108,12 +128,26 @@ class CssExtractRspackPluginImpl {
|
|
|
108
128
|
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
109
129
|
if (this.isHMREnabled(compiler)) {
|
|
110
130
|
const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
|
|
131
|
+
const isMainThreadChunk = (chunk) => {
|
|
132
|
+
for (const module of compilation.chunkGraph.getChunkModulesIterable(chunk)) {
|
|
133
|
+
if (module.layer) {
|
|
134
|
+
return String(module.layer).split(':').pop() === 'main-thread';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
111
139
|
hooks.beforeEmit.tapPromise(this.name, async (args) => {
|
|
112
140
|
const cssChunks = args.cssChunks;
|
|
113
141
|
const content = cssChunks.map((chunk) => chunk.source.source().toString('utf-8'));
|
|
114
|
-
|
|
142
|
+
// Generate the hot update files of this template's own chunks —
|
|
143
|
+
// `entryNames` cannot be used as the key since async lazy bundle
|
|
144
|
+
// templates have none.
|
|
145
|
+
const chunkKeys = args.chunkGroups
|
|
146
|
+
.flatMap(cg => cg.chunks)
|
|
147
|
+
.map(chunk => String(chunk.name ?? chunk.id));
|
|
148
|
+
for (const chunkKey of chunkKeys) {
|
|
115
149
|
// generate hot update file which is required by cssHotUpdateList
|
|
116
|
-
const hotUpdateFilePath = this.hotUpdateFiles.get(
|
|
150
|
+
const hotUpdateFilePath = this.hotUpdateFiles.get(chunkKey);
|
|
117
151
|
if (!hotUpdateFilePath) {
|
|
118
152
|
continue;
|
|
119
153
|
}
|
|
@@ -175,9 +209,18 @@ class CssExtractRspackPluginImpl {
|
|
|
175
209
|
generate() {
|
|
176
210
|
const chunk = this.chunk;
|
|
177
211
|
const asyncChunks = Array.from(chunk.getAllAsyncChunks())
|
|
212
|
+
// CSS only exists on the background thread (main-thread CSS is
|
|
213
|
+
// dropped by the ignore-css-loader), so main-thread chunks get
|
|
214
|
+
// no CSS hot update.
|
|
215
|
+
.filter(c => !isMainThreadChunk(c))
|
|
178
216
|
.map(c => {
|
|
179
|
-
const
|
|
180
|
-
|
|
217
|
+
const layoutName = c.id !== null && c.id !== undefined
|
|
218
|
+
? LynxTemplatePlugin.getAsyncChunkLayoutName(compilation, c.id)
|
|
219
|
+
: undefined;
|
|
220
|
+
const path = layoutName === undefined
|
|
221
|
+
? compilation.getAssetPathWithInfo(options.chunkFilename ?? '.rspeedy/async/[name]/[name].css', { chunk: c }).path
|
|
222
|
+
: `.rspeedy/async/${layoutName}.css`;
|
|
223
|
+
return [String(c.name ?? c.id), path];
|
|
181
224
|
});
|
|
182
225
|
const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css', { chunk });
|
|
183
226
|
const initialChunk = [chunk.name, path];
|
|
@@ -201,6 +244,10 @@ ${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify
|
|
|
201
244
|
if (onceForChunkSet.has(chunk))
|
|
202
245
|
return;
|
|
203
246
|
onceForChunkSet.add(chunk);
|
|
247
|
+
// The main-thread CSS HMR runtime receives updates from the
|
|
248
|
+
// background thread instead of reading `cssHotUpdateList`.
|
|
249
|
+
if (isMainThreadChunk(chunk))
|
|
250
|
+
return;
|
|
204
251
|
runtimeRequirements.add(RuntimeGlobals.publicPath);
|
|
205
252
|
compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash, this.hotUpdateFiles));
|
|
206
253
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/css-extract-webpack-plugin-canary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-canary-20260715-2b5d83a4",
|
|
4
4
|
"description": "This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
],
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@microsoft/api-extractor": "7.58.2",
|
|
45
|
-
"@rspack/core": "2.
|
|
46
|
-
"@rstest/core": "0.
|
|
45
|
+
"@rspack/core": "2.1.3",
|
|
46
|
+
"@rstest/core": "0.11.0",
|
|
47
47
|
"css-loader": "^7.1.4",
|
|
48
48
|
"sass-loader": "^16.0.7",
|
|
49
49
|
"@lynx-js/css-serializer": "npm:@lynx-js/css-serializer-canary@0.1.6",
|
|
50
|
-
"@lynx-js/
|
|
51
|
-
"@lynx-js/
|
|
50
|
+
"@lynx-js/test-tools": "0.0.0",
|
|
51
|
+
"@lynx-js/template-webpack-plugin": "npm:@lynx-js/template-webpack-plugin-canary@0.13.0-canary-20260715-2b5d83a4"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@lynx-js/template-webpack-plugin": "*"
|