@stylexswc/webpack-plugin 0.13.0-rc.1 → 0.13.0-rc.10

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 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
@@ -1,15 +1,15 @@
1
- import stylexBabelPlugin from '@stylexjs/babel-plugin';
2
1
  import { VIRTUAL_CSS_PATTERN } from './constants';
3
2
  import type webpack from 'webpack';
4
3
  import type { Rule as StyleXRule } from '@stylexjs/babel-plugin';
5
4
  import type { CSSTransformer, StyleXPluginOption, StyleXWebpackLoaderOptions } from './types';
6
5
  export type RegisterStyleXRules = (_resourcePath: string, _stylexRules: StyleXRule[]) => void;
7
6
  export default class StyleXPlugin {
8
- stylexRules: Map<string, readonly stylexBabelPlugin.Rule[]>;
7
+ stylexRules: Map<string, readonly StyleXRule[]>;
9
8
  useCSSLayers: boolean;
10
9
  loaderOption: StyleXWebpackLoaderOptions;
11
10
  transformCss: CSSTransformer;
12
- constructor({ stylexImports, useCSSLayers, rsOptions, nextjsMode, transformCss, transformer, extractCSS, }?: StyleXPluginOption);
11
+ loaderOrder: StyleXPluginOption['loaderOrder'];
12
+ constructor({ stylexImports, useCSSLayers, rsOptions, nextjsMode, transformCss, extractCSS, loaderOrder, }?: StyleXPluginOption);
13
13
  apply(compiler: webpack.Compiler): void;
14
14
  }
15
15
  export { VIRTUAL_CSS_PATTERN };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,wBAAwB,CAAC;AAEvD,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,CAAC;AAkBjB,MAAM,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;AAE9F,MAAM,CAAC,OAAO,OA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AAC;AAE/B,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -25,7 +25,8 @@ class StyleXPlugin {
25
25
  useCSSLayers;
26
26
  loaderOption;
27
27
  transformCss;
28
- constructor({ stylexImports = ['stylex', '@stylexjs/stylex'], useCSSLayers = false, rsOptions = {}, nextjsMode = false, transformCss = identityTransfrom, transformer = 'rs-compiler', extractCSS = true, } = {}) {
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,13 +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
- transformer,
42
43
  extractCSS,
43
44
  };
44
45
  this.transformCss = transformCss;
46
+ this.loaderOrder = loaderOrder;
45
47
  }
46
48
  apply(compiler) {
47
49
  // If splitChunk is enabled, we create a dedicated chunk for stylex css
@@ -92,11 +94,8 @@ class StyleXPlugin {
92
94
  this.stylexRules.set(resourcePath, stylexRules);
93
95
  },
94
96
  };
