@stylexswc/nextjs-plugin 0.12.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 +152 -15
- package/dist/turbopack.d.ts +5 -0
- package/dist/turbopack.d.ts.map +1 -0
- package/dist/turbopack.js +36 -0
- package/package.json +24 -10
package/README.md
CHANGED
|
@@ -39,6 +39,73 @@ 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
|
+
|
|
42
109
|
## Plugin Options
|
|
43
110
|
|
|
44
111
|
### Basic Options
|
|
@@ -47,8 +114,9 @@ npm install --save-dev @stylexswc/nextjs-plugin
|
|
|
47
114
|
|
|
48
115
|
- Type: `Partial<StyleXOptions>`
|
|
49
116
|
- Optional
|
|
50
|
-
- Description: StyleX compiler options that will be passed to the NAPI-RS
|
|
51
|
-
For standard StyleX options, see the
|
|
117
|
+
- Description: StyleX compiler options that will be passed to the NAPI-RS
|
|
118
|
+
compiler. For standard StyleX options, see the
|
|
119
|
+
[official StyleX documentation](https://stylexjs.com/docs/api/configuration/babel-plugin/).
|
|
52
120
|
|
|
53
121
|
> [!NOTE]
|
|
54
122
|
> **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 +125,21 @@ npm install --save-dev @stylexswc/nextjs-plugin
|
|
|
57
125
|
|
|
58
126
|
- Type: `(string | RegExp)[]`
|
|
59
127
|
- Optional
|
|
60
|
-
- Description: **RS-compiler Only** An array of glob patterns or regular
|
|
61
|
-
|
|
62
|
-
|
|
128
|
+
- Description: **RS-compiler Only** An array of glob patterns or regular
|
|
129
|
+
expressions to include specific files for StyleX transformation. When
|
|
130
|
+
specified, only files matching at least one of these patterns will be
|
|
131
|
+
transformed. Patterns are matched against paths relative to the current
|
|
132
|
+
working directory.
|
|
63
133
|
|
|
64
134
|
##### `rsOptions.exclude`
|
|
65
135
|
|
|
66
136
|
- Type: `(string | RegExp)[]`
|
|
67
137
|
- Optional
|
|
68
|
-
- Description: **RS-compiler Only** An array of glob patterns or regular
|
|
69
|
-
|
|
70
|
-
|
|
138
|
+
- Description: **RS-compiler Only** An array of glob patterns or regular
|
|
139
|
+
expressions to exclude specific files from StyleX transformation. Files
|
|
140
|
+
matching any of these patterns will not be transformed, even if they match an
|
|
141
|
+
`include` pattern. Patterns are matched against paths relative to the current
|
|
142
|
+
working directory.
|
|
71
143
|
|
|
72
144
|
#### `stylexImports`
|
|
73
145
|
|
|
@@ -101,6 +173,8 @@ npm install --save-dev @stylexswc/nextjs-plugin
|
|
|
101
173
|
|
|
102
174
|
### Example Configuration
|
|
103
175
|
|
|
176
|
+
#### Webpack Configuration
|
|
177
|
+
|
|
104
178
|
```javascript
|
|
105
179
|
const path = require('path');
|
|
106
180
|
const stylexPlugin = require('@stylexswc/nextjs-plugin');
|
|
@@ -111,7 +185,11 @@ module.exports = stylexPlugin({
|
|
|
111
185
|
rsOptions: {
|
|
112
186
|
dev: process.env.NODE_ENV !== 'production',
|
|
113
187
|
// Include only specific directories
|
|
114
|
-
include: [
|
|
188
|
+
include: [
|
|
189
|
+
'app/**/*.{ts,tsx}',
|
|
190
|
+
'components/**/*.{ts,tsx}',
|
|
191
|
+
'src/**/*.{ts,tsx}',
|
|
192
|
+
],
|
|
115
193
|
// Exclude test files and API routes
|
|
116
194
|
exclude: ['**/*.test.*', '**/*.stories.*', '**/__tests__/**', 'app/api/**'],
|
|
117
195
|
aliases: {
|
|
@@ -140,6 +218,65 @@ module.exports = stylexPlugin({
|
|
|
140
218
|
});
|
|
141
219
|
```
|
|
142
220
|
|
|
221
|
+
#### Turbopack Configuration
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import path from 'path';
|
|
225
|
+
import withStylexTurbopack from '@stylexswc/nextjs-plugin/turbopack';
|
|
226
|
+
|
|
227
|
+
const rootDir = __dirname;
|
|
228
|
+
|
|
229
|
+
export default withStylexTurbopack({
|
|
230
|
+
// Add any StyleX options here
|
|
231
|
+
rsOptions: {
|
|
232
|
+
dev: process.env.NODE_ENV !== 'production',
|
|
233
|
+
aliases: {
|
|
234
|
+
'@/*': [path.join(rootDir, '*')],
|
|
235
|
+
},
|
|
236
|
+
unstable_moduleResolution: {
|
|
237
|
+
type: 'commonJS',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
stylexImports: ['@stylexjs/stylex'],
|
|
241
|
+
})({
|
|
242
|
+
transpilePackages: ['@stylexjs/open-props'],
|
|
243
|
+
experimental: {
|
|
244
|
+
turbopack: {
|
|
245
|
+
// Additional Turbopack configuration if needed
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
// Optionally, add any other Next.js config below
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
##### Required: PostCSS Configuration for CSS Extraction
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
// postcss.config.js
|
|
256
|
+
const path = require('path');
|
|
257
|
+
|
|
258
|
+
module.exports = {
|
|
259
|
+
plugins: {
|
|
260
|
+
'@stylexswc/postcss-plugin': {
|
|
261
|
+
include: [
|
|
262
|
+
'app/**/*.{js,jsx,ts,tsx}',
|
|
263
|
+
'components/**/*.{js,jsx,ts,tsx}',
|
|
264
|
+
],
|
|
265
|
+
rsOptions: {
|
|
266
|
+
aliases: {
|
|
267
|
+
'@/*': [path.join(__dirname, '*')],
|
|
268
|
+
},
|
|
269
|
+
unstable_moduleResolution: {
|
|
270
|
+
type: 'commonJS',
|
|
271
|
+
},
|
|
272
|
+
dev: process.env.NODE_ENV === 'development',
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
autoprefixer: {},
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
```
|
|
279
|
+
|
|
143
280
|
### Path Filtering Examples
|
|
144
281
|
|
|
145
282
|
**Include only specific directories:**
|
|
@@ -149,7 +286,7 @@ stylexPlugin({
|
|
|
149
286
|
rsOptions: {
|
|
150
287
|
include: ['app/**/*.tsx', 'components/**/*.tsx'],
|
|
151
288
|
},
|
|
152
|
-
})
|
|
289
|
+
});
|
|
153
290
|
```
|
|
154
291
|
|
|
155
292
|
**Exclude test and build files:**
|
|
@@ -159,7 +296,7 @@ stylexPlugin({
|
|
|
159
296
|
rsOptions: {
|
|
160
297
|
exclude: ['**/*.test.*', '**/*.spec.*', '**/dist/**', '**/node_modules/**'],
|
|
161
298
|
},
|
|
162
|
-
})
|
|
299
|
+
});
|
|
163
300
|
```
|
|
164
301
|
|
|
165
302
|
**Using regular expressions:**
|
|
@@ -170,7 +307,7 @@ stylexPlugin({
|
|
|
170
307
|
include: [/app\/.*\.tsx$/, /components\/.*\.tsx$/],
|
|
171
308
|
exclude: [/\.test\./, /\.stories\./],
|
|
172
309
|
},
|
|
173
|
-
})
|
|
310
|
+
});
|
|
174
311
|
```
|
|
175
312
|
|
|
176
313
|
**Combined include and exclude (exclude takes precedence):**
|
|
@@ -181,7 +318,7 @@ stylexPlugin({
|
|
|
181
318
|
include: ['app/**/*.{ts,tsx}', 'components/**/*.{ts,tsx}'],
|
|
182
319
|
exclude: ['**/__tests__/**', '**/__mocks__/**', 'app/api/**'],
|
|
183
320
|
},
|
|
184
|
-
})
|
|
321
|
+
});
|
|
185
322
|
```
|
|
186
323
|
|
|
187
324
|
**Exclude node_modules except specific packages:**
|
|
@@ -192,7 +329,7 @@ stylexPlugin({
|
|
|
192
329
|
// Exclude all node_modules except @stylexjs/open-props
|
|
193
330
|
exclude: [/node_modules(?!\/@stylexjs\/open-props)/],
|
|
194
331
|
},
|
|
195
|
-
})
|
|
332
|
+
});
|
|
196
333
|
```
|
|
197
334
|
|
|
198
335
|
**Transform only specific packages from node_modules:**
|
|
@@ -208,7 +345,7 @@ stylexPlugin({
|
|
|
208
345
|
],
|
|
209
346
|
exclude: ['**/*.test.*', 'app/api/**'],
|
|
210
347
|
},
|
|
211
|
-
})
|
|
348
|
+
});
|
|
212
349
|
```
|
|
213
350
|
|
|
214
351
|
## 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">) => (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,CAC9D,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.
|
|
4
|
+
"version": "0.13.0-rc.10",
|
|
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.
|
|
22
|
-
"@stylexswc/
|
|
34
|
+
"@stylexswc/rs-compiler": "0.13.0-rc.10",
|
|
35
|
+
"@stylexswc/turbopack-plugin": "0.13.0-rc.10",
|
|
36
|
+
"@stylexswc/webpack-plugin": "0.13.0-rc.10"
|
|
23
37
|
},
|
|
24
38
|
"devDependencies": {
|
|
25
|
-
"@babel/types": "^7.28.
|
|
26
|
-
"@stylexswc/eslint-config": "0.
|
|
27
|
-
"@stylexswc/typescript-config": "0.
|
|
39
|
+
"@babel/types": "^7.28.5",
|
|
40
|
+
"@stylexswc/eslint-config": "0.13.0-rc.10",
|
|
41
|
+
"@stylexswc/typescript-config": "0.13.0-rc.10",
|
|
28
42
|
"@types/babel__core": "^7.20.5",
|
|
29
|
-
"@types/node": "^24.
|
|
30
|
-
"next": "^
|
|
43
|
+
"@types/node": "^24.9.2",
|
|
44
|
+
"next": "^16.0.1",
|
|
31
45
|
"postcss": "^8.5.6",
|
|
32
|
-
"react": "^19.
|
|
33
|
-
"react-dom": "^19.
|
|
46
|
+
"react": "^19.2.0",
|
|
47
|
+
"react-dom": "^19.2.0",
|
|
34
48
|
"webpack": "^5.102.1"
|
|
35
49
|
},
|
|
36
50
|
"peerDependencies": {
|