stylex-webpack 0.2.1-beta.5 → 0.2.1-beta.7

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/dist/index.js CHANGED
@@ -66,7 +66,7 @@ class StyleXPlugin {
66
66
  });
67
67
  });
68
68
  const { Compilation, NormalModule, sources } = compiler.webpack;
69
- const { RawSource } = sources;
69
+ const { RawSource, ConcatSource } = sources;
70
70
  // Apply loader to JS modules
71
71
  compiler.hooks.make.tap(PLUGIN_NAME, (compilation)=>{
72
72
  NormalModule.getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, mod)=>{
@@ -119,12 +119,16 @@ class StyleXPlugin {
119
119
  if (!stringifiedStylexRule) {
120
120
  continue;
121
121
  }
122
- this.stylexRules.set(cssModule.identifier(), JSON.parse(decodeURIComponent(stringifiedStylexRule)));
122
+ const params = new URLSearchParams(stringifiedStylexRule);
123
+ const stylex = params.get('stylex');
124
+ if (stylex != null) {
125
+ this.stylexRules.set(cssModule.identifier(), JSON.parse(stylex));
126
+ }
123
127
  }
124
128
  }
125
129
  }
126
130
  // Let's find the css file that belongs to the stylex chunk
127
- const cssAssetDetails = Object.entries(assets).find(([assetName])=>stylexChunk.files.has(assetName));
131
+ const cssAssetDetails = Object.entries(assets).find(([assetName])=>stylexChunk.files.has(assetName) && assetName.includes(STYLEX_CHUNK_NAME));
128
132
  if (!cssAssetDetails) {
129
133
  return;
130
134
  }
@@ -132,7 +136,8 @@ class StyleXPlugin {
132
136
  if (stylexCSS == null) {
133
137
  return;
134
138
  }
135
- compilation.updateAsset(cssAssetDetails[0], new RawSource(await this.transformCss(stylexCSS)));
139
+ const finalCss = await this.transformCss(stylexCSS);
140
+ compilation.updateAsset(cssAssetDetails[0], (source)=>new ConcatSource(source, new RawSource(finalCss)));
136
141
  });
137
142
  });
138
143
  }
