stylex-webpack 0.2.0 → 0.2.1-beta.1
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 +15 -0
- package/dist/stylex-loader.js +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -98,6 +98,21 @@ class StyleXPlugin {
|
|
|
98
98
|
if (stylexChunk == null) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
+
// Collect stylex rules from module instead of self maintained map
|
|
102
|
+
if (this.loaderOption.nextjsMode) {
|
|
103
|
+
const cssModulesInStylexChunk = compilation.chunkGraph.getChunkModulesIterableBySourceType(stylexChunk, 'css/mini-extract');
|
|
104
|
+
// we only re-collect stylex rules if we can found css in the stylex chunk
|
|
105
|
+
if (cssModulesInStylexChunk) {
|
|
106
|
+
this.stylexRules = new Map();
|
|
107
|
+
for (const cssModule of cssModulesInStylexChunk){
|
|
108
|
+
const stringifiedStylexRule = cssModule._identifier.split('!').pop()?.split('?').pop();
|
|
109
|
+
if (!stringifiedStylexRule) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
this.stylexRules.set(cssModule.identifier(), JSON.parse(decodeURIComponent(stringifiedStylexRule)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
101
116
|
// Let's find the css file that belongs to the stylex chunk
|
|
102
117
|
const cssAssetDetails = Object.entries(assets).find(([assetName])=>stylexChunk.files.has(assetName));
|
|
103
118
|
if (!cssAssetDetails) {
|
package/dist/stylex-loader.js
CHANGED
|
@@ -54,7 +54,8 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
54
54
|
// TODO: rspack doesn't support custom loader context
|
|
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
59
|
if (!nextjsMode) {
|
|
59
60
|
// Normal webpack mode
|
|
60
61
|
// We generate a virtual css file that looks like it is relative to the source
|