@stylexswc/nextjs-plugin 0.5.1 → 0.6.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 +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -56
- package/package.json +9 -8
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ experience with StyleX:
|
|
|
26
26
|
experience.
|
|
27
27
|
- Integrates seamlessly with Next.js SWC Compiler for a streamlined workflow.
|
|
28
28
|
|
|
29
|
-
###
|
|
29
|
+
### StyleX NAPI-RS Compiler
|
|
30
30
|
|
|
31
31
|
- Utilizes NAPI-RS to compile StyleX code, offering advantages over the SWC
|
|
32
32
|
plugin approach.
|
|
@@ -74,6 +74,13 @@ npm install --save-dev @stylexswc/nextjs-plugin
|
|
|
74
74
|
- Default: `false`
|
|
75
75
|
- Description: Enables CSS cascade layers support for better style isolation.
|
|
76
76
|
|
|
77
|
+
#### `extractCSS`
|
|
78
|
+
|
|
79
|
+
- Type: `boolean`
|
|
80
|
+
- Optional
|
|
81
|
+
- Default: `true`
|
|
82
|
+
- Description: Controls whether CSS should be extracted into a separate file
|
|
83
|
+
|
|
77
84
|
### Advanced Options
|
|
78
85
|
|
|
79
86
|
#### `transformCss`
|
|
@@ -100,7 +107,6 @@ module.exports = stylexPlugin({
|
|
|
100
107
|
},
|
|
101
108
|
unstable_moduleResolution: {
|
|
102
109
|
type: 'commonJS',
|
|
103
|
-
rootDir,
|
|
104
110
|
},
|
|
105
111
|
},
|
|
106
112
|
stylexImports: ['@stylexjs/stylex', { from: './theme', as: 'tokens' }],
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAmFpE,QAAA,MAAM,UAAU,mBACG,kBAAkB,mBACtB,UAAU,KAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,gCAAgC,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAmFpE,QAAA,MAAM,UAAU,mBACG,kBAAkB,mBACtB,UAAU,KAAQ,UA6I9B,CAAC;AAEJ,eAAe,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -117,60 +117,63 @@ const withStyleX = (pluginOptions) => (nextConfig = {}) => {
|
|
|
117
117
|
config.optimization ||= {};
|
|
118
118
|
config.optimization.splitChunks ||= {};
|
|
119
119
|
config.optimization.splitChunks.cacheGroups ||= {};
|
|
120
|
+
const extractCSS = pluginOptions?.extractCSS ?? true;
|
|
121
|
+
config.plugins ??= [];
|
|
120
122
|
let lazyPostCSSPromise = null;
|
|
121
123
|
const postcss = () => {
|
|
122
124
|
lazyPostCSSPromise ||= (0, css_1.lazyPostCSS)(ctx.dir, getSupportedBrowsers(ctx.dir, ctx.dev), undefined, false);
|
|
123
125
|
return lazyPostCSSPromise;
|
|
124
126
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
rule
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
setRule
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
127
|
+
if (extractCSS) {
|
|
128
|
+
const MiniCssExtractPlugin = getNextMiniCssExtractPlugin(ctx.dev);
|
|
129
|
+
// Based on https://github.com/vercel/next.js/blob/88a5f263f11cb55907f0d89a4cd53647ee8e96ac/packages/next/build/webpack/config/helpers.ts#L12-L18
|
|
130
|
+
const cssRules = (config.module?.rules?.find(rule => typeof rule === 'object' &&
|
|
131
|
+
rule !== null &&
|
|
132
|
+
Array.isArray(rule.oneOf) &&
|
|
133
|
+
rule.oneOf.some(setRule => setRule &&
|
|
134
|
+
setRule.test instanceof RegExp &&
|
|
135
|
+
typeof setRule.test.test === 'function' &&
|
|
136
|
+
setRule.test.test('filename.css')))).oneOf;
|
|
137
|
+
// Here we matches virtual css file emitted by StyleXPlugin
|
|
138
|
+
cssRules?.unshift({
|
|
139
|
+
test: webpack_plugin_1.VIRTUAL_CSS_PATTERN,
|
|
140
|
+
use: getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin, postcss),
|
|
141
|
+
});
|
|
142
|
+
// StyleX need to emit the css file on both server and client, both during the
|
|
143
|
+
// development and production.
|
|
144
|
+
// However, Next.js only add MiniCssExtractPlugin on client + production.
|
|
145
|
+
//
|
|
146
|
+
// To simplify the logic at our side, we will add MiniCssExtractPlugin based on
|
|
147
|
+
// the "instanceof" check (We will only add our required MiniCssExtractPlugin if
|
|
148
|
+
// Next.js hasn't added it yet).
|
|
149
|
+
// This also prevent multiple MiniCssExtractPlugin being added (which will cause
|
|
150
|
+
// RealContentHashPlugin to panic)
|
|
151
|
+
if (!config.plugins.some((plugin) => plugin instanceof MiniCssExtractPlugin)) {
|
|
152
|
+
// HMR reloads the CSS file when the content changes but does not use
|
|
153
|
+
// the new file name, which means it can't contain a hash.
|
|
154
|
+
const filename = ctx.dev ? 'static/css/[name].css' : 'static/css/[contenthash].css';
|
|
155
|
+
// Logic adopted from https://git.io/JtdBy
|
|
156
|
+
config.plugins.push(new MiniCssExtractPlugin({
|
|
157
|
+
filename,
|
|
158
|
+
chunkFilename: filename,
|
|
159
|
+
// Next.js guarantees that CSS order "doesn't matter", due to imposed
|
|
160
|
+
// restrictions:
|
|
161
|
+
// 1. Global CSS can only be defined in a single entrypoint (_app)
|
|
162
|
+
// 2. CSS Modules generate scoped class names by default and cannot
|
|
163
|
+
// include Global CSS (:global() selector).
|
|
164
|
+
//
|
|
165
|
+
// While not a perfect guarantee (e.g. liberal use of `:global()`
|
|
166
|
+
// selector), this assumption is required to code-split CSS.
|
|
167
|
+
//
|
|
168
|
+
// As for StyleX, the CSS is always atomic (so classes are always unique),
|
|
169
|
+
// and StyleX Plugin will always sort the css based on media query and pseudo
|
|
170
|
+
// selector.
|
|
171
|
+
//
|
|
172
|
+
// If this warning were to trigger, it'd be unactionable by the user,
|
|
173
|
+
// but likely not valid -- so just disable it.
|
|
174
|
+
ignoreOrder: true,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
174
177
|
}
|
|
175
178
|
config.plugins.push(new webpack_plugin_1.default({
|
|
176
179
|
...pluginOptions,
|
|
@@ -180,14 +183,18 @@ const withStyleX = (pluginOptions) => (nextConfig = {}) => {
|
|
|
180
183
|
},
|
|
181
184
|
// Enforce nextjsMode to true
|
|
182
185
|
nextjsMode: true,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
...(extractCSS
|
|
187
|
+
? {
|
|
188
|
+
async transformCss(css) {
|
|
189
|
+
const { postcssWithPlugins } = await postcss();
|
|
190
|
+
const result = await postcssWithPlugins.process(css);
|
|
191
|
+
if (typeof pluginOptions?.transformCss === 'function') {
|
|
192
|
+
return pluginOptions.transformCss(result.css);
|
|
193
|
+
}
|
|
194
|
+
return result.css;
|
|
195
|
+
},
|
|
188
196
|
}
|
|
189
|
-
|
|
190
|
-
},
|
|
197
|
+
: { transformCss: undefined }),
|
|
191
198
|
}));
|
|
192
199
|
return config;
|
|
193
200
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/nextjs-plugin",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "StyleX NextJS plugin with NAPI-RS compiler",
|
|
4
|
+
"version": "0.6.0-rc.1",
|
|
5
5
|
"config": {
|
|
6
6
|
"scripty": {
|
|
7
7
|
"path": "../../scripts/packages"
|
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@babel/types": "^7.23.9",
|
|
12
|
-
"@stylexswc/eslint-config": "0.
|
|
13
|
-
"@stylexswc/rs-compiler": "0.
|
|
14
|
-
"@stylexswc/typescript-config": "0.
|
|
15
|
-
"@stylexswc/webpack-plugin": "0.
|
|
12
|
+
"@stylexswc/eslint-config": "0.6.0-rc.1",
|
|
13
|
+
"@stylexswc/rs-compiler": "0.6.0-rc.1",
|
|
14
|
+
"@stylexswc/typescript-config": "0.6.0-rc.1",
|
|
15
|
+
"@stylexswc/webpack-plugin": "0.6.0-rc.1",
|
|
16
16
|
"@types/babel__core": "^7.20.5",
|
|
17
17
|
"@types/node": "^22.5.1",
|
|
18
|
-
"next": "^15.
|
|
18
|
+
"next": "^15.1.2",
|
|
19
19
|
"postcss": "^8.4.49",
|
|
20
20
|
"react": "^19.0.0",
|
|
21
21
|
"react-dom": "^19.0.0",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"next",
|
|
29
29
|
"nextjs",
|
|
30
30
|
"nextjs-plugin",
|
|
31
|
-
"stylex"
|
|
31
|
+
"stylex",
|
|
32
|
+
"swc"
|
|
32
33
|
],
|
|
33
34
|
"license": "MIT",
|
|
34
35
|
"main": "dist/index.js",
|