unplugin-stylex 0.6.1 → 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 +12 -0
- package/README.md +143 -73
- package/dist/astro.cjs +24 -19
- package/dist/astro.d.ts +38 -16
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +15 -10
- package/dist/{chunk-IU3ZVEOU.cjs → chunk-45JWH4GZ.cjs} +57 -38
- package/dist/{chunk-F2LYIKCV.js → chunk-5RGNKABP.js} +1 -1
- package/dist/{chunk-B3OIQQRZ.js → chunk-SSMUIUHR.js} +41 -22
- package/dist/{chunk-7LU6DGX6.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 +19 -12
- package/tsconfig.json +3 -6
- package/turbo.json +23 -0
- 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,17 @@
|
|
|
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
|
+
|
|
9
|
+
## 0.6.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#281](https://github.com/eryue0220/unplugin-stylex/pull/281) [`e3eb53d`](https://github.com/eryue0220/unplugin-stylex/commit/e3eb53d5f30142cffa5578ec872df7244351bc4f) Thanks [@eryue0220](https://github.com/eryue0220)! - fix windows path error
|
|
14
|
+
|
|
3
15
|
## 0.6.1
|
|
4
16
|
|
|
5
17
|
### 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,106 +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
|
-
|
|
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
|
+
```
|
|
154
212
|
|
|
155
|
-
|
|
213
|
+
### Defaults
|
|
156
214
|
|
|
157
|
-
|
|
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: [] }`
|
|
158
224
|
|
|
159
|
-
|
|
225
|
+
## Notes
|
|
160
226
|
|
|
161
|
-
|
|
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).
|
|
162
232
|
|
|
163
|
-
|
|
233
|
+
## Examples
|
|
164
234
|
|
|
165
|
-
|
|
235
|
+
- See runnable examples in [`examples`](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
|
|
166
236
|
|
|
167
|
-
|
|
237
|
+
## Acknowledgments
|
|
168
238
|
|
|
169
239
|
- [@stylexjs/rollup-plugin](https://github.com/facebook/stylex/tree/main/packages/rollup-plugin)
|
|
170
|
-
- [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,40 +1,43 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
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
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunk45JWH4GZcjs = require('./chunk-45JWH4GZ.cjs');
|
|
11
13
|
require('./chunk-ZBPRDZS4.cjs');
|
|
12
14
|
|
|
13
15
|
// src/astro.ts
|
|
14
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
15
16
|
function astro(options = {}) {
|
|
16
|
-
const configured =
|
|
17
|
-
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"));
|
|
18
19
|
return {
|
|
19
|
-
name:
|
|
20
|
+
name: _chunk45JWH4GZcjs.PLUGIN_NAME,
|
|
20
21
|
hooks: {
|
|
21
22
|
"astro:config:setup": async ({ config, updateConfig, injectScript }) => {
|
|
22
|
-
var _a;
|
|
23
|
+
var _a, _b;
|
|
23
24
|
const astroOptions = {
|
|
24
25
|
...options,
|
|
25
26
|
validExts: _nullishCoalesce(options.validExts, () => ( /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/))
|
|
26
27
|
};
|
|
27
|
-
if (!
|
|
28
|
-
|
|
28
|
+
if (!_chunk45JWH4GZcjs.stylexRulesStore.has(_chunk45JWH4GZcjs.STORE_KEY)) {
|
|
29
|
+
_chunk45JWH4GZcjs.stylexRulesStore.set(_chunk45JWH4GZcjs.STORE_KEY, {});
|
|
29
30
|
}
|
|
30
31
|
config.vite.plugins ??= [];
|
|
31
|
-
const basePlugin =
|
|
32
|
+
const basePlugin = _chunkWDYGV6FUcjs.vite_default.call(void 0, astroOptions);
|
|
32
33
|
const wrappedPlugin = {
|
|
33
34
|
...basePlugin,
|
|
34
|
-
getStylexRules: () =>
|
|
35
|
+
getStylexRules: () => _chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY) || {}
|
|
35
36
|
};
|
|
36
37
|
const base = _nullishCoalesce(config.base, () => ( "/"));
|
|
37
|
-
const
|
|
38
|
+
const assetsDir = typeof ((_a = config.build) == null ? void 0 : _a.assets) === "string" ? config.build.assets : "_astro";
|
|
39
|
+
const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
|
|
40
|
+
const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, base, fileName);
|
|
38
41
|
injectScript(
|
|
39
42
|
"head-inline",
|
|
40
43
|
`
|
|
@@ -47,7 +50,7 @@ function astro(options = {}) {
|
|
|
47
50
|
`
|
|
48
51
|
);
|
|
49
52
|
config.vite.plugins.push(wrappedPlugin);
|
|
50
|
-
const currentNoExternal = _nullishCoalesce(((
|
|
53
|
+
const currentNoExternal = _nullishCoalesce(((_b = config.vite.ssr) == null ? void 0 : _b.noExternal), () => ( []));
|
|
51
54
|
const noExternal = Array.isArray(currentNoExternal) ? [...currentNoExternal] : [];
|
|
52
55
|
if (!noExternal.includes("@stylexjs/stylex")) {
|
|
53
56
|
noExternal.push("@stylexjs/stylex");
|
|
@@ -63,11 +66,13 @@ function astro(options = {}) {
|
|
|
63
66
|
"astro:server:setup": ({ server }) => {
|
|
64
67
|
server.middlewares.use((req, res, next) => {
|
|
65
68
|
var _a, _b;
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const assetsDir = "_astro";
|
|
70
|
+
const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
|
|
71
|
+
const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, "/", fileName);
|
|
72
|
+
const normalizedUrl = (_a = req.url) == null ? void 0 : _a.split("?")[0];
|
|
73
|
+
if (normalizedUrl === cssPath || normalizedUrl === `/${filename}` || (normalizedUrl == null ? void 0 : normalizedUrl.endsWith(`/${filename}`)) || normalizedUrl === filename) {
|
|
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)));
|
|
71
76
|
res.setHeader("Content-Type", "text/css");
|
|
72
77
|
res.setHeader("Cache-Control", "no-cache");
|
|
73
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,25 +1,26 @@
|
|
|
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,
|
|
7
7
|
buildStylexRules,
|
|
8
8
|
getOptions,
|
|
9
|
+
getStylexAssetFileName,
|
|
10
|
+
getStylexPublicPath,
|
|
9
11
|
stylexRulesStore
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-SSMUIUHR.js";
|
|
11
13
|
import "./chunk-6F4PWJZI.js";
|
|
12
14
|
|
|
13
15
|
// src/astro.ts
|
|
14
|
-
import * as path from "path";
|
|
15
16
|
function astro(options = {}) {
|
|
16
17
|
const configured = getOptions({ ...options, framework: "vite" });
|
|
17
|
-
const filename = configured.stylex.filename;
|
|
18
|
+
const filename = configured.stylex.filename ?? "stylex.css";
|
|
18
19
|
return {
|
|
19
20
|
name: PLUGIN_NAME,
|
|
20
21
|
hooks: {
|
|
21
22
|
"astro:config:setup": async ({ config, updateConfig, injectScript }) => {
|
|
22
|
-
var _a;
|
|
23
|
+
var _a, _b;
|
|
23
24
|
const astroOptions = {
|
|
24
25
|
...options,
|
|
25
26
|
validExts: options.validExts ?? /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/
|
|
@@ -34,7 +35,9 @@ function astro(options = {}) {
|
|
|
34
35
|
getStylexRules: () => stylexRulesStore.get(STORE_KEY) || {}
|
|
35
36
|
};
|
|
36
37
|
const base = config.base ?? "/";
|
|
37
|
-
const
|
|
38
|
+
const assetsDir = typeof ((_a = config.build) == null ? void 0 : _a.assets) === "string" ? config.build.assets : "_astro";
|
|
39
|
+
const fileName = getStylexAssetFileName(filename, assetsDir);
|
|
40
|
+
const cssPath = getStylexPublicPath(base, fileName);
|
|
38
41
|
injectScript(
|
|
39
42
|
"head-inline",
|
|
40
43
|
`
|
|
@@ -47,7 +50,7 @@ function astro(options = {}) {
|
|
|
47
50
|
`
|
|
48
51
|
);
|
|
49
52
|
config.vite.plugins.push(wrappedPlugin);
|
|
50
|
-
const currentNoExternal = ((
|
|
53
|
+
const currentNoExternal = ((_b = config.vite.ssr) == null ? void 0 : _b.noExternal) ?? [];
|
|
51
54
|
const noExternal = Array.isArray(currentNoExternal) ? [...currentNoExternal] : [];
|
|
52
55
|
if (!noExternal.includes("@stylexjs/stylex")) {
|
|
53
56
|
noExternal.push("@stylexjs/stylex");
|
|
@@ -63,9 +66,11 @@ function astro(options = {}) {
|
|
|
63
66
|
"astro:server:setup": ({ server }) => {
|
|
64
67
|
server.middlewares.use((req, res, next) => {
|
|
65
68
|
var _a, _b;
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
+
const assetsDir = "_astro";
|
|
70
|
+
const fileName = getStylexAssetFileName(filename, assetsDir);
|
|
71
|
+
const cssPath = getStylexPublicPath("/", fileName);
|
|
72
|
+
const normalizedUrl = (_a = req.url) == null ? void 0 : _a.split("?")[0];
|
|
73
|
+
if (normalizedUrl === cssPath || normalizedUrl === `/${filename}` || (normalizedUrl == null ? void 0 : normalizedUrl.endsWith(`/${filename}`)) || normalizedUrl === filename) {
|
|
69
74
|
const stylexRules = stylexRulesStore.get(STORE_KEY) ?? {};
|
|
70
75
|
const collectedCSS = buildStylexRules(stylexRules, ((_b = options.stylex) == null ? void 0 : _b.useCSSLayers) ?? false);
|
|
71
76
|
res.setHeader("Content-Type", "text/css");
|