@lynx-js/css-extract-webpack-plugin 0.6.5 → 0.7.0
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 +8 -0
- package/lib/CssExtractRspackPlugin.js +24 -10
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @lynx-js/css-extract-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- **BREAKING CHANGE**: Require `@lynx-js/template-webpack-plugin` 0.10.0. ([#1965](https://github.com/lynx-family/lynx-stack/pull/1965))
|
|
8
|
+
|
|
9
|
+
- Merge all css chunk and generate a `.css.hot-update.json` file for each bundle. ([#1965](https://github.com/lynx-family/lynx-stack/pull/1965))
|
|
10
|
+
|
|
3
11
|
## 0.6.5
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -95,6 +95,7 @@ class CssExtractRspackPluginImpl {
|
|
|
95
95
|
this.options = options;
|
|
96
96
|
this.name = 'CssExtractRspackPlugin';
|
|
97
97
|
this.hash = null;
|
|
98
|
+
this.hotUpdateFiles = new Map();
|
|
98
99
|
new compiler.webpack.CssExtractRspackPlugin({
|
|
99
100
|
filename: options.filename ?? '[name].css',
|
|
100
101
|
chunkFilename: options.chunkFilename ?? '',
|
|
@@ -110,9 +111,15 @@ class CssExtractRspackPluginImpl {
|
|
|
110
111
|
// @ts-expect-error Rspack to Webpack Compilation
|
|
111
112
|
compilation);
|
|
112
113
|
hooks.beforeEmit.tapPromise(this.name, async (args) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const cssChunks = args.cssChunks;
|
|
115
|
+
const content = cssChunks.map((chunk) => chunk.source.source().toString('utf-8'));
|
|
116
|
+
for (const entryName of args.entryNames) {
|
|
117
|
+
// generate hot update file which is required by cssHotUpdateList
|
|
118
|
+
const hotUpdateFilePath = this.hotUpdateFiles.get(entryName);
|
|
119
|
+
if (!hotUpdateFilePath) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const css = LynxTemplatePlugin.convertCSSChunksToMap(content, options.cssPlugins, Boolean(args.finalEncodeOptions.compilerOptions['enableCSSSelector']));
|
|
116
123
|
const cssDeps = Object.entries(css.cssMap).reduce((acc, [key, value]) => {
|
|
117
124
|
const importRuleNodes = value.filter((node) => node.type === 'ImportRule');
|
|
118
125
|
acc[key] = importRuleNodes.map(({ href }) => href);
|
|
@@ -140,7 +147,7 @@ class CssExtractRspackPluginImpl {
|
|
|
140
147
|
content: buffer.toString('base64'),
|
|
141
148
|
deps: cssDeps,
|
|
142
149
|
};
|
|
143
|
-
compilation.emitAsset(
|
|
150
|
+
compilation.emitAsset(hotUpdateFilePath, new compiler.webpack.sources.RawSource(JSON.stringify(result), true));
|
|
144
151
|
}
|
|
145
152
|
catch (error) {
|
|
146
153
|
if (error && typeof error === 'object' && 'error_msg' in error) {
|
|
@@ -159,9 +166,10 @@ class CssExtractRspackPluginImpl {
|
|
|
159
166
|
});
|
|
160
167
|
const { RuntimeGlobals, RuntimeModule } = compiler.webpack;
|
|
161
168
|
class CSSHotUpdateRuntimeModule extends RuntimeModule {
|
|
162
|
-
constructor(hash) {
|
|
169
|
+
constructor(hash, hotUpdateFiles) {
|
|
163
170
|
super('lynx css hot update');
|
|
164
171
|
this.hash = hash;
|
|
172
|
+
this.hotUpdateFiles = hotUpdateFiles;
|
|
165
173
|
}
|
|
166
174
|
generate() {
|
|
167
175
|
const chunk = this.chunk;
|
|
@@ -172,10 +180,16 @@ class CssExtractRspackPluginImpl {
|
|
|
172
180
|
});
|
|
173
181
|
const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css', { chunk });
|
|
174
182
|
const initialChunk = [chunk.name, path];
|
|
175
|
-
const cssHotUpdateList = [...asyncChunks, initialChunk].map(([chunkName, cssHotUpdatePath]) =>
|
|
176
|
-
|
|
177
|
-
cssHotUpdatePath.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`)
|
|
178
|
-
|
|
183
|
+
const cssHotUpdateList = [...asyncChunks, initialChunk].map(([chunkName, cssHotUpdatePath]) => {
|
|
184
|
+
// use hash of previous compilation cause CSSHotUpdateRuntimeModule can not get hash immediately
|
|
185
|
+
const hotUpdatePath = cssHotUpdatePath.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`);
|
|
186
|
+
// save all hot update file info
|
|
187
|
+
this.hotUpdateFiles.set(chunkName, hotUpdatePath);
|
|
188
|
+
return [
|
|
189
|
+
chunkName,
|
|
190
|
+
hotUpdatePath,
|
|
191
|
+
];
|
|
192
|
+
});
|
|
179
193
|
return `
|
|
180
194
|
${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify(cssHotUpdateList) : 'null'};
|
|
181
195
|
`;
|
|
@@ -187,7 +201,7 @@ ${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify
|
|
|
187
201
|
return;
|
|
188
202
|
onceForChunkSet.add(chunk);
|
|
189
203
|
runtimeRequirements.add(RuntimeGlobals.publicPath);
|
|
190
|
-
compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash));
|
|
204
|
+
compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash, this.hotUpdateFiles));
|
|
191
205
|
};
|
|
192
206
|
compilation.hooks.runtimeRequirementInTree
|
|
193
207
|
.for(RuntimeGlobals.ensureChunkHandlers)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/css-extract-webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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",
|
|
@@ -45,17 +45,17 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@microsoft/api-extractor": "7.52.15",
|
|
48
|
-
"@rspack/core": "1.6.
|
|
48
|
+
"@rspack/core": "1.6.6",
|
|
49
49
|
"css-loader": "^7.1.2",
|
|
50
50
|
"sass-loader": "^16.0.5",
|
|
51
51
|
"webpack": "^5.102.0",
|
|
52
52
|
"@lynx-js/css-serializer": "0.1.3",
|
|
53
|
-
"@lynx-js/template-webpack-plugin": "0.
|
|
53
|
+
"@lynx-js/template-webpack-plugin": "0.10.0",
|
|
54
54
|
"@lynx-js/test-tools": "0.0.0",
|
|
55
55
|
"@lynx-js/vitest-setup": "0.0.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@lynx-js/template-webpack-plugin": "^0.
|
|
58
|
+
"@lynx-js/template-webpack-plugin": "^0.10.0"
|
|
59
59
|
},
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18"
|