package/dist/next.js CHANGED
@@ -29,7 +29,7 @@ const getNextMiniCssExtractPlugin = (isDev)=>{
29
29
  if (isDev) {
30
30
  try {
31
31
  // Check if hotModuleReplacement exists
32
- require('next/dist/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement');
32
+ require.resolve('next/dist/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement');
33
33
  return NextMiniCssExtractPlugin;
34
34
  } catch {
35
35
  log.warn('Next.js built-in mini-css-extract-plugin is broken, will fallback to "mini-css-extract-plugin"');
@@ -51,7 +51,7 @@ function getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin, postcss) {
51
51
  loaders.push({
52
52
  loader: MiniCssExtractPlugin.loader,
53
53
  options: {
54
- publicPath: `${ctx.assetPrefix}/_next/`,
54
+ publicPath: `${ctx.config.assetPrefix}/_next/`,
55
55
  esModule: false
56
56
  }
57
57
  });
@@ -55,20 +55,24 @@ async function stylexLoader(inputCode, inputSourceMap) {
55
55
  // Find a better way to register stylex rules to the compiler instance
56
56
  this.StyleXWebpackContextKey.registerStyleXRules(this.resourcePath, metadata.stylex);
57
57
  // color: #fff is not url safe
58
- const serializedStyleXRules = encodeURIComponent(JSON.stringify(metadata.stylex));
58
+ const serializedStyleXRules = JSON.stringify(metadata.stylex);
59
+ const urlParams = new URLSearchParams({
60
+ from: this.resourcePath,
61
+ stylex: serializedStyleXRules
62
+ });
59
63
  if (!nextjsMode) {
60
64
  // Normal webpack mode
61
65
  // We generate a virtual css file that looks like it is relative to the source
62
66
  const virtualFileName = loaderUtils.interpolateName(this, '[path][name].[hash:base64:8].stylex.virtual.css', {
63
67
  content: serializedStyleXRules
64
68
  });
65
- const virtualCssRequest = stringifyRequest(this, `${virtualFileName}!=!${VIRTUAL_CSS_PATH}?${serializedStyleXRules}`);
69
+ const virtualCssRequest = stringifyRequest(this, `${virtualFileName}!=!${VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
66
70
  const postfix = `\nimport ${virtualCssRequest};`;
67
71
  return callback(null, code + postfix, map ?? undefined);
68
72
  }
69
73
  // Next.js App Router doesn't support inline matchResource and inline loaders
70
74
  // So we adapt Next.js' "external" css import approach instead
71
- const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}?${serializedStyleXRules}`);
75
+ const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
72
76
  const postfix = `\nimport ${virtualCssRequest};`;
73
77
  return callback(null, code + postfix, map ?? undefined);
74
78
  } catch (error) {
@@ -3,18 +3,28 @@
3
3
  var loaderUtils = require('loader-utils');
4
4
 
5
5
  // prefer loader-utils over self-implemented hash function to utilize caching + bulk hashing
6
- function stylexVirtualCssLoader() {
6
+ function stylexVirtualCssLoader(inputCode, inputSourceMap) {
7
7
  const callback = this.async();
8
- const data = decodeURIComponent(this.resourceQuery.slice(1));
8
+ const data = new URLSearchParams(this.resourceQuery.slice(1));
9
9
  try {
10
+ const stylex = data.get('stylex');
11
+ if (stylex == null) {
12
+ callback(null, inputCode, inputSourceMap);
13
+ return;
14
+ }
15
+ // If we got stylex in the virtual css import, we need to disable the cache
16
+ // to fix HMR and Next.js navigation
17
+ // TODO: find a better way to mark the generated chunk as uncacheable instead
18
+ // of disable caching the result of this loader
19
+ this.cacheable(false);
10
20
  // @ts-expect-error -- getHashDigest supports string & xxhash64
11
- const hash = loaderUtils.getHashDigest(data, 'xxhash64', 'base62', 32);
21
+ const hash = loaderUtils.getHashDigest(stylex, 'xxhash64', 'base62', 32);
12
22
  const css = `
13
23
  /*
14
24
  * dummy css generated by stylex-webpack
15
25
  * real css will be injected later directly to the module
16
26
  *
17
- * stylex rules: ${data}
27
+ * stylex rules: ${stylex}
18
28
  */
19
29
  .__stylex_dummy_${hash} {}`;
20
30
  callback(null, css);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylex-webpack",
3
- "version": "0.2.1-beta.5",
3
+ "version": "0.2.1-beta.7",
4
4
  "description": "The another Webpack Plugin for Facebook's StyleX",
5
5
  "homepage": "https://github.com/SukkaW/style9-webpack#readme",
6
6
  "repository": {
@@ -38,43 +38,43 @@
38
38
  "author": "Sukka <https://skk.moe>",
39
39
  "license": "MIT",
40
40
  "dependencies": {
41
- "@babel/core": "^7.23.9",
42
- "@babel/plugin-syntax-jsx": "^7.23.3",
43
- "@babel/plugin-syntax-typescript": "^7.23.3",
41
+ "@babel/core": "^7.24.4",
42
+ "@babel/plugin-syntax-jsx": "^7.24.1",
43
+ "@babel/plugin-syntax-typescript": "^7.24.1",
44
44
  "@stylexjs/babel-plugin": "^0.5.1",
45
45
  "loader-utils": "^3.2.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@eslint-sukka/node": "^5.1.0",
49
- "@eslint-sukka/ts": "^5.1.0",
50
- "@swc-node/register": "^1.8.0",
51
- "@swc/core": "^1.4.1",
48
+ "@eslint-sukka/node": "^5.1.2",
49
+ "@eslint-sukka/ts": "^5.1.2",
50
+ "@swc-node/register": "^1.9.0",
51
+ "@swc/core": "^1.4.12",
52
52
  "@types/babel__core": "^7.20.5",
53
- "@types/chai": "^4.3.11",
53
+ "@types/chai": "^4.3.14",
54
54
  "@types/loader-utils": "^2.0.6",
55
55
  "@types/mocha": "^10.0.6",
56
- "@types/node": "^20.11.17",
56
+ "@types/node": "^20.12.4",
57
57
  "browserslist": "^4.23.0",
58
58
  "bumpp": "^9.3.0",
59
59
  "chai": "^4.4.1",
60
60
  "css-loader": "^6.10.0",
61
- "eslint": "^8.56.0",
62
- "eslint-config-sukka": "^5.1.0",
63
- "eslint-formatter-sukka": "^5.1.0",
64
- "memfs": "^4.7.0",
65
- "mini-css-extract-plugin": "^2.8.0",
66
- "mocha": "^10.3.0",
61
+ "eslint": "^8.57.0",
62
+ "eslint-config-sukka": "^5.1.2",
63
+ "eslint-formatter-sukka": "^5.1.2",
64
+ "memfs": "^4.8.1",
65
+ "mini-css-extract-plugin": "^2.8.1",
66
+ "mocha": "^10.4.0",
67
67
  "mocha-chai-jest-snapshot": "^1.1.4",
68
- "next": "^14.1.0",
69
- "postcss": "^8.4.35",
68
+ "next": "^14.1.4",
69
+ "postcss": "^8.4.38",
70
70
  "rimraf": "^5.0.5",
71
- "rollup": "^4.10.0",
71
+ "rollup": "^4.14.0",
72
72
  "rollup-plugin-copy": "^3.5.0",
73
73
  "rollup-plugin-dts": "^6.1.0",
74
74
  "rollup-plugin-swc3": "^0.11.0",
75
75
  "swc-loader": "^0.2.6",
76
- "typescript": "^5.3.3",
77
- "webpack": "^5.90.1"
76
+ "typescript": "^5.4.4",
77
+ "webpack": "^5.91.0"
78
78
  },
79
79
  "peerDependencies": {
80
80
  "@stylexjs/stylex": "*"