@lynx-js/css-extract-webpack-plugin 0.5.2 → 0.5.3
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.d.ts +5 -1
- package/lib/CssExtractRspackPlugin.js +41 -23
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @lynx-js/css-extract-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix CSS HMR not working with nested entry name. ([#456](https://github.com/lynx-family/lynx-stack/pull/456))
|
|
8
|
+
|
|
9
|
+
- fix: add enableCSSInvalidation for encodeCSS of css HMR, this will fix pseudo-class (such as `:active`) not working in HMR. ([#435](https://github.com/lynx-family/lynx-stack/pull/435))
|
|
10
|
+
|
|
3
11
|
## 0.5.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Compiler, CssExtractRspackPluginOptions as ExternalCssExtractRspackPluginOptions } from '@rspack/core';
|
|
2
2
|
import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin';
|
|
3
3
|
/**
|
|
4
|
-
* The options for {@link @lynx-js/
|
|
4
|
+
* The options for {@link @lynx-js/css-extract-webpack-plugin#CssExtractRspackPlugin}
|
|
5
5
|
*
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
@@ -14,6 +14,10 @@ interface CssExtractRspackPluginOptions extends ExternalCssExtractRspackPluginOp
|
|
|
14
14
|
* {@inheritdoc @lynx-js/template-webpack-plugin#LynxTemplatePluginOptions.enableCSSSelector}
|
|
15
15
|
*/
|
|
16
16
|
enableCSSSelector: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* {@inheritdoc @lynx-js/template-webpack-plugin#LynxTemplatePluginOptions.enableCSSInvalidation}
|
|
19
|
+
*/
|
|
20
|
+
enableCSSInvalidation: boolean;
|
|
17
21
|
/**
|
|
18
22
|
* {@inheritdoc @lynx-js/template-webpack-plugin#LynxTemplatePluginOptions.targetSdkVersion}
|
|
19
23
|
*/
|
|
@@ -66,7 +66,7 @@ class CssExtractRspackPlugin {
|
|
|
66
66
|
.freeze({
|
|
67
67
|
enableRemoveCSSScope: false,
|
|
68
68
|
enableCSSSelector: true,
|
|
69
|
-
|
|
69
|
+
enableCSSInvalidation: true,
|
|
70
70
|
targetSdkVersion: '3.2',
|
|
71
71
|
filename: '[name].css',
|
|
72
72
|
cssPlugins: [],
|
|
@@ -97,29 +97,56 @@ class CssExtractRspackPluginImpl {
|
|
|
97
97
|
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
98
98
|
if (compiler.options.mode === 'development'
|
|
99
99
|
|| process.env['NODE_ENV'] === 'development') {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
const { RuntimeGlobals, RuntimeModule } = compiler.webpack;
|
|
101
|
+
class CSSHotUpdateRuntimeModule extends RuntimeModule {
|
|
102
|
+
constructor(hash) {
|
|
103
|
+
super('lynx css hot update');
|
|
104
|
+
this.hash = hash;
|
|
105
|
+
}
|
|
106
|
+
generate() {
|
|
107
|
+
const chunk = this.chunk;
|
|
106
108
|
const asyncChunks = Array.from(chunk.getAllAsyncChunks())
|
|
107
109
|
.map(c => {
|
|
108
110
|
const { path } = compilation.getAssetPathWithInfo(options.chunkFilename ?? '.rspeedy/async/[name]/[name].css', { chunk: c });
|
|
109
111
|
return [c.name, path];
|
|
110
112
|
});
|
|
111
|
-
const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css',
|
|
112
|
-
// Rspack does not pass JsChunk to Rust.
|
|
113
|
-
// See: https://github.com/web-infra-dev/rspack/blob/73c31abcb78472eb5a3d93e4ece19d9f106727a6/crates/rspack_binding_values/src/path_data.rs#L62
|
|
114
|
-
{ filename: chunk.name });
|
|
113
|
+
const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css', { chunk });
|
|
115
114
|
const initialChunk = [chunk.name, path];
|
|
116
115
|
const cssHotUpdateList = [...asyncChunks, initialChunk].map(([chunkName, cssHotUpdatePath]) => [
|
|
117
116
|
chunkName,
|
|
118
117
|
cssHotUpdatePath.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`),
|
|
119
118
|
]);
|
|
120
|
-
|
|
119
|
+
return `
|
|
120
|
+
${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify(cssHotUpdateList) : 'null'};
|
|
121
|
+
`;
|
|
121
122
|
}
|
|
122
|
-
}
|
|
123
|
+
}
|
|
124
|
+
const onceForChunkSet = new WeakSet();
|
|
125
|
+
const handler = (chunk, runtimeRequirements) => {
|
|
126
|
+
if (onceForChunkSet.has(chunk))
|
|
127
|
+
return;
|
|
128
|
+
onceForChunkSet.add(chunk);
|
|
129
|
+
runtimeRequirements.add(RuntimeGlobals.publicPath);
|
|
130
|
+
compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash));
|
|
131
|
+
};
|
|
132
|
+
compilation.hooks.runtimeRequirementInTree
|
|
133
|
+
.for(RuntimeGlobals.ensureChunkHandlers)
|
|
134
|
+
.tap(this.name, handler);
|
|
135
|
+
compilation.hooks.runtimeRequirementInTree
|
|
136
|
+
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
|
137
|
+
.tap(this.name, handler);
|
|
138
|
+
compilation.hooks.runtimeRequirementInTree
|
|
139
|
+
.for(RuntimeGlobals.hmrDownloadManifest)
|
|
140
|
+
.tap(this.name, handler);
|
|
141
|
+
compilation.hooks.runtimeRequirementInTree
|
|
142
|
+
.for(RuntimeGlobals.baseURI)
|
|
143
|
+
.tap(this.name, handler);
|
|
144
|
+
compilation.hooks.runtimeRequirementInTree
|
|
145
|
+
.for(RuntimeGlobals.externalInstallChunk)
|
|
146
|
+
.tap(this.name, handler);
|
|
147
|
+
compilation.hooks.runtimeRequirementInTree
|
|
148
|
+
.for(RuntimeGlobals.onChunksLoaded)
|
|
149
|
+
.tap(this.name, handler);
|
|
123
150
|
compilation.hooks.processAssets.tapPromise({
|
|
124
151
|
name: this.name,
|
|
125
152
|
stage: 300,
|
|
@@ -144,6 +171,7 @@ class CssExtractRspackPluginImpl {
|
|
|
144
171
|
targetSdkVersion: options.targetSdkVersion,
|
|
145
172
|
enableCSSSelector: options.enableCSSSelector,
|
|
146
173
|
enableRemoveCSSScope: options.enableRemoveCSSScope,
|
|
174
|
+
enableCSSInvalidation: options.enableCSSInvalidation,
|
|
147
175
|
}, options.cssPlugins, hooks.encode.taps.length > 0
|
|
148
176
|
? async (encodeOptions) => {
|
|
149
177
|
// @ts-expect-error Only CSS is needed
|
|
@@ -176,15 +204,5 @@ class CssExtractRspackPluginImpl {
|
|
|
176
204
|
}
|
|
177
205
|
});
|
|
178
206
|
}
|
|
179
|
-
#overrideChunkLoadingRuntimeModule(compiler, runtimeModule, cssHotUpdateList) {
|
|
180
|
-
const { RuntimeGlobals } = compiler.webpack;
|
|
181
|
-
runtimeModule.source.source = Buffer.concat([
|
|
182
|
-
Buffer.from(runtimeModule.source.source),
|
|
183
|
-
// cssHotUpdateList
|
|
184
|
-
Buffer.from(`
|
|
185
|
-
${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify(cssHotUpdateList) : 'null'};
|
|
186
|
-
`),
|
|
187
|
-
]);
|
|
188
|
-
}
|
|
189
207
|
}
|
|
190
208
|
//# sourceMappingURL=CssExtractRspackPlugin.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/css-extract-webpack-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
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",
|
|
@@ -44,14 +44,15 @@
|
|
|
44
44
|
"mini-css-extract-plugin": "^2.9.2"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "7.
|
|
48
|
-
"@rspack/core": "1.
|
|
47
|
+
"@microsoft/api-extractor": "7.52.2",
|
|
48
|
+
"@rspack/core": "1.3.1",
|
|
49
49
|
"css-loader": "^7.1.2",
|
|
50
50
|
"sass-loader": "^16.0.5",
|
|
51
51
|
"webpack": "^5.98.0",
|
|
52
52
|
"@lynx-js/css-serializer": "0.1.2",
|
|
53
|
-
"@lynx-js/template-webpack-plugin": "0.6.
|
|
54
|
-
"@lynx-js/test-tools": "0.0.0"
|
|
53
|
+
"@lynx-js/template-webpack-plugin": "0.6.8",
|
|
54
|
+
"@lynx-js/test-tools": "0.0.0",
|
|
55
|
+
"@lynx-js/vitest-setup": "0.0.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"@lynx-js/template-webpack-plugin": "^0.5.0 || ^0.6.0"
|