@stylexswc/nextjs-plugin 0.12.1-rc.1 → 0.13.0-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 CHANGED
@@ -39,6 +39,74 @@ To install the package, run the following command:
39
39
  npm install --save-dev @stylexswc/nextjs-plugin
40
40
  ```
41
41
 
42
+ ## Usage
43
+
44
+ This plugin supports both Webpack and Turbopack configurations in Next.js.
45
+
46
+ ### Using with Webpack
47
+
48
+ For standard Next.js Webpack builds, use the default import:
49
+
50
+ ```javascript
51
+ const stylexPlugin = require('@stylexswc/nextjs-plugin');
52
+
53
+ module.exports = stylexPlugin({
54
+ // StyleX options here
55
+ })({
56
+ // Next.js config here
57
+ });
58
+ ```
59
+
60
+ ### Using with Turbopack
61
+
62
+ > [!IMPORTANT]
63
+ > **Turbopack Limitation**: Turbopack does not support webpack plugins ([see Next.js docs](https://nextjs.org/docs/app/api-reference/turbopack#webpack-plugins)). When using Turbopack, the loader only compiles StyleX code but **does not extract CSS**.
64
+ >
65
+ > **You must configure the PostCSS plugin for CSS extraction.** Install `@stylexswc/postcss-plugin` and configure it in `postcss.config.js`:
66
+ >
67
+ > ```javascript
68
+ > // postcss.config.js
69
+ > module.exports = {
70
+ > plugins: {
71
+ > '@stylexswc/postcss-plugin': {
72
+ > rsOptions: {
73
+ > dev: process.env.NODE_ENV === 'development',
74
+ > },
75
+ > },
76
+ > autoprefixer: {},
77
+ > },
78
+ > };
79
+ > ```
80
+
81
+ For Next.js with Turbopack, use the `/turbopack` export:
82
+
83
+ ```typescript
84
+ import withStylexTurbopack from '@stylexswc/nextjs-plugin/turbopack';
85
+
86
+ export default withStylexTurbopack({
87
+ // StyleX options here same as postcss-plugin
88
+ rsOptions: {
89
+ dev: process.env.NODE_ENV === 'development',
90
+ },
91
+ })({
92
+ // Next.js config here
93
+ experimental: {
94
+ turbopack: {
95
+ // Additional Turbopack configuration if needed
96
+ },
97
+ },
98
+ });
99
+ ```
100
+
101
+ > [!NOTE]
102
+ > When using Turbopack, the following options are not supported and will be ignored:
103
+ >
104
+ > - `useCSSLayers`
105
+ > - `nextjsMode`
106
+ > - `transformCss`
107
+ > - `extractCSS`
108
+ > - `transformer`
109
+
42
110
  ## Plugin Options
43
111
 
44
112
  ### Basic Options
@@ -47,8 +115,9 @@ npm install --save-dev @stylexswc/nextjs-plugin
47
115
 
48
116
  - Type: `Partial<StyleXOptions>`
49
117
  - Optional
50
- - Description: StyleX compiler options that will be passed to the NAPI-RS compiler.
51
- For standard StyleX options, see the [official StyleX documentation](https://stylexjs.com/docs/api/configuration/babel-plugin/).
118
+ - Description: StyleX compiler options that will be passed to the NAPI-RS
119
+ compiler. For standard StyleX options, see the
120
+ [official StyleX documentation](https://stylexjs.com/docs/api/configuration/babel-plugin/).
52
121
 
53
122
  > [!NOTE]
54
123
  > **New Features:** The `include` and `exclude` options are exclusive to this NAPI-RS compiler implementation and are not available in the official StyleX Babel plugin.
@@ -57,17 +126,21 @@ npm install --save-dev @stylexswc/nextjs-plugin
57
126
 
58
127
  - Type: `(string | RegExp)[]`
59
128
  - Optional
60
- - Description: **RS-compiler Only** An array of glob patterns or regular expressions to include specific files for StyleX transformation.
61
- When specified, only files matching at least one of these patterns will be transformed.
62
- Patterns are matched against paths relative to the current working directory.
129
+ - Description: **RS-compiler Only** An array of glob patterns or regular
130
+ expressions to include specific files for StyleX transformation. When
131
+ specified, only files matching at least one of these patterns will be
132
+ transformed. Patterns are matched against paths relative to the current
133
+ working directory.
63
134
 
64
135
  ##### `rsOptions.exclude`
65
136
 
66
137
  - Type: `(string | RegExp)[]`
67
138
  - Optional
68
- - Description: **RS-compiler Only** An array of glob patterns or regular expressions to exclude specific files from StyleX transformation.
69
- Files matching any of these patterns will not be transformed, even if they match an `include` pattern.
70
- Patterns are matched against paths relative to the current working directory.
139
+ - Description: **RS-compiler Only** An array of glob patterns or regular
140
+ expressions to exclude specific files from StyleX transformation. Files
141
+ matching any of these patterns will not be transformed, even if they match an
142
+ `include` pattern. Patterns are matched against paths relative to the current
143
+ working directory.
71
144
 
72
145
  #### `stylexImports`
73
146
 
@@ -101,6 +174,8 @@ npm install --save-dev @stylexswc/nextjs-plugin
101
174
 
102
175
  ### Example Configuration
103
176
 
177
+ #### Webpack Configuration
178
+
104
179
  ```javascript
