stylex-webpack 0.4.6 → 0.4.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 +14 -20
- package/dist/stylex-loader.js +7 -1
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var path = require('node:path');
|
|
|
5
5
|
var process = require('node:process');
|
|
6
6
|
var identity = require('foxts/identity');
|
|
7
7
|
|
|
8
|
-
var version = "0.4.
|
|
8
|
+
var version = "0.4.7";
|
|
9
9
|
|
|
10
10
|
const PLUGIN_NAME = 'stylex';
|
|
11
11
|
const VIRTUAL_ENTRYPOINT_CSS_PATH = require.resolve('./stylex.css');
|
|
@@ -159,31 +159,25 @@ class StyleXPlugin {
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
+
if (this.loaderOption.nextjsMode && this.loaderOption.nextjsAppRouterMode && isNextJsCompilerName(compiler.name)) {
|
|
163
|
+
var _globalThis;
|
|
164
|
+
(_globalThis = globalThis).__stylex_nextjs_global_registry__ ?? (_globalThis.__stylex_nextjs_global_registry__ = new Map());
|
|
165
|
+
globalThis.__stylex_nextjs_global_registry__.set(compiler.name, this.stylexRules);
|
|
166
|
+
}
|
|
162
167
|
});
|
|
163
168
|
compilation.hooks.processAssets.tapPromise({
|
|
164
169
|
name: PLUGIN_NAME,
|
|
165
170
|
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
166
171
|
}, async (assets)=>{
|
|
167
|
-
if (this.loaderOption.nextjsMode && this.loaderOption.nextjsAppRouterMode &&
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- type safe
|
|
175
|
-
if (compiler.name === NEXTJS_COMPILER_NAMES.client) {
|
|
176
|
-
const globalRegistry = globalThis.__stylex_nextjs_global_registry__;
|
|
177
|
-
if (globalRegistry != null) {
|
|
178
|
-
// now we merge all collected rules from other compilers
|
|
179
|
-
globalRegistry.forEach((rules)=>{
|
|
180
|
-
rules.forEach((rule, resourcePath)=>{
|
|
181
|
-
this.stylexRules.set(resourcePath, rule);
|
|
182
|
-
});
|
|
172
|
+
if (this.loaderOption.nextjsMode && this.loaderOption.nextjsAppRouterMode && compiler.name === NEXTJS_COMPILER_NAMES.client) {
|
|
173
|
+
const globalRegistry = globalThis.__stylex_nextjs_global_registry__;
|
|
174
|
+
if (globalRegistry != null) {
|
|
175
|
+
// now we merge all collected rules from other compilers
|
|
176
|
+
globalRegistry.forEach((rules)=>{
|
|
177
|
+
rules.forEach((rule, resourcePath)=>{
|
|
178
|
+
this.stylexRules.set(resourcePath, rule);
|
|
183
179
|
});
|
|
184
|
-
}
|
|
185
|
-
} else {
|
|
186
|
-
compiler.name;
|
|
180
|
+
});
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
const stylexCSS = getStyleXRules(this.stylexRules, this.useCSSLayers);
|
package/dist/stylex-loader.js
CHANGED
|
@@ -4,6 +4,7 @@ var core = require('@babel/core');
|
|
|
4
4
|
var stylexBabelPlugin = require('@stylexjs/babel-plugin');
|
|
5
5
|
var guard = require('foxts/guard');
|
|
6
6
|
|
|
7
|
+
const LOADER_TRANSFORMED_FLAG = '/* [stylex-webpack] stylex-loader transformed */';
|
|
7
8
|
require.resolve('./stylex.css');
|
|
8
9
|
const VIRTUAL_STYLEX_CSS_DUMMY_IMPORT_PATH = require.resolve('./stylex-virtual.css');
|
|
9
10
|
const BUILD_INFO_STYLEX_KEY = '~stylex_webpack_stylex_rules';
|
|
@@ -15,6 +16,11 @@ function stringifyRequest(loaderContext, request) {
|
|
|
15
16
|
const PLUGIN_NAME = 'stylex';
|
|
16
17
|
async function stylexLoader(inputCode, inputSourceMap) {
|
|
17
18
|
const callback = this.async();
|
|
19
|
+
// bail out early if already transformed
|
|
20
|
+
// for some reason, a module might be passed to stylex-loader more than once, happened with Next.js App Router
|
|
21
|
+
if (inputCode.includes(LOADER_TRANSFORMED_FLAG)) {
|
|
22
|
+
return callback(null, inputCode, inputSourceMap);
|
|
23
|
+
}
|
|
18
24
|
const { stylexImports, stylexOption } = this.getOptions();
|
|
19
25
|
// bail out early if the input doesn't contain stylex imports
|
|
20
26
|
if (!stylexImports.some((importName)=>inputCode.includes(importName))) {
|
|
@@ -56,7 +62,7 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
56
62
|
stylex: JSON.stringify(metadata.stylex) // color: #fff is not url safe, let's get through JSON.stringify
|
|
57
63
|
});
|
|
58
64
|
const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_STYLEX_CSS_DUMMY_IMPORT_PATH}?${urlParams.toString()}`);
|
|
59
|
-
const postfix = `\nimport ${virtualCssRequest}
|
|
65
|
+
const postfix = `\nimport ${virtualCssRequest};\n${LOADER_TRANSFORMED_FLAG}`;
|
|
60
66
|
return callback(null, code + postfix, map ?? undefined);
|
|
61
67
|
} catch (error) {
|
|
62
68
|
return callback(error);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylex-webpack",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@eslint-sukka/node": "^8.0.2",
|
|
61
61
|
"@rollup/plugin-json": "^6.1.0",
|
|
62
62
|
"@swc-node/register": "^1.11.1",
|
|
63
|
-
"@swc/core": "^1.15.
|
|
63
|
+
"@swc/core": "^1.15.1",
|
|
64
64
|
"@types/babel__core": "^7.20.5",
|
|
65
65
|
"@types/loader-utils": "^3.0.0",
|
|
66
66
|
"@types/mocha": "^10.0.10",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"next": "^15.5.6",
|
|
80
80
|
"postcss": "^8.5.6",
|
|
81
81
|
"premove": "^4.0.0",
|
|
82
|
-
"rollup": "^4.
|
|
82
|
+
"rollup": "^4.53.1",
|
|
83
83
|
"rollup-plugin-copy": "^3.5.0",
|
|
84
84
|
"rollup-plugin-dts": "^6.2.3",
|
|
85
85
|
"rollup-plugin-swc3": "^0.12.1",
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
"eslint>chalk": "npm:picocolors@^1.1.1"
|
|
97
97
|
},
|
|
98
98
|
"onlyBuiltDependencies": [
|
|
99
|
+
"@swc/core",
|
|
99
100
|
"oxc-resolver"
|
|
100
101
|
]
|
|
101
102
|
}
|