@stylexswc/rollup-plugin 0.17.0-rc.4 → 0.17.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 +131 -82
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/package.json +17 -5
package/README.md
CHANGED
|
@@ -1,123 +1,174 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
# @stylexswc/rollup-plugin
|
|
2
|
+
|
|
3
|
+
> StyleX plugin for Rollup, powered by a Rust compiler (NAPI-RS + SWC). Part of
|
|
4
|
+
> the [StyleX SWC Plugin](https://github.com/Dwlad90/stylex-swc-plugin#readme)
|
|
5
|
+
> workspace.
|
|
6
|
+
|
|
7
|
+
This plugin compiles [StyleX](https://stylexjs.com) code in your Rollup build
|
|
8
|
+
with
|
|
9
|
+
[`@stylexswc/rs-compiler`](https://www.npmjs.com/package/@stylexswc/rs-compiler),
|
|
10
|
+
a Rust implementation of the StyleX transform, instead of the official Babel
|
|
11
|
+
plugin. Your StyleX code stays exactly the same — only the build step changes,
|
|
12
|
+
with per-file transforms 2x to 5x faster than Babel
|
|
13
|
+
([performance](https://github.com/Dwlad90/stylex-swc-plugin#performance)).
|
|
14
|
+
The extracted CSS is processed with [Lightning CSS](https://lightningcss.dev)
|
|
15
|
+
before it is written to disk.
|
|
16
|
+
|
|
17
|
+
This is a community project and is not affiliated with Meta. It tracks the
|
|
18
|
+
official StyleX releases
|
|
19
|
+
<!-- stylex-compatibility:start -->(currently compatible with StyleX v0.19.0)<!-- stylex-compatibility:end -->
|
|
20
|
+
and requires Node.js 20 or newer.
|
|
8
21
|
|
|
9
22
|
## Installation
|
|
10
23
|
|
|
11
|
-
To install the package, run the following command:
|
|
12
|
-
|
|
13
24
|
```bash
|
|
14
|
-
npm install --save-dev @stylexswc/
|
|
25
|
+
npm install --save-dev @stylexswc/rollup-plugin
|
|
15
26
|
```
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
The Rust compiler (`@stylexswc/rs-compiler`) is installed automatically as a
|
|
29
|
+
dependency. Your application still needs the StyleX runtime:
|
|
18
30
|
|
|
19
31
|
```bash
|
|
20
|
-
npm install
|
|
32
|
+
npm install @stylexjs/stylex
|
|
21
33
|
```
|
|
22
34
|
|
|
23
35
|
## Usage
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
Add the plugin to your Rollup config:
|
|
26
38
|
|
|
27
39
|
```js
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
// rollup.config.mjs
|
|
41
|
+
import stylexPlugin from '@stylexswc/rollup-plugin';
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
main: './js/index.js',
|
|
34
|
-
},
|
|
43
|
+
export default {
|
|
44
|
+
input: 'src/index.js',
|
|
35
45
|
output: {
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
file: 'dist/bundle.js',
|
|
47
|
+
format: 'cjs',
|
|
38
48
|
},
|
|
39
49
|
plugins: [
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
stylexPlugin.default({
|
|
51
|
+
fileName: 'stylex.css',
|
|
52
|
+
rsOptions: {
|
|
53
|
+
dev: process.env.NODE_ENV !== 'production',
|
|
54
|
+
},
|
|
43
55
|
}),
|
|
44
56
|
],
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
module.exports = config;
|
|
57
|
+
};
|
|
49
58
|
```
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
> [!NOTE]
|
|
61
|
+
> In an ESM config file the plugin is exposed on the `default` property
|
|
62
|
+
> because the package is compiled to CommonJS — hence
|
|
63
|
+
> `stylexPlugin.default(...)`. With a CommonJS config
|
|
64
|
+
> (`const stylexPlugin = require('@stylexswc/rollup-plugin')`), call
|
|
65
|
+
> `stylexPlugin(...)` directly.
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
A complete working setup, including JSX handling via `@rollup/plugin-swc`, lives
|
|
68
|
+
in the
|
|
69
|
+
[`rollup-example` app](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/apps/rollup-example).
|
|
70
|
+
|
|
71
|
+
## Plugin Options
|
|
54
72
|
|
|
55
73
|
### `rsOptions`
|
|
56
74
|
|
|
57
75
|
- Type: `StyleXOptions`
|
|
58
76
|
- Optional
|
|
59
77
|
- Default: `{}`
|
|
60
|
-
- Description: StyleX compiler options
|
|
61
|
-
|
|
78
|
+
- Description: StyleX compiler options passed to `@stylexswc/rs-compiler`. For
|
|
79
|
+
the standard options, see the
|
|
80
|
+
[official StyleX documentation](https://stylexjs.com/docs/api/configuration/babel-plugin/).
|
|
62
81
|
|
|
63
82
|
> [!NOTE]
|
|
64
|
-
>
|
|
83
|
+
> The `include` and `exclude` options are exclusive to the Rust compiler
|
|
84
|
+
> and are not available in the official StyleX Babel plugin.
|
|
65
85
|
|
|
66
86
|
#### `rsOptions.include`
|
|
67
87
|
|
|
68
88
|
- Type: `(string | RegExp)[]`
|
|
69
89
|
- Optional
|
|
70
|
-
- Description:
|
|
71
|
-
When specified, only files matching at least one
|
|
72
|
-
Patterns are matched against paths relative to the current
|
|
73
|
-
|
|
90
|
+
- Description: Glob patterns or regular expressions selecting the files to
|
|
91
|
+
transform. When specified, only files matching at least one pattern are
|
|
92
|
+
transformed. Patterns are matched against paths relative to the current
|
|
93
|
+
working directory. Regular expressions support lookahead and lookbehind.
|
|
74
94
|
|
|
75
95
|
#### `rsOptions.exclude`
|
|
76
96
|
|
|
77
97
|
- Type: `(string | RegExp)[]`
|
|
78
98
|
- Optional
|
|
79
|
-
- Description:
|
|
80
|
-
|
|
81
|
-
Patterns are matched against paths relative to the
|
|
82
|
-
|
|
99
|
+
- Description: Glob patterns or regular expressions excluding files from the
|
|
100
|
+
transform. A file matching any exclude pattern is skipped even if it matches
|
|
101
|
+
an `include` pattern. Patterns are matched against paths relative to the
|
|
102
|
+
current working directory. Regular expressions support lookahead and
|
|
103
|
+
lookbehind.
|
|
83
104
|
|
|
84
|
-
###
|
|
105
|
+
### `fileName`
|
|
85
106
|
|
|
86
|
-
|
|
107
|
+
- Type: `string`
|
|
108
|
+
- Optional
|
|
109
|
+
- Default: `'stylex.css'`
|
|
110
|
+
- Description: Name of the emitted CSS asset.
|
|
87
111
|
|
|
88
|
-
|
|
89
|
-
|
|
112
|
+
### `useCSSLayers`
|
|
113
|
+
|
|
114
|
+
- Type: `boolean`
|
|
115
|
+
- Optional
|
|
116
|
+
- Default: `false`
|
|
117
|
+
- Description: Wraps the generated CSS in cascade layers for better style
|
|
118
|
+
isolation.
|
|
119
|
+
|
|
120
|
+
### `lightningcssOptions`
|
|
121
|
+
|
|
122
|
+
- Type: `TransformOptions`
|
|
123
|
+
- Optional
|
|
124
|
+
- Description: Options forwarded to the Lightning CSS transform that
|
|
125
|
+
post-processes the extracted CSS (everything except `code`, `filename`, and
|
|
126
|
+
`visitor`).
|
|
127
|
+
|
|
128
|
+
### `extractCSS`
|
|
129
|
+
|
|
130
|
+
- Type: `boolean`
|
|
131
|
+
- Optional
|
|
132
|
+
- Default: `true`
|
|
133
|
+
- Description: Controls whether the generated CSS is extracted into a separate
|
|
134
|
+
file.
|
|
135
|
+
|
|
136
|
+
## Path Filtering Examples
|
|
137
|
+
|
|
138
|
+
Include only specific directories:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
stylexPlugin.default({
|
|
90
142
|
rsOptions: {
|
|
91
143
|
include: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
92
144
|
},
|
|
93
|
-
})
|
|
145
|
+
});
|
|
94
146
|
```
|
|
95
147
|
|
|
96
|
-
|
|
148
|
+
Exclude test and build files:
|
|
97
149
|
|
|
98
|
-
```
|
|
99
|
-
stylexPlugin({
|
|
150
|
+
```js
|
|
151
|
+
stylexPlugin.default({
|
|
100
152
|
rsOptions: {
|
|
101
153
|
exclude: ['**/*.test.*', '**/*.spec.*', '**/dist/**'],
|
|
102
154
|
},
|
|
103
|
-
})
|
|
155
|
+
});
|
|
104
156
|
```
|
|
105
157
|
|
|
106
|
-
|
|
158
|
+
Exclude all of `node_modules` except specific packages (negative lookahead):
|
|
107
159
|
|
|
108
|
-
```
|
|
109
|
-
stylexPlugin({
|
|
160
|
+
```js
|
|
161
|
+
stylexPlugin.default({
|
|
110
162
|
rsOptions: {
|
|
111
|
-
// Exclude all node_modules except @stylexjs packages
|
|
112
163
|
exclude: [/node_modules(?!\/@stylexjs)/],
|
|
113
164
|
},
|
|
114
|
-
})
|
|
165
|
+
});
|
|
115
166
|
```
|
|
116
167
|
|
|
117
|
-
|
|
168
|
+
Transform only specific packages from `node_modules`:
|
|
118
169
|
|
|
119
|
-
```
|
|
120
|
-
stylexPlugin({
|
|
170
|
+
```js
|
|
171
|
+
stylexPlugin.default({
|
|
121
172
|
rsOptions: {
|
|
122
173
|
include: [
|
|
123
174
|
'src/**/*.{ts,tsx,js,jsx}',
|
|
@@ -125,42 +176,40 @@ stylexPlugin({
|
|
|
125
176
|
],
|
|
126
177
|
exclude: ['**/*.test.*'],
|
|
127
178
|
},
|
|
128
|
-
})
|
|
179
|
+
});
|
|
129
180
|
```
|
|
130
181
|
|
|
131
|
-
|
|
182
|
+
## FAQ
|
|
132
183
|
|
|
133
|
-
|
|
134
|
-
- Optional
|
|
135
|
-
- Default: `'stylex.css'`
|
|
136
|
-
- Description: Name of the output CSS file
|
|
184
|
+
### Do I still need `@stylexjs/babel-plugin`?
|
|
137
185
|
|
|
138
|
-
|
|
186
|
+
No. This plugin replaces the Babel plugin in your build. You only keep
|
|
187
|
+
`@stylexjs/stylex` as your app's runtime dependency, and your `stylex.create` /
|
|
188
|
+
`stylex.props` code does not change.
|
|
139
189
|
|
|
140
|
-
|
|
141
|
-
- Optional
|
|
142
|
-
- Default: `false`
|
|
143
|
-
- Description: Enable CSS Layers support for better style isolation
|
|
190
|
+
### Does this work together with other Rollup plugins?
|
|
144
191
|
|
|
145
|
-
|
|
192
|
+
Yes. Run StyleX after resolution/commonjs plugins and alongside your transpiler
|
|
193
|
+
plugin (SWC or Babel). The
|
|
194
|
+
[example app](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/apps/rollup-example)
|
|
195
|
+
shows a full pipeline with `@rollup/plugin-swc`.
|
|
146
196
|
|
|
147
|
-
-
|
|
148
|
-
- Optional
|
|
149
|
-
- Description: LightningCSS transform options (excluding code, filename, and
|
|
150
|
-
visitor properties)
|
|
197
|
+
### How do I post-process the generated CSS?
|
|
151
198
|
|
|
152
|
-
|
|
199
|
+
The plugin already runs Lightning CSS on the extracted stylesheet; tune it with
|
|
200
|
+
`lightningcssOptions` (for example `targets` from a browserslist query).
|
|
153
201
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
-
|
|
157
|
-
|
|
202
|
+
### Is this an official StyleX package?
|
|
203
|
+
|
|
204
|
+
No. It is a community-maintained alternative to the official tooling and is not
|
|
205
|
+
affiliated with or supported by Meta.
|
|
158
206
|
|
|
159
207
|
## Documentation
|
|
160
208
|
|
|
161
|
-
- [StyleX
|
|
162
|
-
- [
|
|
209
|
+
- [StyleX documentation](https://stylexjs.com)
|
|
210
|
+
- [`@stylexswc/rs-compiler` compiler options](https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/crates/stylex-rs-compiler)
|
|
163
211
|
|
|
164
212
|
## License
|
|
165
213
|
|
|
166
|
-
MIT — see
|
|
214
|
+
MIT — see
|
|
215
|
+
[LICENSE](https://github.com/Dwlad90/stylex-swc-plugin/blob/develop/LICENSE)
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAA2C,MAAM,QAAQ,CAAC;AAM9E,OAAO,KAAK,EAAE,aAAa,EAAsB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAU/F,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,mBAAmB,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC,CAAC;IAC7F,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,SAAc,EACd,QAAuB,EACvB,YAAoB,EACpB,mBAAmB,EACnB,UAAiB,GAClB,GAAE,aAAkB,GAAG,MAAM,CA8H7B"}
|
package/dist/index.js
CHANGED
|
@@ -71,6 +71,23 @@ function stylexPlugin({ rsOptions = {}, fileName = 'stylex.css', useCSSLayers =
|
|
|
71
71
|
// "no changes made".
|
|
72
72
|
return null;
|
|
73
73
|
}
|
|
74
|
+
// The combined map of all previous plugins lets the compiler resolve
|
|
75
|
+
// debug source-map annotations to the original authored file, and lets
|
|
76
|
+
// it chain its emitted map onto it. Rollup resets the sourcemap chain
|
|
77
|
+
// when `getCombinedSourcemap` is used, so returning the chained map is
|
|
78
|
+
// the expected contract.
|
|
79
|
+
if (normalizedRsOptions.inputSourceMap === undefined) {
|
|
80
|
+
try {
|
|
81
|
+
const combinedMap = this.getCombinedSourcemap();
|
|
82
|
+
if (combinedMap?.mappings) {
|
|
83
|
+
normalizedRsOptions.inputSourceMap = JSON.stringify(combinedMap);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
// No usable source map for this module - annotations fall back to
|
|
88
|
+
// locating positions in the source text.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
74
91
|
const result = (0, rs_compiler_1.transform)(id, inputCode, normalizedRsOptions);
|
|
75
92
|
if (result == null) {
|
|
76
93
|
console.warn('stylex: transformAsync returned null');
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/rollup-plugin",
|
|
3
|
-
"description": "StyleX
|
|
4
|
-
"version": "0.17.
|
|
3
|
+
"description": "StyleX plugin for Rollup powered by a Rust NAPI-RS/SWC compiler. Fast StyleX transforms and CSS extraction without Babel.",
|
|
4
|
+
"version": "0.17.1-rc.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
22
|
-
"@stylexswc/rs-compiler": "0.17.
|
|
22
|
+
"@stylexswc/rs-compiler": "0.17.1-rc.1",
|
|
23
23
|
"lightningcss": "^1.32.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
@@ -32,14 +32,26 @@
|
|
|
32
32
|
"jest-chain-transform": "^0.0.8",
|
|
33
33
|
"rollup": "^4.62.2"
|
|
34
34
|
},
|
|
35
|
+
"bugs": "https://github.com/Dwlad90/stylex-swc-plugin/issues",
|
|
36
|
+
"homepage": "https://github.com/Dwlad90/stylex-swc-plugin/tree/develop/packages/rollup-plugin#readme",
|
|
35
37
|
"keywords": [
|
|
38
|
+
"atomic-css",
|
|
39
|
+
"css-extraction",
|
|
40
|
+
"css-in-js",
|
|
41
|
+
"lightningcss",
|
|
42
|
+
"napi-rs",
|
|
43
|
+
"rollup",
|
|
36
44
|
"rollup-plugin",
|
|
37
|
-
"
|
|
45
|
+
"rust",
|
|
38
46
|
"stylex",
|
|
39
47
|
"swc"
|
|
40
48
|
],
|
|
41
49
|
"main": "dist/index.js",
|
|
42
|
-
"repository":
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/Dwlad90/stylex-swc-plugin.git",
|
|
53
|
+
"directory": "packages/rollup-plugin"
|
|
54
|
+
},
|
|
43
55
|
"scripts": {
|
|
44
56
|
"build": "scripty --ts --flatten",
|
|
45
57
|
"check:artifacts": "scripty",
|