105
180
  const path = require('path');
106
181
  const stylexPlugin = require('@stylexswc/nextjs-plugin');
@@ -111,7 +186,11 @@ module.exports = stylexPlugin({
111
186
  rsOptions: {
112
187
  dev: process.env.NODE_ENV !== 'production',
113
188
  // Include only specific directories
114
- include: ['app/**/*.{ts,tsx}', 'components/**/*.{ts,tsx}', 'src/**/*.{ts,tsx}'],
189
+ include: [
190
+ 'app/**/*.{ts,tsx}',
191
+ 'components/**/*.{ts,tsx}',
192
+ 'src/**/*.{ts,tsx}',
193
+ ],
115
194
  // Exclude test files and API routes
116
195
  exclude: ['**/*.test.*', '**/*.stories.*', '**/__tests__/**', 'app/api/**'],
117
196
  aliases: {
@@ -140,6 +219,65 @@ module.exports = stylexPlugin({
140
219
  });
141
220
  ```
142
221
 
222
+ #### Turbopack Configuration
223
+
224
+ ```typescript
225
+ import path from 'path';
226
+ import withStylexTurbopack from '@stylexswc/nextjs-plugin/turbopack';
227
+
228
+ const rootDir = __dirname;
229
+
230
+ export default withStylexTurbopack({
231
+ // Add any StyleX options here
232
+ rsOptions: {
233
+ dev: process.env.NODE_ENV !== 'production',
234
+ aliases: {
235
+ '@/*': [path.join(rootDir, '*')],
236
+ },
237
+ unstable_moduleResolution: {
238
+ type: 'commonJS',
239
+ },
240
+ },
241
+ stylexImports: ['@stylexjs/stylex'],
242
+ })({
243
+ transpilePackages: ['@stylexjs/open-props'],
244
+ experimental: {
245
+ turbopack: {
246
+ // Additional Turbopack configuration if needed
247
+ },
248
+ },
249
+ // Optionally, add any other Next.js config below
250
+ });
251
+ ```
252
+
253
+ ##### Required: PostCSS Configuration for CSS Extraction
254
+
255
+ ```javascript
256
+ // postcss.config.js
257
+ const path = require('path');
258
+
259
+ module.exports = {
260
+ plugins: {
261
+ '@stylexswc/postcss-plugin': {
262
+ include: [
263
+ 'app/**/*.{js,jsx,ts,tsx}',
264
+ 'components/**/*.{js,jsx,ts,tsx}',
265
+ ],
266
+ rsOptions: {
267
+ aliases: {
268
+ '@/*': [path.join(__dirname, '*')],
269
+ },
270
+ unstable_moduleResolution: {
271
+ type: 'commonJS',
272
+ },
273
+ dev: process.env.NODE_ENV === 'development',
274
+ },
275
+ },
276
+ autoprefixer: {},
277
+ },
278
+ };
279
+ ```
280
+
143
281
  ### Path Filtering Examples
144
282
 
145
283
  **Include only specific directories:**
@@ -149,7 +287,7 @@ stylexPlugin({
149
287
  rsOptions: {
150
288
  include: ['app/**/*.tsx', 'components/**/*.tsx'],
151
289
  },
152
- })
290
+ });
153
291
  ```
154
292
 
155
293
  **Exclude test and build files:**
@@ -159,7 +297,7 @@ stylexPlugin({
159
297
  rsOptions: {
160
298
  exclude: ['**/*.test.*', '**/*.spec.*', '**/dist/**', '**/node_modules/**'],
161
299
  },
162
- })
300
+ });
163
301
  ```
164
302
 
165
303
  **Using regular expressions:**
@@ -170,7 +308,7 @@ stylexPlugin({
170
308
  include: [/app\/.*\.tsx$/, /components\/.*\.tsx$/],
171
309
  exclude: [/\.test\./, /\.stories\./],
172
310
  },
173
- })
311
+ });
174
312
  ```
175
313
 
176
314
  **Combined include and exclude (exclude takes precedence):**
@@ -181,7 +319,7 @@ stylexPlugin({
181
319
  include: ['app/**/*.{ts,tsx}', 'components/**/*.{ts,tsx}'],
182
320
  exclude: ['**/__tests__/**', '**/__mocks__/**', 'app/api/**'],
183
321
  },
184
- })
322
+ });
185
323
  ```
186
324
 
187
325
  **Exclude node_modules except specific packages:**
@@ -192,7 +330,7 @@ stylexPlugin({
192
330
  // Exclude all node_modules except @stylexjs/open-props
193
331
  exclude: [/node_modules(?!\/@stylexjs\/open-props)/],
194
332
  },
195
- })
333
+ });
196
334
  ```
