@lynx-js/css-extract-webpack-plugin 0.6.4 → 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 CHANGED
@@ -1,5 +1,19 @@
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
+
11
+ ## 0.6.5
12
+
13
+ ### Patch Changes
14
+
15
+ - Set main thread JS basename to `lepusCode.filename` in tasm encode data. It will ensure a filename is reported on MTS error without devtools enabled. ([#1949](https://github.com/lynx-family/lynx-stack/pull/1949))
16
+
3
17
  ## 0.6.4
4
18
 
5
19
  ### 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
- for (const { name: filename, source, } of args.cssChunks) {
114
- const content = source.source().toString('utf-8');
115
- const css = LynxTemplatePlugin.convertCSSChunksToMap([content], options.cssPlugins, Boolean(args.finalEncodeOptions.compilerOptions['enableCSSSelector']));
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);
@@ -130,6 +137,7 @@ class CssExtractRspackPluginImpl {
130
137
  lepusCode: {
131
138
  root: undefined,
132
139
  lepusChunk: {},
140
+ filename: undefined,
133
141
  },
134
142
  manifest: {},
135
143
  customSections: {},
@@ -139,7 +147,7 @@ class CssExtractRspackPluginImpl {
139
147
  content: buffer.toString('base64'),
140
148
  deps: cssDeps,
141
149
  };
142
- compilation.emitAsset(filename.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`), new compiler.webpack.sources.RawSource(JSON.stringify(result), true));
150
+ compilation.emitAsset(hotUpdateFilePath, new compiler.webpack.sources.RawSource(JSON.stringify(result), true));
143
151
  }
144
152
  catch (error) {
145
153
  if (error && typeof error === 'object' && 'error_msg' in error) {
@@ -158,9 +166,10 @@ class CssExtractRspackPluginImpl {
158
166
  });
159
167
  const { RuntimeGlobals, RuntimeModule } = compiler.webpack;
160
168
  class CSSHotUpdateRuntimeModule extends RuntimeModule {
161
- constructor(hash) {
169
+ constructor(hash, hotUpdateFiles) {
162
170
  super('lynx css hot update');
163
171
  this.hash = hash;
172
+ this.hotUpdateFiles = hotUpdateFiles;
164
173
  }
165
174
  generate() {
166
175
  const chunk = this.chunk;
@@ -171,10 +180,16 @@ class CssExtractRspackPluginImpl {
171
180
  });
172
181
  const { path } = compilation.getPathWithInfo(options.filename ?? '[name].css', { chunk });
173
182
  const initialChunk = [chunk.name, path];
174
- const cssHotUpdateList = [...asyncChunks, initialChunk].map(([chunkName, cssHotUpdatePath]) => [
175
- chunkName,
176
- cssHotUpdatePath.replace('.css', `${this.hash ? `.${this.hash}` : ''}.css.hot-update.json`),
177
- ]);
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
+ });
178
193
  return `
179
194
  ${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify(cssHotUpdateList) : 'null'};
180
195
  `;
@@ -186,7 +201,7 @@ ${RuntimeGlobals.require}.cssHotUpdateList = ${cssHotUpdateList ? JSON.stringify
186
201
  return;
187
202
  onceForChunkSet.add(chunk);
188
203
  runtimeRequirements.add(RuntimeGlobals.publicPath);
189
- compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash));
204
+ compilation.addRuntimeModule(chunk, new CSSHotUpdateRuntimeModule(this.hash, this.hotUpdateFiles));
190
205
  };
191
206
  compilation.hooks.runtimeRequirementInTree
192
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.6.4",
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.5.8",
48
+ "@rspack/core": "1.6.6",
49
49
  "css-loader": "^7.1.2",
50
50
  "sass-loader": "^16.0.5",
51
- "webpack": "^5.101.3",
51
+ "webpack": "^5.102.0",
52
52
  "@lynx-js/css-serializer": "0.1.3",
53
- "@lynx-js/template-webpack-plugin": "0.9.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.9.0"
58
+ "@lynx-js/template-webpack-plugin": "^0.10.0"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=18"