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.
Files changed (82) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +143 -73
  3. package/dist/astro.cjs +24 -19
  4. package/dist/astro.d.ts +38 -16
  5. package/dist/astro.d.ts.map +1 -0
  6. package/dist/astro.js +15 -10
  7. package/dist/{chunk-IU3ZVEOU.cjs → chunk-45JWH4GZ.cjs} +57 -38
  8. package/dist/{chunk-F2LYIKCV.js → chunk-5RGNKABP.js} +1 -1
  9. package/dist/{chunk-B3OIQQRZ.js → chunk-SSMUIUHR.js} +41 -22
  10. package/dist/{chunk-7LU6DGX6.cjs → chunk-WDYGV6FU.cjs} +2 -2
  11. package/dist/core/build.d.ts +5 -0
  12. package/dist/core/build.d.ts.map +1 -0
  13. package/dist/core/options.d.ts +5 -0
  14. package/dist/core/options.d.ts.map +1 -0
  15. package/dist/core/plugins.d.ts +2 -0
  16. package/dist/core/plugins.d.ts.map +1 -0
  17. package/dist/core/transformers/astro.d.ts +3 -0
  18. package/dist/core/transformers/astro.d.ts.map +1 -0
  19. package/dist/core/transformers/default.d.ts +3 -0
  20. package/dist/core/transformers/default.d.ts.map +1 -0
  21. package/dist/core/transformers/index.d.ts +3 -0
  22. package/dist/core/transformers/index.d.ts.map +1 -0
  23. package/dist/core/transformers/svelte.d.ts +3 -0
  24. package/dist/core/transformers/svelte.d.ts.map +1 -0
  25. package/dist/esbuild.cjs +2 -2
  26. package/dist/esbuild.d.ts +18 -8
  27. package/dist/esbuild.d.ts.map +1 -0
  28. package/dist/esbuild.js +1 -1
  29. package/dist/farm.cjs +2 -2
  30. package/dist/farm.d.ts +19 -6
  31. package/dist/farm.d.ts.map +1 -0
  32. package/dist/farm.js +1 -1
  33. package/dist/index.cjs +2 -2
  34. package/dist/index.d.ts +7 -11
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +1 -1
  37. package/dist/rolldown.cjs +2 -2
  38. package/dist/rolldown.d.ts +20 -8
  39. package/dist/rolldown.d.ts.map +1 -0
  40. package/dist/rolldown.js +1 -1
  41. package/dist/rollup.cjs +2 -2
  42. package/dist/rollup.d.ts +17 -8
  43. package/dist/rollup.d.ts.map +1 -0
  44. package/dist/rollup.js +1 -1
  45. package/dist/rspack.cjs +2 -2
  46. package/dist/rspack.d.ts +17 -8
  47. package/dist/rspack.d.ts.map +1 -0
  48. package/dist/rspack.js +1 -1
  49. package/dist/types.d.ts +16 -10
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/utils/constants.d.ts +4 -0
  52. package/dist/utils/constants.d.ts.map +1 -0
  53. package/dist/utils/get-aliases.d.ts +4 -0
  54. package/dist/utils/get-aliases.d.ts.map +1 -0
  55. package/dist/utils/index.d.ts +5 -0
  56. package/dist/utils/index.d.ts.map +1 -0
  57. package/dist/utils/store.d.ts +4 -0
  58. package/dist/utils/store.d.ts.map +1 -0
  59. package/dist/utils/stylex-path.d.ts +4 -0
  60. package/dist/utils/stylex-path.d.ts.map +1 -0
  61. package/dist/vite.cjs +3 -3
  62. package/dist/vite.d.ts +18 -8
  63. package/dist/vite.d.ts.map +1 -0
  64. package/dist/vite.js +2 -2
  65. package/dist/webpack.cjs +2 -2
  66. package/dist/webpack.d.ts +17 -8
  67. package/dist/webpack.d.ts.map +1 -0
  68. package/dist/webpack.js +1 -1
  69. package/jsr.json +1 -1
  70. package/package.json +19 -12
  71. package/tsconfig.json +3 -6
  72. package/turbo.json +23 -0
  73. package/dist/astro.d.cts +0 -39
  74. package/dist/esbuild.d.cts +0 -14
  75. package/dist/farm.d.cts +0 -11
  76. package/dist/index.d.cts +0 -20
  77. package/dist/rolldown.d.cts +0 -14
  78. package/dist/rollup.d.cts +0 -14
  79. package/dist/rspack.d.cts +0 -15
  80. package/dist/types.d.cts +0 -41
  81. package/dist/vite.d.cts +0 -14
  82. 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 · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/eryue0220/unplugin-stylex/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/unplugin-stylex.svg?style=flat)](https://www.npmjs.com/package/unplugin-stylex)
2
2
 
3
- ## Installation
3
+ `unplugin-stylex` brings StyleX transform support to multiple bundlers via [unplugin](https://github.com/unjs/unplugin).
4
4
 
5
- Install the package from the following command
5
+ ## Installation
6
6
 
7
- ```shell
8
- npm install unplugin-stylex --save-dev
7
+ ```bash
8
+ npm i -D unplugin-stylex @stylexjs/stylex
9
9
  ```
10
10
 
11
- or with yarn:
11
+ or
12
12
 
13
- ```shell
14
- yarn add unplugin-stylex --save-dev
13
+ ```bash
14
+ yarn add -D unplugin-stylex @stylexjs/stylex
15
15
  ```
16
16
 
17
- or with pnpm:
17
+ or
18
18
 
19
- ```shell
20
- pnpm i unplugin-stylex --save-dev
19
+ ```bash
20
+ pnpm add -D unplugin-stylex @stylexjs/stylex
21
21
  ```
22
22
 
23
- ## Configuration
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>vite</summary><br>
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({ /* options */}),
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
- </br></details>
74
+ </details>
41
75
 
42
76
  <details>
43
- <summary>esbuild</summary><br>
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
- export default {
51
- plugins: [
52
- stylexPlugin({ /* options */ }),
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
- </br></details>
92
+ </details>
58
93
 
59
94
  <details>
60
- <summary>farm</summary><br>
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
- // other rollup config
69
- plugins: [
70
- stylexPlugin({ /* options */}),
71
- ],
103
+ plugins: [stylexPlugin()],
72
104
  })
73
105
  ```
74
106
 
75
- </br></details>
107
+ </details>
76
108
 
77
109
  <details>
78
- <summary>rspack</summary><br>
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
- module.exports = {
85
- // other rspack config
86
- plugins: [
87
- stylexPlugin({ /* options */}),
88
- ],
116
+ export default {
117
+ plugins: [stylexPlugin()],
89
118
  }
90
119
  ```
91
120
 
92
- </br></details>
121
+ </details>
93
122
 
94
123
  <details>
95
- <summary>rolldown</summary><br>
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.js
99
- import stylexRolldownPlugin from 'unplugin-stylex/rolldown'
146
+ // rolldown.config.mjs
147
+ import { defineConfig } from 'rolldown'
148
+ import stylexPlugin from 'unplugin-stylex/rolldown'
100
149
 
101
- export default {
102
- // other rolldown config
103
- plugins: [
104
- stylexRolldownPlugin({ /* options */}),
105
- ],
106
- }
150
+ export default defineConfig({
151
+ plugins: [stylexPlugin()],
152
+ })
107
153
  ```
108
154
 
109
- </br></details>
155
+ </details>
110
156
 
111
157
  <details>
112
- <summary>rollup</summary><br>
158
+ <summary>Rollup</summary>
113
159
 
114
160
  ```js
115
161
  // rollup.config.js
116
- import stylexRollupPlugin from 'unplugin-stylex/rollup'
162
+ import stylexPlugin from 'unplugin-stylex/rollup'
117
163
 
118
164
  export default {
119
- // other rollup config
120
- plugins: [
121
- stylexRollupPlugin({ /* options */}),
122
- ],
165
+ plugins: [stylexPlugin()],
123
166
  }
124
167
  ```
125
168
 
126
- </br></details>
169
+ </details>
127
170
 
128
171
  <details>
129
- <summary>webpack</summary><br>
172
+ <summary>Webpack</summary>
130
173
 
131
174
  ```js
132
175
  // webpack.config.js
133
- import stylexWebpackPlugin from 'unplugin-stylex/webpack'
176
+ const stylexPlugin = require('unplugin-stylex/webpack').default
134
177
 
135
178
  module.exports = {
136
- // other webpack config
137
- plugins: [
138
- stylexWebpackPlugin({ /* options */}),
139
- ],
179
+ plugins: [stylexPlugin()],
140
180
  }
141
181
  ```
142
182
 
143
- </br></details>
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
- Current support argument, which may have change in the future
152
-
153
- ### options.dev
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
- #### options.stylex.runtimeInjection
213
+ ### Defaults
156
214
 
157
- #### options.stylex.classNamePrefix
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
- #### options.stylex.useCSSLayers
225
+ ## Notes
160
226
 
161
- #### options.stylex.babelConfig
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
- #### options.stylex.stylexImports
233
+ ## Examples
164
234
 
165
- #### options.stylex.unstable_moduleResolution
235
+ - See runnable examples in [`examples`](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
166
236
 
167
- # Acknowledgments
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 _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
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 _chunk7LU6DGX6cjs = require('./chunk-7LU6DGX6.cjs');
3
+ var _chunkWDYGV6FUcjs = require('./chunk-WDYGV6FU.cjs');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunkIU3ZVEOUcjs = require('./chunk-IU3ZVEOU.cjs');
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 = _chunkIU3ZVEOUcjs.getOptions.call(void 0, { ...options, framework: "vite" });
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: _chunkIU3ZVEOUcjs.PLUGIN_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 (!_chunkIU3ZVEOUcjs.stylexRulesStore.has(_chunkIU3ZVEOUcjs.STORE_KEY)) {
28
- _chunkIU3ZVEOUcjs.stylexRulesStore.set(_chunkIU3ZVEOUcjs.STORE_KEY, {});
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 = _chunk7LU6DGX6cjs.vite_default.call(void 0, astroOptions);
32
+ const basePlugin = _chunkWDYGV6FUcjs.vite_default.call(void 0, astroOptions);
32
33
  const wrappedPlugin = {
33
34
  ...basePlugin,
34
- getStylexRules: () => _chunkIU3ZVEOUcjs.stylexRulesStore.get(_chunkIU3ZVEOUcjs.STORE_KEY) || {}
35
+ getStylexRules: () => _chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY) || {}
35
36
  };
36
37
  const base = _nullishCoalesce(config.base, () => ( "/"));
37
- const cssPath = path.posix.join(base, filename).replace(/\/+/g, "/");
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(((_a = config.vite.ssr) == null ? void 0 : _a.noExternal), () => ( []));
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 base = "/";
67
- const cssPath = path.posix.join(base, filename).replace(/\/+/g, base);
68
- if (req.url === cssPath || req.url === `/${filename}` || ((_a = req.url) == null ? void 0 : _a.endsWith(`/${filename}`))) {
69
- const stylexRules = _nullishCoalesce(_chunkIU3ZVEOUcjs.stylexRulesStore.get(_chunkIU3ZVEOUcjs.STORE_KEY), () => ( {}));
70
- const collectedCSS = _chunkIU3ZVEOUcjs.buildStylexRules.call(void 0, stylexRules, _nullishCoalesce(((_b = options.stylex) == null ? void 0 : _b.useCSSLayers), () => ( false)));
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
- declare function astro(options?: UnpluginStylexOptions): {
53
+ export default function astro(options?: UnpluginStylexOptions): {
26
54
  name: string;
27
55
  hooks: {
28
- 'astro:config:setup': ({ config, updateConfig, injectScript }: {
29
- config: any;
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
- export { astro as default };
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-F2LYIKCV.js";
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-B3OIQQRZ.js";
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 cssPath = path.posix.join(base, filename).replace(/\/+/g, "/");
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 = ((_a = config.vite.ssr) == null ? void 0 : _a.noExternal) ?? [];
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 base = "/";
67
- const cssPath = path.posix.join(base, filename).replace(/\/+/g, base);
68
- if (req.url === cssPath || req.url === `/${filename}` || ((_a = req.url) == null ? void 0 : _a.endsWith(`/${filename}`))) {
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");