197
335
 
198
336
  **Transform only specific packages from node_modules:**
@@ -208,7 +346,7 @@ stylexPlugin({
208
346
  ],
209
347
  exclude: ['**/*.test.*', 'app/api/**'],
210
348
  },
211
- })
349
+ });
212
350
  ```
213
351
 
214
352
  ## Examples
@@ -0,0 +1,5 @@
1
+ import type { NextConfig } from 'next/dist/server/config-shared';
2
+ import type { StyleXPluginOption } from '@stylexswc/webpack-plugin';
3
+ declare const withStyleX: (pluginOptions?: Omit<StyleXPluginOption, "useCSSLayers" | "nextjsMode" | "transformCss" | "extractCSS" | "transformer">) => (nextConfig?: NextConfig) => NextConfig;
4
+ export default withStyleX;
5
+ //# sourceMappingURL=turbopack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turbopack.d.ts","sourceRoot":"","sources":["../src/turbopack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAuB,MAAM,gCAAgC,CAAC;AACtF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,QAAA,MAAM,UAAU,GAEZ,gBAAgB,IAAI,CAClB,kBAAkB,EAClB,cAAc,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,GAAG,aAAa,CAC9E,MAEF,aAAY,UAAe,KAAG,UA+B9B,CAAC;AAEJ,eAAe,UAAU,CAAC"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const withStyleX = (pluginOptions) => (nextConfig = {}) => {
4
+ const reactLoaders = [
5
+ {
6
+ loader: '@stylexswc/turbopack-plugin/loader',
7
+ // @ts-expect-error - StyleXPluginOption is compatible with Next.js' Turbopack loader options, but types are not aligned yet
8
+ options: {
9
+ ...pluginOptions,
10
+ },
11
+ },
12
+ ];
13
+ return {
14
+ ...nextConfig,
15
+ turbopack: {
16
+ ...nextConfig?.turbopack,
17
+ rules: {
18
+ '*.ts': {
19
+ loaders: reactLoaders,
20
+ },
21
+ '*.tsx': {
22
+ loaders: reactLoaders,
23
+ },
24
+ '*.js': {
25
+ loaders: reactLoaders,
26
+ },
27
+ '*.jsx': {
28
+ loaders: reactLoaders,
29
+ },
30
+ },
31
+ },
32
+ };
33
+ };
34
+ exports.default = withStyleX;
35
+ module.exports = withStyleX;
36
+ module.exports.default = withStyleX;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stylexswc/nextjs-plugin",
3
3
  "description": "StyleX NextJS plugin with NAPI-RS compiler",
4
- "version": "0.12.1-rc.1",
4
+ "version": "0.13.0-rc.1",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "sideEffects": false,
@@ -12,25 +12,39 @@
12
12
  "registry": "https://registry.npmjs.org/",
13
13
  "access": "public"
14
14
  },
15
+ "exports": {
16
+ "./turbopack": {
17
+ "import": "./dist/turbopack.js",
18
+ "require": "./dist/turbopack.js",
19
+ "types": "./dist/turbopack.d.ts"
20
+ },
21
+ ".": {
22
+ "import": "./dist/index.js",
23
+ "require": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
25
+ },
26
+ "./package.json": "./package.json"
27
+ },
15
28
  "config": {
16
29
  "scripty": {
17
30
  "path": "../../scripts/packages"
18
31
  }
19
32
  },
20
33
  "dependencies": {
21
- "@stylexswc/rs-compiler": "0.12.1-rc.1",
22
- "@stylexswc/webpack-plugin": "0.12.1-rc.1"
34
+ "@stylexswc/rs-compiler": "0.13.0-rc.1",
35
+ "@stylexswc/turbopack-plugin": "0.13.0-rc.1",
36
+ "@stylexswc/webpack-plugin": "0.13.0-rc.1"
23
37
  },
24
38
  "devDependencies": {
25
39
  "@babel/types": "^7.28.4",
26
- "@stylexswc/eslint-config": "0.12.1-rc.1",
27
- "@stylexswc/typescript-config": "0.12.1-rc.1",
40
+ "@stylexswc/eslint-config": "0.13.0-rc.1",
41
+ "@stylexswc/typescript-config": "0.13.0-rc.1",
28
42
  "@types/babel__core": "^7.20.5",
29
43
  "@types/node": "^24.7.2",
30
- "next": "^15.5.4",
44
+ "next": "^16.0.0",
31
45
  "postcss": "^8.5.6",
32
- "react": "^19.1.1",
33
- "react-dom": "^19.1.1",
46
+ "react": "^19.2.0",
47
+ "react-dom": "^19.2.0",
34
48
  "webpack": "^5.102.1"
35
49
  },
36
50
  "peerDependencies": {