@stylexswc/webpack-plugin 0.13.0-rc.9 → 0.13.1-rc.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/README.md +30 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/stylex-loader.d.ts.map +1 -1
- package/dist/stylex-loader.js +12 -3
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -113,6 +113,35 @@ module.exports = config;
|
|
|
113
113
|
- Default: `true`
|
|
114
114
|
- Description: Controls whether CSS should be extracted into a separate file
|
|
115
115
|
|
|
116
|
+
#### `loaderOrder`
|
|
117
|
+
|
|
118
|
+
- Type: `'first' | 'last'`
|
|
119
|
+
- Optional
|
|
120
|
+
- Default: `'first'`
|
|
121
|
+
- Description: Determines when the StyleX transformation is applied relative to other webpack loaders.
|
|
122
|
+
- `'first'` (recommended): StyleX processes the source code before any other loaders run.
|
|
123
|
+
Automatically enables `injectStylexSideEffects` to prevent tree-shaking from removing `.stylex` and `.consts` imports.
|
|
124
|
+
- `'last'`: StyleX processes after all other loaders have completed.
|
|
125
|
+
Use this if you need other loaders (like TypeScript or SWC plugins) to transform your code before StyleX processing.
|
|
126
|
+
|
|
127
|
+
**Why `'first'` is recommended:**
|
|
128
|
+
When StyleX transforms your code first, imports from `.stylex` and `.consts` files may appear unused to subsequent loaders/bundlers and get removed by tree-shaking. The plugin automatically injects side-effect imports to prevent this issue.
|
|
129
|
+
|
|
130
|
+
**Example of the problem:**
|
|
131
|
+
```ts
|
|
132
|
+
// Before transformation
|
|
133
|
+
import { colors } from './theme.stylex';
|
|
134
|
+
const styles = stylex.create({
|
|
135
|
+
root: { backgroundColor: colors.primary }
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// After StyleX transformation (appears unused to bundler)
|
|
139
|
+
import { colors } from './theme.stylex'; // ← May be tree-shaken!
|
|
140
|
+
const styles = { root: { backgroundColor: 'x1a2b3c', $$css: true } };
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
With `loaderOrder: 'first'`, the plugin automatically preserves these imports by injecting side-effect imports.
|
|
144
|
+
|
|
116
145
|
### Advanced Options
|
|
117
146
|
|
|
118
147
|
#### `transformCss`
|
|
@@ -141,6 +170,7 @@ module.exports = {
|
|
|
141
170
|
stylexImports: ['@stylexjs/stylex', { from: './theme', as: 'tokens' }],
|
|
142
171
|
useCSSLayers: true,
|
|
143
172
|
nextjsMode: false,
|
|
173
|
+
loaderOrder: 'first', // Process before other loaders (default)
|
|
144
174
|
transformCss: async css => {
|
|
145
175
|
const postcss = require('postcss');
|
|
146
176
|
const result = await postcss([require('autoprefixer')]).process(css);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export default class StyleXPlugin {
|
|
|
8
8
|
useCSSLayers: boolean;
|
|
9
9
|
loaderOption: StyleXWebpackLoaderOptions;
|
|
10
10
|
transformCss: CSSTransformer;
|
|
11
|
-
|
|
11
|
+
loaderOrder: StyleXPluginOption['loaderOrder'];
|
|
12
|
+
constructor({ stylexImports, useCSSLayers, rsOptions, nextjsMode, transformCss, extractCSS, loaderOrder, }?: StyleXPluginOption);
|
|
12
13
|
apply(compiler: webpack.Compiler): void;
|
|
13
14
|
}
|
|
14
15
|
export { VIRTUAL_CSS_PATTERN };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,0BAA0B,EAE3B,MAAM,SAAS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
25
|
useCSSLayers;
|
|
26
26
|
loaderOption;
|
|
27
27
|
transformCss;
|
|
28
|
-
|
|
28
|
+
loaderOrder;
|
|
29
|
+
constructor({ stylexImports = ['stylex', '@stylexjs/stylex'], useCSSLayers = false, rsOptions = {}, nextjsMode = false, transformCss = identityTransfrom, extractCSS = true, loaderOrder = 'first', } = {}) {
|
|
29
30
|
this.useCSSLayers = useCSSLayers;
|
|
30
31
|
this.loaderOption = {
|
|
31
32
|
stylexImports,
|
|
@@ -35,12 +36,14 @@ class StyleXPlugin {
|
|
|
35
36
|
runtimeInjection: false,
|
|
36
37
|
treeshakeCompensation: true,
|
|
37
38
|
importSources: stylexImports,
|
|
39
|
+
injectStylexSideEffects: loaderOrder !== 'last',
|
|
38
40
|
...rsOptions,
|
|
39
41
|
},
|
|
40
42
|
nextjsMode,
|
|
41
43
|
extractCSS,
|
|
42
44
|
};
|
|
43
45
|
this.transformCss = transformCss;
|
|
46
|
+
this.loaderOrder = loaderOrder;
|
|
44
47
|
}
|
|
45
48
|
apply(compiler) {
|
|
46
49
|
// If splitChunk is enabled, we create a dedicated chunk for stylex css
|
|
@@ -91,11 +94,8 @@ class StyleXPlugin {
|
|
|
91
94
|
this.stylexRules.set(resourcePath, stylexRules);
|
|
92
95
|
},
|
|
93
96
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// else it will be unused imports, that will be removed by tree shaking,
|
|
97
|
-
// and to run other transformations first, e.g. custom SWC plugins.
|
|
98
|
-
mod.loaders.unshift({
|
|
97
|
+
const insertMethod = this.loaderOrder === 'last' ? 'unshift' : 'push';
|
|
98
|
+
mod.loaders[insertMethod]({
|
|
99
99
|
loader: stylexLoaderPath,
|
|
100
100
|
options: this.loaderOption,
|
|
101
101
|
ident: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylex-loader.d.ts","sourceRoot":"","sources":["../src/stylex-loader.ts"],"names":[],"mappings":"AACA,OAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,wBAA8B,YAAY,CACxC,IAAI,EAAE,aAAa,CAAC,uBAAuB,GAAG,0BAA0B,CAAC,EACzE,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"stylex-loader.d.ts","sourceRoot":"","sources":["../src/stylex-loader.ts"],"names":[],"mappings":"AACA,OAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,wBAA8B,YAAY,CACxC,IAAI,EAAE,aAAa,CAAC,uBAAuB,GAAG,0BAA0B,CAAC,EACzE,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,SAAS,iBA0G1B"}
|
package/dist/stylex-loader.js
CHANGED
|
@@ -31,6 +31,15 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
const { code, map, metadata } = (0, utils_1.generateStyleXOutput)(this.resourcePath, stringifiedInputCode, rsOptions);
|
|
34
|
+
let parsedMap = undefined;
|
|
35
|
+
if (map) {
|
|
36
|
+
try {
|
|
37
|
+
parsedMap = typeof map === 'string' ? JSON.parse(map) : map;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
logger?.warn(`@stylexswc/webpack-plugin: failed to parse map for resource ${this.resourcePath}: ${error.message}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
34
43
|
// If metadata.stylex doesn't exist at all, we only need to return the transformed code
|
|
35
44
|
if (!extractCSS ||
|
|
36
45
|
!metadata ||
|
|
@@ -39,7 +48,7 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
39
48
|
!metadata.stylex.length) {
|
|
40
49
|
if (extractCSS)
|
|
41
50
|
logger?.debug(`No stylex styles generated from ${this.resourcePath}`);
|
|
42
|
-
return callback(null, code
|
|
51
|
+
return callback(null, code, parsedMap);
|
|
43
52
|
}
|
|
44
53
|
logger?.debug(`Read stylex styles from ${this.resourcePath}:`, metadata.stylex);
|
|
45
54
|
this.StyleXWebpackContextKey.registerStyleXRules(this.resourcePath, metadata.stylex);
|
|
@@ -54,13 +63,13 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
54
63
|
const virtualFileName = loader_utils_1.default.interpolateName(this, '[path][name].[hash:base64:8].stylex.virtual.css', { content: serializedStyleXRules });
|
|
55
64
|
const virtualCssRequest = (0, utils_1.stringifyRequest)(this, `${virtualFileName}!=!${constants_1.VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
|
|
56
65
|
const postfix = `\nimport ${virtualCssRequest};`;
|
|
57
|
-
return callback(null, code + postfix,
|
|
66
|
+
return callback(null, code + postfix, parsedMap);
|
|
58
67
|
}
|
|
59
68
|
// Next.js App Router doesn't support inline matchResource and inline loaders
|
|
60
69
|
// So we adapt Next.js' "external" css import approach instead
|
|
61
70
|
const virtualCssRequest = (0, utils_1.stringifyRequest)(this, `${constants_1.VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
|
|
62
71
|
const postfix = `\nimport ${virtualCssRequest};`;
|
|
63
|
-
return callback(null, code + postfix,
|
|
72
|
+
return callback(null, code + postfix, parsedMap);
|
|
64
73
|
}
|
|
65
74
|
catch (error) {
|
|
66
75
|
return callback(error);
|
package/dist/types.d.ts
CHANGED
|
@@ -44,6 +44,16 @@ export interface StyleXPluginOption {
|
|
|
44
44
|
* @default true
|
|
45
45
|
*/
|
|
46
46
|
extractCSS?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Loader execution order
|
|
49
|
+
*
|
|
50
|
+
* Determines when the StyleX transformation is applied relative to other webpack loaders:
|
|
51
|
+
* - 'first': StyleX processes source code before any other loaders (recommended)
|
|
52
|
+
* - 'last': StyleX processes after all other loaders have run
|
|
53
|
+
*
|
|
54
|
+
* @default 'first'
|
|
55
|
+
*/
|
|
56
|
+
loaderOrder?: 'first' | 'last';
|
|
47
57
|
}
|
|
48
58
|
export type StyleXWebpackLoaderOptions = {
|
|
49
59
|
stylexImports: StyleXOptions['importSources'];
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,GAAG,CAAC;AAE7C,KAAK,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAC3C,MAAM,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AAE3C,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAAG,SAAS,KAC1B,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC/C;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH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OAAO,GAAG,MAAM,CAAC;CAChC;AACD,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC9C,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG;IAC1F,uBAAuB,EAAE;QACvB,mBAAmB,EAAE,mBAAmB,CAAC;KAC1C,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;KAAE,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/webpack-plugin",
|
|
3
3
|
"description": "StyleX webpack plugin with NAPI-RS compiler",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.1-rc.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@stylexjs/babel-plugin": "^0.16.3",
|
|
22
|
-
"@stylexswc/rs-compiler": "0.13.
|
|
22
|
+
"@stylexswc/rs-compiler": "0.13.1-rc.1",
|
|
23
23
|
"loader-utils": "^3.3.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/types": "^7.28.5",
|
|
27
|
-
"@stylexswc/eslint-config": "0.13.
|
|
28
|
-
"@stylexswc/typescript-config": "0.13.
|
|
27
|
+
"@stylexswc/eslint-config": "0.13.1-rc.1",
|
|
28
|
+
"@stylexswc/typescript-config": "0.13.1-rc.1",
|
|
29
29
|
"@types/babel__core": "^7.20.5",
|
|
30
30
|
"@types/loader-utils": "^3.0.0",
|
|
31
31
|
"@types/node": "^24.9.2",
|