95
- // We use .unshift() and not .push() like original webpack plugin
96
- // because we want to transpile theme imports first,
97
- // else it will be unused imports, that will be removed by tree shaking,
98
- // and to run other transformations first, e.g. custom SWC plugins.
99
- mod.loaders.unshift({
97
+ const insertMethod = this.loaderOrder === 'last' ? 'unshift' : 'push';
98
+ mod.loaders[insertMethod]({
100
99
  loader: stylexLoaderPath,
101
100
  options: this.loaderOption,
102
101
  ident: null,
@@ -171,4 +170,6 @@ class StyleXPlugin {
171
170
  exports.default = StyleXPlugin;
172
171
  module.exports = StyleXPlugin;
173
172
  module.exports.default = StyleXPlugin;
173
+ module.exports.loader = stylexLoaderPath;
174
+ module.exports.virtualLoader = stylexVirtualLoaderPath;
174
175
  module.exports.VIRTUAL_CSS_PATTERN = constants_1.VIRTUAL_CSS_PATTERN;
@@ -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;AAE7C,wBAA8B,YAAY,CACxC,IAAI,EAAE,aAAa,CAAC,uBAAuB,GAAG,0BAA0B,CAAC,EACzE,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,SAAS,iBAqG1B"}
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"}
@@ -7,12 +7,13 @@ exports.default = stylexLoader;
7
7
  const constants_1 = require("./constants");
8
8
  const loader_utils_1 = __importDefault(require("loader-utils"));
9
9
  const utils_1 = require("./utils");
10
+ const skipWarnRegex = /empty|client-only/;
10
11
  async function stylexLoader(inputCode, inputSourceMap) {
11
12
  const callback = this.async();
12
- const { stylexImports, rsOptions, nextjsMode, transformer, extractCSS = true, } = this.getOptions();
13
+ const { stylexImports, rsOptions, nextjsMode, extractCSS = true } = this.getOptions();
13
14
  const logger = this._compiler?.getInfrastructureLogger(constants_1.PLUGIN_NAME);
14
15
  if (!inputCode) {
15
- if (!this.resourcePath.includes('empty')) {
16
+ if (!skipWarnRegex.test(this.resourcePath)) {
16
17
  logger?.warn(`@stylexswc/webpack-plugin: inputCode is empty for resource ${this.resourcePath}`);
17
18
  }
18
19
  return callback(null, inputCode, inputSourceMap);
@@ -29,7 +30,16 @@ async function stylexLoader(inputCode, inputSourceMap) {
29
30
  return callback(new Error('stylex-loader: loader context is not SupplementedLoaderContext!'));
30
31
  }
31
32
  try {
32
- const { code, map, metadata } = (0, utils_1.generateStyleXOutput)(this.resourcePath, stringifiedInputCode, rsOptions, transformer);
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
+ }
33
43
  // If metadata.stylex doesn't exist at all, we only need to return the transformed code
34
44
  if (!extractCSS ||
35
45
  !metadata ||
@@ -38,7 +48,7 @@ async function stylexLoader(inputCode, inputSourceMap) {
38
48
  !metadata.stylex.length) {
39
49
  if (extractCSS)
40
50
  logger?.debug(`No stylex styles generated from ${this.resourcePath}`);
41
- return callback(null, code ?? undefined, map ?? undefined);
51
+ return callback(null, code, parsedMap);
42
52
  }
43
53
  logger?.debug(`Read stylex styles from ${this.resourcePath}:`, metadata.stylex);
44
54
  this.StyleXWebpackContextKey.registerStyleXRules(this.resourcePath, metadata.stylex);
@@ -53,13 +63,13 @@ async function stylexLoader(inputCode, inputSourceMap) {
53
63
  const virtualFileName = loader_utils_1.default.interpolateName(this, '[path][name].[hash:base64:8].stylex.virtual.css', { content: serializedStyleXRules });
54
64
  const virtualCssRequest = (0, utils_1.stringifyRequest)(this, `${virtualFileName}!=!${constants_1.VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
55
65
  const postfix = `\nimport ${virtualCssRequest};`;
56
- return callback(null, code + postfix, map ?? undefined);
66
+ return callback(null, code + postfix, parsedMap);
57
67
  }
58
68
  // Next.js App Router doesn't support inline matchResource and inline loaders
59
69
  // So we adapt Next.js' "external" css import approach instead
60
70
  const virtualCssRequest = (0, utils_1.stringifyRequest)(this, `${constants_1.VIRTUAL_CSS_PATH}?${urlParams.toString()}`);
61
71
  const postfix = `\nimport ${virtualCssRequest};`;
62
- return callback(null, code + postfix, map ?? undefined);
72
+ return callback(null, code + postfix, parsedMap);
63
73
  }
64
74
  catch (error) {
65
75
  return callback(error);
package/dist/types.d.ts CHANGED
@@ -6,7 +6,7 @@ type AsyncFnParams = Parameters<ReturnType<LoaderContext<unknown>['async']>>;
6
6
  export type InputCode = AsyncFnParams['1'];
7
7
  export type SourceMap = AsyncFnParams['2'];
8
8
  export type CSSTransformer = (_css: string, _filePath: string | undefined) => string | Buffer | Promise<string | Buffer>;
9
- export interface StyleXPluginOption extends Pick<StyleXWebpackLoaderOptions, 'transformer'> {
9
+ export interface StyleXPluginOption {
10
10
  /**
11
11
  * stylex options passed to stylex babel plugin
12
12
  *
@@ -44,17 +44,21 @@ export interface StyleXPluginOption extends Pick<StyleXWebpackLoaderOptions, 'tr
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'];
50
60
  rsOptions: Partial<StyleXOptions>;
51
61
  nextjsMode: boolean;
52
- /**
53
- * Specify the transformer to transform StyleX code
54
- *
55
- * @default 'rs-compiler'
56
- */
57
- transformer?: 'rs-compiler' | 'swc';
58
62
  extractCSS?: boolean;
59
63
  };
60
64
  export type SupplementedLoaderContext<Options = unknown> = webpack.LoaderContext<Options> & {
@@ -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,kBAAmB,SAAQ,IAAI,CAAC,0BAA0B,EAAE,aAAa,CAAC;IACzF;;;;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,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC;IAE9B;;;;OAIG;IACH,UAAU,CAAC,EA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ugin from '@stylexswc/rs-compiler';
2
2
  import type webpack from 'webpack';
3
- import type { StyleXWebpackLoaderOptions, SupplementedLoaderContext } from './types';
3
+ import type { SupplementedLoaderContext } from './types';
4
4
  import type { StyleXTransformResult } from '@stylexswc/rs-compiler';
5
5
  export declare function stringifyRequest(loaderContext: webpack.LoaderContext<unknown>, request: string): string;
6
6
  export declare const isSupplementedLoaderContext: <T>(context: webpack.LoaderContext<T>) => context is SupplementedLoaderContext<T>;
7
- export declare function generateStyleXOutput(resourcePath: string, inputSource: string, rsOptions: Partial<stylexPlugin.StyleXOptions>, transformer: StyleXWebpackLoaderOptions['transformer']): StyleXTransformResult;
7
+ export declare function generateStyleXOutput(resourcePath: string, inputSource: string, rsOptions: Partial<stylexPlugin.StyleXOptions>): StyleXTransformResult;
8
8
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,YAAoC,MAAM,wBAAwB,CAAC;AAE1E,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAiB,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,UAI9F;AAED,eAAO,MAAM,2BAA2B,GAAI,CAAC,EAC3C,SAAS,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,KAChC,OAAO,IAAI,yBAAyB,CAAC,CAAC,CAExC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,EAC9C,WAAW,EAAE,0BAA0B,CAAC,aAAa,CAAC,GACrD,qBAAqB,CA4BvB"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,YAAoC,MAAM,wBAAwB,CAAC;AAE1E,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,UAI9F;AAED,eAAO,MAAM,2BAA2B,GAAI,CAAC,EAC3C,SAAS,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,KAChC,OAAO,IAAI,yBAAyB,CAAC,CAAC,CAExC,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,aAAa,CAAC,GAC7C,qBAAqB,CAEvB"}
package/dist/utils.js CHANGED
@@ -44,22 +44,6 @@ const isSupplementedLoaderContext = (context) => {
44
44
  return Object.prototype.hasOwnProperty.call(context, 'StyleXWebpackContextKey');
45
45
  };
46
46
  exports.isSupplementedLoaderContext = isSupplementedLoaderContext;
47
- function generateStyleXOutput(resourcePath, inputSource, rsOptions, transformer) {
48
- if (transformer === 'swc') {
49
- const metadata = { stylex: [] };
50
- let metadataStr = '[]';
51
- const code = inputSource.replace(/\/\/*__stylex_metadata_start__(?<metadata>.+)__stylex_metadata_end__/, (...args) => {
52
- metadataStr = args.at(-1)?.metadata.split('"__stylex_metadata_end__')[0];
53
- return '';
54
- });
55
- try {
56
- metadata.stylex = JSON.parse(metadataStr)?.map((rule) => [rule.class_name, rule.style, rule.priority]);
57
- }
58
- catch (e) {
59
- console.error('Error parsing StylexX metadata', e);
60
- }
61
- const map = undefined;
62
- return { code, map, metadata };
63
- }
47
+ function generateStyleXOutput(resourcePath, inputSource, rsOptions) {
64
48
  return rs_compiler_1.default.transform(resourcePath, inputSource, (0, rs_compiler_1.normalizeRsOptions)(rsOptions ?? {}));
65
49
  }
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.0-rc.1",
4
+ "version": "0.13.0-rc.10",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -18,17 +18,17 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@stylexjs/babel-plugin": "^0.16.2",
22
- "@stylexswc/rs-compiler": "0.13.0-rc.1",
21
+ "@stylexjs/babel-plugin": "^0.16.3",
22
+ "@stylexswc/rs-compiler": "0.13.0-rc.10",
23
23
  "loader-utils": "^3.3.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@babel/types": "^7.28.4",
27
- "@stylexswc/eslint-config": "0.13.0-rc.1",
28
- "@stylexswc/typescript-config": "0.13.0-rc.1",
26
+ "@babel/types": "^7.28.5",
27
+ "@stylexswc/eslint-config": "0.13.0-rc.10",
28
+ "@stylexswc/typescript-config": "0.13.0-rc.10",
29
29
  "@types/babel__core": "^7.20.5",
30
30
  "@types/loader-utils": "^3.0.0",
31
- "@types/node": "^24.7.2",
31
+ "@types/node": "^24.9.2",
32
32
  "mini-css-extract-plugin": "^2.9.2",
33
33
  "webpack": "^5.102.1"
34
34
  },