unplugin-stylex 0.6.2 → 0.6.3
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/CHANGELOG.md +6 -0
- package/README.md +143 -84
- package/dist/astro.cjs +15 -15
- package/dist/astro.d.ts +38 -16
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -3
- package/dist/{chunk-KKH6K7RE.cjs → chunk-45JWH4GZ.cjs} +14 -11
- package/dist/{chunk-WUKLRLI4.js → chunk-5RGNKABP.js} +1 -1
- package/dist/{chunk-FEGNQ7CQ.js → chunk-SSMUIUHR.js} +14 -11
- package/dist/{chunk-O4FQWPVV.cjs → chunk-WDYGV6FU.cjs} +2 -2
- package/dist/core/build.d.ts +5 -0
- package/dist/core/build.d.ts.map +1 -0
- package/dist/core/options.d.ts +5 -0
- package/dist/core/options.d.ts.map +1 -0
- package/dist/core/plugins.d.ts +2 -0
- package/dist/core/plugins.d.ts.map +1 -0
- package/dist/core/transformers/astro.d.ts +3 -0
- package/dist/core/transformers/astro.d.ts.map +1 -0
- package/dist/core/transformers/default.d.ts +3 -0
- package/dist/core/transformers/default.d.ts.map +1 -0
- package/dist/core/transformers/index.d.ts +3 -0
- package/dist/core/transformers/index.d.ts.map +1 -0
- package/dist/core/transformers/svelte.d.ts +3 -0
- package/dist/core/transformers/svelte.d.ts.map +1 -0
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.d.ts +18 -8
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +2 -2
- package/dist/farm.d.ts +19 -6
- package/dist/farm.d.ts.map +1 -0
- package/dist/farm.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +7 -11
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/rolldown.cjs +2 -2
- package/dist/rolldown.d.ts +20 -8
- package/dist/rolldown.d.ts.map +1 -0
- package/dist/rolldown.js +1 -1
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.d.ts +17 -8
- package/dist/rollup.d.ts.map +1 -0
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.d.ts +17 -8
- package/dist/rspack.d.ts.map +1 -0
- package/dist/rspack.js +1 -1
- package/dist/types.d.ts +16 -10
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/get-aliases.d.ts +4 -0
- package/dist/utils/get-aliases.d.ts.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/store.d.ts +4 -0
- package/dist/utils/store.d.ts.map +1 -0
- package/dist/utils/stylex-path.d.ts +4 -0
- package/dist/utils/stylex-path.d.ts.map +1 -0
- package/dist/vite.cjs +3 -3
- package/dist/vite.d.ts +18 -8
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +2 -2
- package/dist/webpack.d.ts +17 -8
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +1 -1
- package/jsr.json +1 -1
- package/package.json +9 -7
- package/tsconfig.json +2 -5
- package/dist/astro.d.cts +0 -39
- package/dist/esbuild.d.cts +0 -14
- package/dist/farm.d.cts +0 -11
- package/dist/index.d.cts +0 -20
- package/dist/rolldown.d.cts +0 -14
- package/dist/rollup.d.cts +0 -14
- package/dist/rspack.d.cts +0 -15
- package/dist/types.d.cts +0 -41
- package/dist/vite.d.cts +0 -14
- package/dist/webpack.d.cts +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# unplugin-stylex
|
|
2
2
|
|
|
3
|
+
## 0.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#321](https://github.com/eryue0220/unplugin-stylex/pull/321) [`cfd5f0b`](https://github.com/eryue0220/unplugin-stylex/commit/cfd5f0bbb9ca21026fd8f9094655e0b0bababcf3) Thanks [@eryue0220](https://github.com/eryue0220)! - update deps
|
|
8
|
+
|
|
3
9
|
## 0.6.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,29 +1,46 @@
|
|
|
1
1
|
# unplugin-stylex · [](https://github.com/eryue0220/unplugin-stylex/blob/main/LICENSE) [](https://www.npmjs.com/package/unplugin-stylex)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`unplugin-stylex` brings StyleX transform support to multiple bundlers via [unplugin](https://github.com/unjs/unplugin).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
npm
|
|
7
|
+
```bash
|
|
8
|
+
npm i -D unplugin-stylex @stylexjs/stylex
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
or
|
|
11
|
+
or
|
|
12
12
|
|
|
13
|
-
```
|
|
14
|
-
yarn add unplugin-stylex
|
|
13
|
+
```bash
|
|
14
|
+
yarn add -D unplugin-stylex @stylexjs/stylex
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
or
|
|
17
|
+
or
|
|
18
18
|
|
|
19
|
-
```
|
|
20
|
-
pnpm
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add -D unplugin-stylex @stylexjs/stylex
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Node.js: `^20.19.0 || >=22.12.0`
|
|
26
|
+
- Peer dependency: `@stylexjs/stylex@0.x`
|
|
27
|
+
|
|
28
|
+
## Supported Targets
|
|
29
|
+
|
|
30
|
+
- Vite (`unplugin-stylex/vite`)
|
|
31
|
+
- Astro integration (`unplugin-stylex/astro`)
|
|
32
|
+
- Esbuild (`unplugin-stylex/esbuild`)
|
|
33
|
+
- Farm (`unplugin-stylex/farm`)
|
|
34
|
+
- Rspack (`unplugin-stylex/rspack`)
|
|
35
|
+
- RSBuild (through Rspack plugin in `tools.rspack.plugins`)
|
|
36
|
+
- Rolldown (`unplugin-stylex/rolldown`)
|
|
37
|
+
- Rollup (`unplugin-stylex/rollup`)
|
|
38
|
+
- Webpack (`unplugin-stylex/webpack`)
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
24
41
|
|
|
25
42
|
<details>
|
|
26
|
-
<summary>
|
|
43
|
+
<summary>Vite</summary>
|
|
27
44
|
|
|
28
45
|
```js
|
|
29
46
|
// vite.config.js
|
|
@@ -32,32 +49,50 @@ import stylexPlugin from 'unplugin-stylex/vite'
|
|
|
32
49
|
|
|
33
50
|
export default defineConfig({
|
|
34
51
|
plugins: [
|
|
35
|
-
stylexPlugin(
|
|
52
|
+
stylexPlugin(),
|
|
53
|
+
],
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
</details>
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>Astro</summary>
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
// astro.config.mjs
|
|
64
|
+
import { defineConfig } from 'astro/config'
|
|
65
|
+
import stylexAstroPlugin from 'unplugin-stylex/astro'
|
|
66
|
+
|
|
67
|
+
export default defineConfig({
|
|
68
|
+
integrations: [
|
|
69
|
+
stylexAstroPlugin(),
|
|
36
70
|
],
|
|
37
71
|
})
|
|
38
72
|
```
|
|
39
73
|
|
|
40
|
-
</
|
|
74
|
+
</details>
|
|
41
75
|
|
|
42
76
|
<details>
|
|
43
|
-
<summary>
|
|
77
|
+
<summary>Esbuild</summary>
|
|
44
78
|
|
|
45
79
|
```js
|
|
46
80
|
// esbuild.config.js
|
|
47
81
|
import { build } from 'esbuild'
|
|
48
82
|
import stylexPlugin from 'unplugin-stylex/esbuild'
|
|
49
83
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
build({
|
|
85
|
+
entryPoints: ['src/index.tsx'],
|
|
86
|
+
bundle: true,
|
|
87
|
+
outfile: 'dist/out.js',
|
|
88
|
+
plugins: [stylexPlugin()],
|
|
89
|
+
})
|
|
55
90
|
```
|
|
56
91
|
|
|
57
|
-
</
|
|
92
|
+
</details>
|
|
58
93
|
|
|
59
94
|
<details>
|
|
60
|
-
<summary>
|
|
95
|
+
<summary>Farm</summary>
|
|
61
96
|
|
|
62
97
|
```js
|
|
63
98
|
// farm.config.js
|
|
@@ -65,117 +100,141 @@ import { defineConfig } from '@farmfe/core'
|
|
|
65
100
|
import stylexPlugin from 'unplugin-stylex/farm'
|
|
66
101
|
|
|
67
102
|
export default defineConfig({
|
|
68
|
-
|
|
69
|
-
plugins: [
|
|
70
|
-
stylexPlugin({ /* options */}),
|
|
71
|
-
],
|
|
103
|
+
plugins: [stylexPlugin()],
|
|
72
104
|
})
|
|
73
105
|
```
|
|
74
106
|
|
|
75
|
-
</
|
|
107
|
+
</details>
|
|
76
108
|
|
|
77
109
|
<details>
|
|
78
|
-
<summary>
|
|
110
|
+
<summary>Rspack</summary>
|
|
79
111
|
|
|
80
112
|
```js
|
|
81
113
|
// rspack.config.js
|
|
82
114
|
import stylexPlugin from 'unplugin-stylex/rspack'
|
|
83
115
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
plugins: [
|
|
87
|
-
stylexPlugin({ /* options */}),
|
|
88
|
-
],
|
|
116
|
+
export default {
|
|
117
|
+
plugins: [stylexPlugin()],
|
|
89
118
|
}
|
|
90
119
|
```
|
|
91
120
|
|
|
92
|
-
</
|
|
121
|
+
</details>
|
|
93
122
|
|
|
94
123
|
<details>
|
|
95
|
-
<summary>
|
|
124
|
+
<summary>RSBuild</summary>
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// rsbuild.config.ts
|
|
128
|
+
import { defineConfig } from '@rsbuild/core'
|
|
129
|
+
import stylexPlugin from 'unplugin-stylex/rspack'
|
|
130
|
+
|
|
131
|
+
export default defineConfig({
|
|
132
|
+
tools: {
|
|
133
|
+
rspack: {
|
|
134
|
+
plugins: [stylexPlugin()],
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
</details>
|
|
141
|
+
|
|
142
|
+
<details>
|
|
143
|
+
<summary>Rolldown</summary>
|
|
96
144
|
|
|
97
145
|
```js
|
|
98
|
-
// rolldown.config.
|
|
99
|
-
import
|
|
146
|
+
// rolldown.config.mjs
|
|
147
|
+
import { defineConfig } from 'rolldown'
|
|
148
|
+
import stylexPlugin from 'unplugin-stylex/rolldown'
|
|
100
149
|
|
|
101
|
-
export default {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
stylexRolldownPlugin({ /* options */}),
|
|
105
|
-
],
|
|
106
|
-
}
|
|
150
|
+
export default defineConfig({
|
|
151
|
+
plugins: [stylexPlugin()],
|
|
152
|
+
})
|
|
107
153
|
```
|
|
108
154
|
|
|
109
|
-
</
|
|
155
|
+
</details>
|
|
110
156
|
|
|
111
157
|
<details>
|
|
112
|
-
<summary>
|
|
158
|
+
<summary>Rollup</summary>
|
|
113
159
|
|
|
114
160
|
```js
|
|
115
161
|
// rollup.config.js
|
|
116
|
-
import
|
|
162
|
+
import stylexPlugin from 'unplugin-stylex/rollup'
|
|
117
163
|
|
|
118
164
|
export default {
|
|
119
|
-
|
|
120
|
-
plugins: [
|
|
121
|
-
stylexRollupPlugin({ /* options */}),
|
|
122
|
-
],
|
|
165
|
+
plugins: [stylexPlugin()],
|
|
123
166
|
}
|
|
124
167
|
```
|
|
125
168
|
|
|
126
|
-
</
|
|
169
|
+
</details>
|
|
127
170
|
|
|
128
171
|
<details>
|
|
129
|
-
<summary>
|
|
172
|
+
<summary>Webpack</summary>
|
|
130
173
|
|
|
131
174
|
```js
|
|
132
175
|
// webpack.config.js
|
|
133
|
-
|
|
176
|
+
const stylexPlugin = require('unplugin-stylex/webpack').default
|
|
134
177
|
|
|
135
178
|
module.exports = {
|
|
136
|
-
|
|
137
|
-
plugins: [
|
|
138
|
-
stylexWebpackPlugin({ /* options */}),
|
|
139
|
-
],
|
|
179
|
+
plugins: [stylexPlugin()],
|
|
140
180
|
}
|
|
141
181
|
```
|
|
142
182
|
|
|
143
|
-
</
|
|
144
|
-
|
|
145
|
-
## Usage
|
|
146
|
-
|
|
147
|
-
More detail usage can check [examples](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
|
|
183
|
+
</details>
|
|
148
184
|
|
|
149
185
|
## Options
|
|
150
186
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
187
|
+
```ts
|
|
188
|
+
type UnpluginStylexOptions = {
|
|
189
|
+
validExts?: RegExp | string[]
|
|
190
|
+
dev?: boolean
|
|
191
|
+
stylex?: {
|
|
192
|
+
filename?: string
|
|
193
|
+
aliases?: Record<string, string | string[]>
|
|
194
|
+
stylexImports?: string[]
|
|
195
|
+
classNamePrefix?: string
|
|
196
|
+
unstable_moduleResolution?: {
|
|
197
|
+
type: 'commonJS' | 'haste'
|
|
198
|
+
rootDir: string
|
|
199
|
+
}
|
|
200
|
+
babelConfig?: {
|
|
201
|
+
plugins: unknown[]
|
|
202
|
+
presets: unknown[]
|
|
203
|
+
babelrc: boolean
|
|
204
|
+
}
|
|
205
|
+
useCSSLayers?: boolean
|
|
206
|
+
genConditionalClasses?: boolean
|
|
207
|
+
treeshakeCompensation?: boolean
|
|
208
|
+
runtimeInjection?: boolean
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
162
212
|
|
|
163
|
-
|
|
213
|
+
### Defaults
|
|
164
214
|
|
|
165
|
-
|
|
215
|
+
- `validExts`: `/\.[mc]?[jt]sx?$|\.svelte$|\.vue$/`
|
|
216
|
+
- `dev`: inferred from environment (`NODE_ENV` / `BABEL_ENV`) unless explicitly set
|
|
217
|
+
- `stylex.filename`: `'stylex.css'`
|
|
218
|
+
- `stylex.stylexImports`: `['@stylexjs/stylex']`
|
|
219
|
+
- `stylex.runtimeInjection`: follows `dev` by default
|
|
220
|
+
- `stylex.aliases`: auto-reads from project config (TS paths + bundler aliases when available)
|
|
221
|
+
- `stylex.useCSSLayers`: `false`
|
|
222
|
+
- `stylex.unstable_moduleResolution`: `{ type: 'commonJS', rootDir: process.cwd() }`
|
|
223
|
+
- `stylex.babelConfig`: `{ babelrc: false, plugins: [], presets: [] }`
|
|
166
224
|
|
|
167
|
-
##
|
|
225
|
+
## Notes
|
|
168
226
|
|
|
169
|
-
|
|
227
|
+
- The plugin only transforms modules containing at least one `stylexImports` source.
|
|
228
|
+
- Output CSS is emitted as an asset file (`stylex.css` by default).
|
|
229
|
+
- Vite and Astro integrations also handle dev server CSS serving and HTML injection.
|
|
230
|
+
- Astro integration defaults `validExts` to include `.astro` and `.stylex`.
|
|
231
|
+
- For Farm projects, `treeshakeCompensation: true` is usually needed (see example config).
|
|
170
232
|
|
|
171
|
-
|
|
172
|
-
- `pnpm turbo:test` — 在所有包中运行测试
|
|
173
|
-
- `pnpm turbo:lint` / `pnpm turbo:check` — 在所有包中运行 lint / check
|
|
174
|
-
- `pnpm turbo:dev` — 并行启动所有包的 dev 脚本
|
|
233
|
+
## Examples
|
|
175
234
|
|
|
176
|
-
|
|
235
|
+
- See runnable examples in [`examples`](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
|
|
177
236
|
|
|
178
|
-
|
|
237
|
+
## Acknowledgments
|
|
179
238
|
|
|
180
239
|
- [@stylexjs/rollup-plugin](https://github.com/facebook/stylex/tree/main/packages/rollup-plugin)
|
|
181
|
-
- [vite-plugin-stylex](https://github.com/HorusGoul/vite-plugin-stylex)
|
|
240
|
+
- [vite-plugin-stylex](https://github.com/HorusGoul/vite-plugin-stylex)
|
package/dist/astro.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkWDYGV6FUcjs = require('./chunk-WDYGV6FU.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -9,15 +9,15 @@ var _chunkO4FQWPVVcjs = require('./chunk-O4FQWPVV.cjs');
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunk45JWH4GZcjs = require('./chunk-45JWH4GZ.cjs');
|
|
13
13
|
require('./chunk-ZBPRDZS4.cjs');
|
|
14
14
|
|
|
15
15
|
// src/astro.ts
|
|
16
16
|
function astro(options = {}) {
|
|
17
|
-
const configured =
|
|
18
|
-
const filename = configured.stylex.filename;
|
|
17
|
+
const configured = _chunk45JWH4GZcjs.getOptions.call(void 0, { ...options, framework: "vite" });
|
|
18
|
+
const filename = _nullishCoalesce(configured.stylex.filename, () => ( "stylex.css"));
|
|
19
19
|
return {
|
|
20
|
-
name:
|
|
20
|
+
name: _chunk45JWH4GZcjs.PLUGIN_NAME,
|
|
21
21
|
hooks: {
|
|
22
22
|
"astro:config:setup": async ({ config, updateConfig, injectScript }) => {
|
|
23
23
|
var _a, _b;
|
|
@@ -25,19 +25,19 @@ function astro(options = {}) {
|
|
|
25
25
|
...options,
|
|
26
26
|
validExts: _nullishCoalesce(options.validExts, () => ( /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/))
|
|
27
27
|
};
|
|
28
|
-
if (!
|
|
29
|
-
|
|
28
|
+
if (!_chunk45JWH4GZcjs.stylexRulesStore.has(_chunk45JWH4GZcjs.STORE_KEY)) {
|
|
29
|
+
_chunk45JWH4GZcjs.stylexRulesStore.set(_chunk45JWH4GZcjs.STORE_KEY, {});
|
|
30
30
|
}
|
|
31
31
|
config.vite.plugins ??= [];
|
|
32
|
-
const basePlugin =
|
|
32
|
+
const basePlugin = _chunkWDYGV6FUcjs.vite_default.call(void 0, astroOptions);
|
|
33
33
|
const wrappedPlugin = {
|
|
34
34
|
...basePlugin,
|
|
35
|
-
getStylexRules: () =>
|
|
35
|
+
getStylexRules: () => _chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY) || {}
|
|
36
36
|
};
|
|
37
37
|
const base = _nullishCoalesce(config.base, () => ( "/"));
|
|
38
38
|
const assetsDir = typeof ((_a = config.build) == null ? void 0 : _a.assets) === "string" ? config.build.assets : "_astro";
|
|
39
|
-
const fileName =
|
|
40
|
-
const cssPath =
|
|
39
|
+
const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
|
|
40
|
+
const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, base, fileName);
|
|
41
41
|
injectScript(
|
|
42
42
|
"head-inline",
|
|
43
43
|
`
|
|
@@ -67,12 +67,12 @@ function astro(options = {}) {
|
|
|
67
67
|
server.middlewares.use((req, res, next) => {
|
|
68
68
|
var _a, _b;
|
|
69
69
|
const assetsDir = "_astro";
|
|
70
|
-
const fileName =
|
|
71
|
-
const cssPath =
|
|
70
|
+
const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
|
|
71
|
+
const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, "/", fileName);
|
|
72
72
|
const normalizedUrl = (_a = req.url) == null ? void 0 : _a.split("?")[0];
|
|
73
73
|
if (normalizedUrl === cssPath || normalizedUrl === `/${filename}` || (normalizedUrl == null ? void 0 : normalizedUrl.endsWith(`/${filename}`)) || normalizedUrl === filename) {
|
|
74
|
-
const stylexRules = _nullishCoalesce(
|
|
75
|
-
const collectedCSS =
|
|
74
|
+
const stylexRules = _nullishCoalesce(_chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY), () => ( {}));
|
|
75
|
+
const collectedCSS = _chunk45JWH4GZcjs.buildStylexRules.call(void 0, stylexRules, _nullishCoalesce(((_b = options.stylex) == null ? void 0 : _b.useCSSLayers), () => ( false)));
|
|
76
76
|
res.setHeader("Content-Type", "text/css");
|
|
77
77
|
res.setHeader("Cache-Control", "no-cache");
|
|
78
78
|
res.end(_nullishCoalesce(collectedCSS, () => ( "")));
|
package/dist/astro.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
import { UnpluginStylexOptions } from './types.js';
|
|
2
|
-
import '@babel/core';
|
|
3
|
-
import '@stylexjs/babel-plugin';
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* This entry file is for astro plugin.
|
|
7
3
|
*
|
|
8
4
|
* @module
|
|
9
5
|
*/
|
|
10
|
-
|
|
6
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
7
|
+
import type { UnpluginStylexOptions } from './types';
|
|
8
|
+
type AstroConfigSetupContext = {
|
|
9
|
+
config: {
|
|
10
|
+
base?: string;
|
|
11
|
+
build?: {
|
|
12
|
+
assets?: string;
|
|
13
|
+
};
|
|
14
|
+
vite: {
|
|
15
|
+
plugins?: unknown[];
|
|
16
|
+
ssr?: {
|
|
17
|
+
noExternal?: unknown;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
updateConfig: (config: {
|
|
22
|
+
vite: {
|
|
23
|
+
ssr: {
|
|
24
|
+
noExternal: string[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}) => void;
|
|
28
|
+
injectScript: (stage: string, content: string) => void;
|
|
29
|
+
};
|
|
30
|
+
type AstroServerSetupContext = {
|
|
31
|
+
server: {
|
|
32
|
+
middlewares: {
|
|
33
|
+
use: (handler: (req: IncomingMessage & {
|
|
34
|
+
url?: string;
|
|
35
|
+
}, res: ServerResponse, next: () => void) => void) => void;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
11
39
|
/**
|
|
12
40
|
* Astro plugin
|
|
13
41
|
*
|
|
@@ -22,18 +50,12 @@ import '@stylexjs/babel-plugin';
|
|
|
22
50
|
* ],
|
|
23
51
|
* })
|
|
24
52
|
*/
|
|
25
|
-
|
|
53
|
+
export default function astro(options?: UnpluginStylexOptions): {
|
|
26
54
|
name: string;
|
|
27
55
|
hooks: {
|
|
28
|
-
'astro:config:setup': ({ config, updateConfig, injectScript }:
|
|
29
|
-
|
|
30
|
-
updateConfig: any;
|
|
31
|
-
injectScript: any;
|
|
32
|
-
}) => Promise<void>;
|
|
33
|
-
'astro:server:setup': ({ server }: {
|
|
34
|
-
server: any;
|
|
35
|
-
}) => void;
|
|
56
|
+
'astro:config:setup': ({ config, updateConfig, injectScript }: AstroConfigSetupContext) => Promise<void>;
|
|
57
|
+
'astro:server:setup': ({ server }: AstroServerSetupContext) => void;
|
|
36
58
|
};
|
|
37
59
|
};
|
|
38
|
-
|
|
39
|
-
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=astro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../src/astro.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAGhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIpD,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,EAAE,MAAM,CAAA;SAChB,CAAA;QACD,IAAI,EAAE;YACJ,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;YACnB,GAAG,CAAC,EAAE;gBACJ,UAAU,CAAC,EAAE,OAAO,CAAA;aACrB,CAAA;SACF,CAAA;KACF,CAAA;IACD,YAAY,EAAE,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,UAAU,EAAE,MAAM,EAAE,CAAA;aACrB,CAAA;SACF,CAAA;KACF,KAAK,IAAI,CAAA;IACV,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACvD,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE;QACN,WAAW,EAAE;YACX,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,GAAG;gBAAE,GAAG,CAAC,EAAE,MAAM,CAAA;aAAE,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,KAAK,IAAI,CAAA;SACjH,CAAA;KACF,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,qBAA0B;;;uEAQU,uBAAuB;2CAyDzD,uBAAuB;;EA2B/D"}
|
package/dist/astro.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5RGNKABP.js";
|
|
4
4
|
import {
|
|
5
5
|
PLUGIN_NAME,
|
|
6
6
|
STORE_KEY,
|
|
@@ -9,13 +9,13 @@ import {
|
|
|
9
9
|
getStylexAssetFileName,
|
|
10
10
|
getStylexPublicPath,
|
|
11
11
|
stylexRulesStore
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-SSMUIUHR.js";
|
|
13
13
|
import "./chunk-6F4PWJZI.js";
|
|
14
14
|
|
|
15
15
|
// src/astro.ts
|
|
16
16
|
function astro(options = {}) {
|
|
17
17
|
const configured = getOptions({ ...options, framework: "vite" });
|
|
18
|
-
const filename = configured.stylex.filename;
|
|
18
|
+
const filename = configured.stylex.filename ?? "stylex.css";
|
|
19
19
|
return {
|
|
20
20
|
name: PLUGIN_NAME,
|
|
21
21
|
hooks: {
|
|
@@ -429,10 +429,13 @@ var transformers = {
|
|
|
429
429
|
// src/index.ts
|
|
430
430
|
var unpluginFactory = (rawOptions, meta) => {
|
|
431
431
|
const options = getOptions({ ...rawOptions || {}, framework: meta.framework });
|
|
432
|
+
const stylexFilename = _nullishCoalesce(options.stylex.filename, () => ( "stylex.css"));
|
|
433
|
+
const stylexImports = _nullishCoalesce(options.stylex.stylexImports, () => ( ["@stylexjs/stylex"]));
|
|
434
|
+
const useCSSLayers = _nullishCoalesce(options.stylex.useCSSLayers, () => ( false));
|
|
432
435
|
if (!stylexRulesStore.has(STORE_KEY)) {
|
|
433
436
|
stylexRulesStore.set(STORE_KEY, {});
|
|
434
437
|
}
|
|
435
|
-
const stylexRules = stylexRulesStore.get(STORE_KEY);
|
|
438
|
+
const stylexRules = _nullishCoalesce(stylexRulesStore.get(STORE_KEY), () => ( {}));
|
|
436
439
|
let viteConfig = null;
|
|
437
440
|
return {
|
|
438
441
|
name: PLUGIN_NAME,
|
|
@@ -449,7 +452,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
449
452
|
const normalizedFile = normalizePath(file);
|
|
450
453
|
const normalizedId = normalizePath(id);
|
|
451
454
|
const extname2 = path3.extname(file).slice(1);
|
|
452
|
-
if (!
|
|
455
|
+
if (!stylexImports.some((importName) => code.includes(importName))) {
|
|
453
456
|
return;
|
|
454
457
|
}
|
|
455
458
|
const context = {
|
|
@@ -468,12 +471,12 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
468
471
|
return result;
|
|
469
472
|
} catch (error) {
|
|
470
473
|
console.error("transform::error::", error);
|
|
471
|
-
this.error(error);
|
|
474
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
472
475
|
}
|
|
473
476
|
},
|
|
474
477
|
buildEnd() {
|
|
475
|
-
const fileName =
|
|
476
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
478
|
+
const fileName = stylexFilename;
|
|
479
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
477
480
|
if (!collectedCSS) return;
|
|
478
481
|
this.emitFile({
|
|
479
482
|
fileName,
|
|
@@ -495,14 +498,14 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
495
498
|
next();
|
|
496
499
|
return;
|
|
497
500
|
}
|
|
498
|
-
const fileName = getStylexAssetFileName(
|
|
501
|
+
const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
|
|
499
502
|
const cssPath = getStylexPublicPath(viteConfig == null ? void 0 : viteConfig.base, fileName);
|
|
500
503
|
const basePath = (_nullishCoalesce((viteConfig == null ? void 0 : viteConfig.base), () => ( "/"))).replace(/\/+$/, "") || "/";
|
|
501
|
-
const filename =
|
|
504
|
+
const filename = stylexFilename;
|
|
502
505
|
const normalizedUrl = req.url.split("?")[0];
|
|
503
506
|
const isCSSRequest = normalizedUrl === cssPath || normalizedUrl === `${basePath}/${filename}` || normalizedUrl === `/${filename}` || normalizedUrl.endsWith(`/${filename}`) || normalizedUrl === filename;
|
|
504
507
|
if (isCSSRequest) {
|
|
505
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
508
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
506
509
|
res.setHeader("Content-Type", "text/css");
|
|
507
510
|
res.setHeader("Cache-Control", "no-cache");
|
|
508
511
|
res.end(collectedCSS || "");
|
|
@@ -513,8 +516,8 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
513
516
|
},
|
|
514
517
|
buildEnd() {
|
|
515
518
|
var _a;
|
|
516
|
-
const fileName = getStylexAssetFileName(
|
|
517
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
519
|
+
const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
|
|
520
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
518
521
|
if (!collectedCSS) return;
|
|
519
522
|
this.emitFile({
|
|
520
523
|
fileName,
|
|
@@ -524,7 +527,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
524
527
|
},
|
|
525
528
|
transformIndexHtml(html, ctx) {
|
|
526
529
|
var _a, _b;
|
|
527
|
-
const fileName = getStylexAssetFileName(
|
|
530
|
+
const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
|
|
528
531
|
const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
|
|
529
532
|
if (!css) {
|
|
530
533
|
return html;
|
|
@@ -429,10 +429,13 @@ var transformers = {
|
|
|
429
429
|
// src/index.ts
|
|
430
430
|
var unpluginFactory = (rawOptions, meta) => {
|
|
431
431
|
const options = getOptions({ ...rawOptions || {}, framework: meta.framework });
|
|
432
|
+
const stylexFilename = options.stylex.filename ?? "stylex.css";
|
|
433
|
+
const stylexImports = options.stylex.stylexImports ?? ["@stylexjs/stylex"];
|
|
434
|
+
const useCSSLayers = options.stylex.useCSSLayers ?? false;
|
|
432
435
|
if (!stylexRulesStore.has(STORE_KEY)) {
|
|
433
436
|
stylexRulesStore.set(STORE_KEY, {});
|
|
434
437
|
}
|
|
435
|
-
const stylexRules = stylexRulesStore.get(STORE_KEY);
|
|
438
|
+
const stylexRules = stylexRulesStore.get(STORE_KEY) ?? {};
|
|
436
439
|
let viteConfig = null;
|
|
437
440
|
return {
|
|
438
441
|
name: PLUGIN_NAME,
|
|
@@ -449,7 +452,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
449
452
|
const normalizedFile = normalizePath(file);
|
|
450
453
|
const normalizedId = normalizePath(id);
|
|
451
454
|
const extname2 = path3.extname(file).slice(1);
|
|
452
|
-
if (!
|
|
455
|
+
if (!stylexImports.some((importName) => code.includes(importName))) {
|
|
453
456
|
return;
|
|
454
457
|
}
|
|
455
458
|
const context = {
|
|
@@ -468,12 +471,12 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
468
471
|
return result;
|
|
469
472
|
} catch (error) {
|
|
470
473
|
console.error("transform::error::", error);
|
|
471
|
-
this.error(error);
|
|
474
|
+
this.error(error instanceof Error ? error.message : String(error));
|
|
472
475
|
}
|
|
473
476
|
},
|
|
474
477
|
buildEnd() {
|
|
475
|
-
const fileName =
|
|
476
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
478
|
+
const fileName = stylexFilename;
|
|
479
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
477
480
|
if (!collectedCSS) return;
|
|
478
481
|
this.emitFile({
|
|
479
482
|
fileName,
|
|
@@ -495,14 +498,14 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
495
498
|
next();
|
|
496
499
|
return;
|
|
497
500
|
}
|
|
498
|
-
const fileName = getStylexAssetFileName(
|
|
501
|
+
const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
|
|
499
502
|
const cssPath = getStylexPublicPath(viteConfig == null ? void 0 : viteConfig.base, fileName);
|
|
500
503
|
const basePath = ((viteConfig == null ? void 0 : viteConfig.base) ?? "/").replace(/\/+$/, "") || "/";
|
|
501
|
-
const filename =
|
|
504
|
+
const filename = stylexFilename;
|
|
502
505
|
const normalizedUrl = req.url.split("?")[0];
|
|
503
506
|
const isCSSRequest = normalizedUrl === cssPath || normalizedUrl === `${basePath}/${filename}` || normalizedUrl === `/${filename}` || normalizedUrl.endsWith(`/${filename}`) || normalizedUrl === filename;
|
|
504
507
|
if (isCSSRequest) {
|
|
505
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
508
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
506
509
|
res.setHeader("Content-Type", "text/css");
|
|
507
510
|
res.setHeader("Cache-Control", "no-cache");
|
|
508
511
|
res.end(collectedCSS || "");
|
|
@@ -513,8 +516,8 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
513
516
|
},
|
|
514
517
|
buildEnd() {
|
|
515
518
|
var _a;
|
|
516
|
-
const fileName = getStylexAssetFileName(
|
|
517
|
-
const collectedCSS = buildStylexRules(stylexRules,
|
|
519
|
+
const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
|
|
520
|
+
const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
|
|
518
521
|
if (!collectedCSS) return;
|
|
519
522
|
this.emitFile({
|
|
520
523
|
fileName,
|
|
@@ -524,7 +527,7 @@ var unpluginFactory = (rawOptions, meta) => {
|
|
|
524
527
|
},
|
|
525
528
|
transformIndexHtml(html, ctx) {
|
|
526
529
|
var _a, _b;
|
|
527
|
-
const fileName = getStylexAssetFileName(
|
|
530
|
+
const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
|
|
528
531
|
const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
|
|
529
532
|
if (!css) {
|
|
530
533
|
return html;
|