@lynx-js/css-extract-webpack-plugin 0.5.0 → 0.5.2
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
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @lynx-js/css-extract-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat(css-extra-webpack-plugin): Support css hmr for lazy bundle ([#155](https://github.com/lynx-family/lynx-stack/pull/155))
|
|
8
|
+
|
|
9
|
+
## 0.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Support NPM provenance. ([#30](https://github.com/lynx-family/lynx-stack/pull/30))
|
|
14
|
+
|
|
3
15
|
## 0.5.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -103,11 +103,21 @@ class CssExtractRspackPluginImpl {
|
|
|
103
103
|
});
|
|
104
104
|
compilation.hooks.runtimeModule.tap(this.name, (runtimeModule, chunk) => {
|
|
105
105
|
if (runtimeModule.name === 'require_chunk_loading') {
|
|
106
|
+
const asyncChunks = Array.from(chunk.getAllAsyncChunks())
|
|
107
|
+
.map(c => {
|
|
108
|
+
const { path } = compilation.getAssetPathWithInfo(options.chunkFilename ?? '.rspeedy/async/[name]/[name].css', { chunk: c });
|
|
109
|
+
return [c.name, path];
|
|
110
|
+
});
|
|
106
111
|
const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css',
|
|
107
112
|
// Rspack does not pass JsChunk to Rust.
|
|
108
113
|
// See: https://github.com/web-infra-dev/rspack/blob/73c31abcb78472eb5a3d93e4ece19d9f106727a6/crates/rspack_binding_values/src/path_data.rs#L62
|
|
109
114
|
{ filename: chunk.name });
|
|
110
|
-
|
|
115
|
+
const initialChunk = [chunk.name, path];
|
|
116
|
+
const cssHotUpdateList = [...asyncChunks, initialChunk].map(([chunkName, cssHotUpdatePath]) => [
|
|
117
|
+
chunkName,
|
|
118
|
+
cssHotUpdatePath.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`),
|
|
119
|
+
]);
|
|
120
|
+
this.#overrideChunkLoadingRuntimeModule(compiler, runtimeModule, cssHotUpdateList);
|
|
111
121
|
}
|
|
112
122
|
});
|
|
113
123
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -148,7 +158,6 @@ class CssExtractRspackPluginImpl {
|
|
|
148
158
|
deps: cssDeps,
|
|
149
159
|
};
|
|
150
160
|
compilation.emitAsset(filename.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`), new compiler.webpack.sources.RawSource(JSON.stringify(result), true));
|
|
151
|
-
this.hash = compilation.hash;
|
|
152
161
|
}
|
|
153
162
|
catch (error) {
|
|
154
163
|
if (error && typeof error === 'object' && 'error_msg' in error) {
|
|
@@ -162,17 +171,18 @@ class CssExtractRspackPluginImpl {
|
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
173
|
}
|
|
174
|
+
this.hash = compilation.hash;
|
|
165
175
|
});
|
|
166
176
|
}
|
|
167
177
|
});
|
|
168
178
|
}
|
|
169
|
-
#overrideChunkLoadingRuntimeModule(compiler, runtimeModule,
|
|
179
|
+
#overrideChunkLoadingRuntimeModule(compiler, runtimeModule, cssHotUpdateList) {
|
|
170
180
|
const { RuntimeGlobals } = compiler.webpack;
|
|
171
181
|
runtimeModule.source.source = Buffer.concat([
|
|
172
182
|
Buffer.from(runtimeModule.source.source),
|
|
173
|
-
//
|
|
183
|
+
// cssHotUpdateList
|
|
174
184
|
Buffer.from(`
|
|
175
|
-
${RuntimeGlobals.require}.
|
|
185
|
+
${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify(cssHotUpdateList) : 'null'};
|
|
176
186
|
`),
|
|
177
187
|
]);
|
|
178
188
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/css-extract-webpack-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
7
7
|
"Lynx"
|
|
8
8
|
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/lynx-family/lynx-stack.git",
|
|
12
|
+
"directory": "packages/webpack/css-extract-webpack-plugin"
|
|
13
|
+
},
|
|
9
14
|
"license": "Apache-2.0",
|
|
10
15
|
"author": {
|
|
11
16
|
"name": "Qingyu Wang",
|
|
@@ -39,14 +44,13 @@
|
|
|
39
44
|
"mini-css-extract-plugin": "^2.9.2"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@microsoft/api-extractor": "7.51.
|
|
43
|
-
"@rspack/
|
|
44
|
-
"@rspack/core": "1.2.6",
|
|
47
|
+
"@microsoft/api-extractor": "7.51.1",
|
|
48
|
+
"@rspack/core": "1.2.8",
|
|
45
49
|
"css-loader": "^7.1.2",
|
|
46
50
|
"sass-loader": "^16.0.5",
|
|
47
51
|
"webpack": "^5.98.0",
|
|
48
|
-
"@lynx-js/css-serializer": "0.1.
|
|
49
|
-
"@lynx-js/template-webpack-plugin": "0.6.
|
|
52
|
+
"@lynx-js/css-serializer": "0.1.2",
|
|
53
|
+
"@lynx-js/template-webpack-plugin": "0.6.5",
|
|
50
54
|
"@lynx-js/test-tools": "0.0.0"
|
|
51
55
|
},
|
|
52
56
|
"peerDependencies": {
|
|
@@ -17,29 +17,38 @@ function debounce(fn, time) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function updateStyle(cssId = 0) {
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
throw new Error('
|
|
20
|
+
const cssHotUpdateList = __webpack_require__.cssHotUpdateList;
|
|
21
|
+
if (!cssHotUpdateList) {
|
|
22
|
+
throw new Error('cssHotUpdateList is not found');
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
for (const [chunkName, cssHotUpdatePath] of cssHotUpdateList) {
|
|
26
|
+
lynx.requireModuleAsync(
|
|
27
|
+
// lynx.requireModuleAsync has two level hash and we cannot delete
|
|
28
|
+
// the LynxGroup level cache here.
|
|
29
|
+
// Temporarily using `Date.now` to avoid being cached.
|
|
30
|
+
__webpack_require__.p + cssHotUpdatePath,
|
|
31
|
+
(err, ret) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Failed to load CSS update file: ${cssHotUpdatePath}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (ret.content) {
|
|
39
|
+
lynx.getCoreContext().dispatchEvent({
|
|
40
|
+
type: 'lynx.hmr.css',
|
|
41
|
+
data: {
|
|
42
|
+
cssId,
|
|
43
|
+
content: ret.content,
|
|
44
|
+
deps: ret.deps,
|
|
45
|
+
entry: lynx.__chunk_entries__[chunkName],
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/**
|
|
@@ -2,13 +2,14 @@ function main() {
|
|
|
2
2
|
try {
|
|
3
3
|
lynx.getJSContext().addEventListener('lynx.hmr.css', (event) => {
|
|
4
4
|
try {
|
|
5
|
-
const { data: { cssId, content, deps } } = event;
|
|
5
|
+
const { data: { cssId, content, deps, entry } } = event;
|
|
6
6
|
// Update the css deps first because the css deps are updated actually.
|
|
7
7
|
if (Array.isArray(deps[cssId])) {
|
|
8
8
|
deps[cssId].forEach(depCSSId => {
|
|
9
9
|
lynx.getDevtool().replaceStyleSheetByIdWithBase64(
|
|
10
10
|
Number(depCSSId),
|
|
11
11
|
content,
|
|
12
|
+
entry,
|
|
12
13
|
);
|
|
13
14
|
});
|
|
14
15
|
}
|
|
@@ -16,6 +17,7 @@ function main() {
|
|
|
16
17
|
lynx.getDevtool().replaceStyleSheetByIdWithBase64(
|
|
17
18
|
Number(cssId),
|
|
18
19
|
content,
|
|
20
|
+
entry,
|
|
19
21
|
);
|
|
20
22
|
|
|
21
23
|
__FlushElementTree();
|