@stylexswc/unplugin 0.11.2-rc.1 → 0.11.2-rc.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/README.md +66 -0
- package/dist/astro.cjs +2 -2
- package/dist/astro.js +1 -1
- package/dist/{chunk-4YI47FZZ.js → chunk-3EDKY6TH.js} +1 -1
- package/dist/{chunk-VCGI7W6A.cjs → chunk-55H2YGNW.cjs} +114 -16
- package/dist/{chunk-YQB2TVUP.cjs → chunk-56CEC7LU.cjs} +2 -2
- package/dist/{chunk-7GG4DYVS.js → chunk-AHX3RGCT.js} +1 -1
- package/dist/{chunk-WJOLWJKA.cjs → chunk-MZPFT5OY.cjs} +2 -2
- package/dist/{chunk-267F4SHV.js → chunk-NM6UYBKL.js} +114 -16
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +2 -2
- package/dist/farm.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +5 -5
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/types.d.cts +7 -0
- package/dist/types.d.ts +7 -0
- package/dist/vite.cjs +3 -3
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +3 -3
- package/dist/webpack.js +2 -2
- package/package.json +7 -3
- package/virtual-css.d.ts +15 -0
package/README.md
CHANGED
|
@@ -184,6 +184,72 @@ build({
|
|
|
184
184
|
- Default: `['js', 'jsx', 'ts', 'tsx', 'mjs', 'mts']`
|
|
185
185
|
- Description: File extensions to process for StyleX transformations.
|
|
186
186
|
|
|
187
|
+
#### `useViteCssPipeline`
|
|
188
|
+
|
|
189
|
+
- Type: `boolean`
|
|
190
|
+
- Default: `false`
|
|
191
|
+
- Description: **(Vite only)** Integrates StyleX-generated CSS into Vite's CSS processing pipeline as a virtual module. When enabled, StyleX CSS will be processed through Vite's CSS transformers (including PostCSS, LightningCSS, etc.) and benefit from proper HMR support.
|
|
192
|
+
|
|
193
|
+
##### Benefits
|
|
194
|
+
|
|
195
|
+
- **CSS Processing**: Generated StyleX CSS goes through Vite's CSS pipeline (PostCSS, LightningCSS, etc.)
|
|
196
|
+
- **Better HMR**: CSS updates are handled through Vite's native CSS HMR with proper source maps
|
|
197
|
+
- **Consistent Output**: All CSS follows the same processing rules and bundling strategy
|
|
198
|
+
- **Build Optimization**: CSS can be code-split and optimized alongside other stylesheets
|
|
199
|
+
|
|
200
|
+
##### How to Use
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// vite.config.ts
|
|
204
|
+
import StylexRsPlugin from '@stylexswc/unplugin/vite';
|
|
205
|
+
import { defineConfig } from 'vite';
|
|
206
|
+
|
|
207
|
+
export default defineConfig({
|
|
208
|
+
plugins: [
|
|
209
|
+
StylexRsPlugin({
|
|
210
|
+
useViteCssPipeline: true,
|
|
211
|
+
}),
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Then import the virtual CSS module in your entry file:
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// src/main.ts
|
|
220
|
+
import 'virtual:stylex.css';
|
|
221
|
+
import { App } from './App';
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**TypeScript Support:**
|
|
225
|
+
|
|
226
|
+
For TypeScript projects, add the type definition to your `tsconfig.json`:
|
|
227
|
+
|
|
228
|
+
```json
|
|
229
|
+
{
|
|
230
|
+
"compilerOptions": {
|
|
231
|
+
"types": ["@stylexswc/unplugin/virtual-css"]
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
> [!NOTE]
|
|
237
|
+
> When `useViteCssPipeline` is enabled, you need to explicitly import `virtual:stylex.css` in your application. The plugin will no longer inject CSS automatically into the HTML.
|
|
238
|
+
|
|
239
|
+
> [!IMPORTANT]
|
|
240
|
+
> **Reset CSS and Other Global Styles**
|
|
241
|
+
>
|
|
242
|
+
> The `virtual:stylex.css` module should only contain StyleX-generated CSS. If you need to include reset CSS, global styles, or other non-StyleX CSS, import them from separate CSS files:
|
|
243
|
+
>
|
|
244
|
+
> ```typescript
|
|
245
|
+
> // src/main.ts
|
|
246
|
+
> import './reset.css'; // Your reset CSS
|
|
247
|
+
> import './global.css'; // Other global styles
|
|
248
|
+
> import 'virtual:stylex.css'; // StyleX-generated CSS
|
|
249
|
+
> ```
|
|
250
|
+
>
|
|
251
|
+
> **Do not** put reset CSS or other styles inside the virtual module, as they should be managed separately from the StyleX-generated styles. See the examples in [`apps/vite-unplugin-virtual-css-example`](../../apps/vite-unplugin-virtual-css-example) and [`apps/vue-unplugin-virtual-css-example`](../../apps/vue-unplugin-virtual-css-example) for reference.
|
|
252
|
+
|
|
187
253
|
### Example Configuration
|
|
188
254
|
|
|
189
255
|
```typescript
|
package/dist/astro.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/astro.ts
|
|
@@ -10,7 +10,7 @@ var astro_default = (options) => ({
|
|
|
10
10
|
"astro:config:setup": async (astro) => {
|
|
11
11
|
var _a;
|
|
12
12
|
(_a = astro.config.vite).plugins || (_a.plugins = []);
|
|
13
|
-
astro.config.vite.plugins.push(
|
|
13
|
+
astro.config.vite.plugins.push(_chunk55H2YGNWcjs.index_default.vite(options));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
});
|
package/dist/astro.js
CHANGED
|
@@ -37,13 +37,14 @@ function getStyleXRules(stylexRules, useCSSLayers) {
|
|
|
37
37
|
// src/utils/normalizeOptions.ts
|
|
38
38
|
var _rscompiler = require('@stylexswc/rs-compiler'); var _rscompiler2 = _interopRequireDefault(_rscompiler);
|
|
39
39
|
function normalizeOptions(options) {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
40
|
+
var _a, _b, _c, _d, _e;
|
|
41
41
|
return __spreadProps(__spreadValues({}, options), {
|
|
42
42
|
fileName: (_a = options.fileName) != null ? _a : "stylex.css",
|
|
43
43
|
useCSSLayers: (_b = options.useCSSLayers) != null ? _b : false,
|
|
44
44
|
pageExtensions: (_c = options.pageExtensions) != null ? _c : ["tsx", "jsx", "js", "ts"],
|
|
45
45
|
rsOptions: _rscompiler.normalizeRsOptions.call(void 0, options.rsOptions || {}),
|
|
46
|
-
extractCSS: (_d = options.extractCSS) != null ? _d : true
|
|
46
|
+
extractCSS: (_d = options.extractCSS) != null ? _d : true,
|
|
47
|
+
useViteCssPipeline: (_e = options.useViteCssPipeline) != null ? _e : false
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -59,6 +60,12 @@ function generateHash(content) {
|
|
|
59
60
|
// src/index.ts
|
|
60
61
|
|
|
61
62
|
var { writeFile, mkdir } = _fs.promises;
|
|
63
|
+
var VIRTUAL_CSS_MODULE_ID = "virtual:stylex.css";
|
|
64
|
+
var RESOLVED_VIRTUAL_CSS_MODULE_ID = "\0" + VIRTUAL_CSS_MODULE_ID;
|
|
65
|
+
var VIRTUAL_CSS_MARKER_VAR = "--stylex-placeholder";
|
|
66
|
+
var VIRTUAL_CSS_MARKER = `:root{${VIRTUAL_CSS_MARKER_VAR}:1}`;
|
|
67
|
+
var viteDevServer = null;
|
|
68
|
+
var hasInvalidatedInitialCSS = false;
|
|
62
69
|
function replaceFileName(original, css) {
|
|
63
70
|
if (!original.includes("[hash]")) {
|
|
64
71
|
return original;
|
|
@@ -123,6 +130,29 @@ var unpluginFactory = (options = {}) => {
|
|
|
123
130
|
]
|
|
124
131
|
});
|
|
125
132
|
}
|
|
133
|
+
if (normalizedOptions.useViteCssPipeline && viteDevServer && !hasInvalidatedInitialCSS) {
|
|
134
|
+
const hasStyleXCode2 = code !== inputCode;
|
|
135
|
+
if (hasStyleXCode2) {
|
|
136
|
+
hasInvalidatedInitialCSS = true;
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
const mod = viteDevServer == null ? void 0 : viteDevServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
139
|
+
if (mod) {
|
|
140
|
+
viteDevServer == null ? void 0 : viteDevServer.moduleGraph.invalidateModule(mod);
|
|
141
|
+
viteDevServer == null ? void 0 : viteDevServer.ws.send({
|
|
142
|
+
type: "update",
|
|
143
|
+
updates: [
|
|
144
|
+
{
|
|
145
|
+
type: "js-update",
|
|
146
|
+
acceptedPath: RESOLVED_VIRTUAL_CSS_MODULE_ID,
|
|
147
|
+
path: RESOLVED_VIRTUAL_CSS_MODULE_ID,
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, 50);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
126
156
|
return {
|
|
127
157
|
code,
|
|
128
158
|
map,
|
|
@@ -161,8 +191,53 @@ var unpluginFactory = (options = {}) => {
|
|
|
161
191
|
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
162
192
|
config.optimizeDeps.exclude.push("@stylexjs/open-props");
|
|
163
193
|
},
|
|
194
|
+
resolveId(id) {
|
|
195
|
+
if (id === VIRTUAL_CSS_MODULE_ID) {
|
|
196
|
+
return RESOLVED_VIRTUAL_CSS_MODULE_ID;
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
async load(id) {
|
|
200
|
+
var _a;
|
|
201
|
+
if (id === RESOLVED_VIRTUAL_CSS_MODULE_ID) {
|
|
202
|
+
const isDev = (_a = this.meta) == null ? void 0 : _a.watchMode;
|
|
203
|
+
if (isDev) {
|
|
204
|
+
const collectedCSS = getStyleXRules(stylexRules, normalizedOptions.useCSSLayers);
|
|
205
|
+
if (!collectedCSS || collectedCSS.trim().length === 0) {
|
|
206
|
+
return {
|
|
207
|
+
code: "/* StyleX styles will load after transformation */",
|
|
208
|
+
map: null
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
code: collectedCSS,
|
|
213
|
+
map: null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
code: VIRTUAL_CSS_MARKER,
|
|
218
|
+
map: null
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
generateBundle(_options, bundle) {
|
|
223
|
+
if (!normalizedOptions.useViteCssPipeline) return;
|
|
224
|
+
const collectedCSS = getStyleXRules(stylexRules, normalizedOptions.useCSSLayers);
|
|
225
|
+
if (!collectedCSS) return;
|
|
226
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
227
|
+
if (output.type === "asset" && fileName.endsWith(".css")) {
|
|
228
|
+
const source = output.source.toString();
|
|
229
|
+
if (source.includes(VIRTUAL_CSS_MARKER)) {
|
|
230
|
+
output.source = source.replace(VIRTUAL_CSS_MARKER, collectedCSS);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
164
236
|
buildEnd() {
|
|
165
237
|
var _a;
|
|
238
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
166
241
|
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
167
242
|
stylexRules,
|
|
168
243
|
normalizedOptions,
|
|
@@ -178,6 +253,8 @@ var unpluginFactory = (options = {}) => {
|
|
|
178
253
|
}
|
|
179
254
|
},
|
|
180
255
|
configureServer(server) {
|
|
256
|
+
viteDevServer = server;
|
|
257
|
+
hasInvalidatedInitialCSS = false;
|
|
181
258
|
server.middlewares.use((req, res, next) => {
|
|
182
259
|
var _a;
|
|
183
260
|
if (cssFileName && ((_a = req.url) == null ? void 0 : _a.includes(cssFileName))) {
|
|
@@ -189,8 +266,18 @@ var unpluginFactory = (options = {}) => {
|
|
|
189
266
|
next();
|
|
190
267
|
});
|
|
191
268
|
},
|
|
192
|
-
async handleHotUpdate({ file: id, file, server, read }) {
|
|
269
|
+
async handleHotUpdate({ file: id, file, server, read, modules }) {
|
|
193
270
|
var _a;
|
|
271
|
+
if (file.includes(".vue")) {
|
|
272
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
273
|
+
const virtualMod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
274
|
+
if (virtualMod) {
|
|
275
|
+
server.moduleGraph.invalidateModule(virtualMod);
|
|
276
|
+
return [...modules, virtualMod];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
194
281
|
const inputCode = await read();
|
|
195
282
|
if (!hasStyleXCode(normalizedOptions, inputCode)) {
|
|
196
283
|
return;
|
|
@@ -202,23 +289,34 @@ var unpluginFactory = (options = {}) => {
|
|
|
202
289
|
(_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir
|
|
203
290
|
);
|
|
204
291
|
if (!collectedCSS) return;
|
|
205
|
-
if (
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
292
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
293
|
+
const virtualMod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
294
|
+
if (virtualMod) {
|
|
295
|
+
server.moduleGraph.invalidateModule(virtualMod);
|
|
296
|
+
return [...modules, virtualMod];
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
if (processedFileName) {
|
|
300
|
+
const normalizedFileName = ensureLeadingSlash(processedFileName);
|
|
301
|
+
server.ws.send({
|
|
302
|
+
type: "update",
|
|
303
|
+
updates: [
|
|
304
|
+
{
|
|
305
|
+
acceptedPath: normalizedFileName,
|
|
306
|
+
path: normalizedFileName,
|
|
307
|
+
timestamp: Date.now(),
|
|
308
|
+
type: "css-update"
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
}
|
|
218
313
|
}
|
|
219
314
|
},
|
|
220
315
|
transformIndexHtml: (html, ctx) => {
|
|
221
316
|
var _a, _b;
|
|
317
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
318
|
+
return html;
|
|
319
|
+
}
|
|
222
320
|
const isDev = !!ctx.server;
|
|
223
321
|
const { processedFileName } = generateCSSAssets(
|
|
224
322
|
stylexRules,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
|
|
5
5
|
// src/vite.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var vite_default = _unplugin.createVitePlugin.call(void 0,
|
|
7
|
+
var vite_default = _unplugin.createVitePlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
|
|
5
5
|
// src/webpack.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var webpack_default = _unplugin.createWebpackPlugin.call(void 0,
|
|
7
|
+
var webpack_default = _unplugin.createWebpackPlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -37,13 +37,14 @@ function getStyleXRules(stylexRules, useCSSLayers) {
|
|
|
37
37
|
// src/utils/normalizeOptions.ts
|
|
38
38
|
import { normalizeRsOptions } from "@stylexswc/rs-compiler";
|
|
39
39
|
function normalizeOptions(options) {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
40
|
+
var _a, _b, _c, _d, _e;
|
|
41
41
|
return __spreadProps(__spreadValues({}, options), {
|
|
42
42
|
fileName: (_a = options.fileName) != null ? _a : "stylex.css",
|
|
43
43
|
useCSSLayers: (_b = options.useCSSLayers) != null ? _b : false,
|
|
44
44
|
pageExtensions: (_c = options.pageExtensions) != null ? _c : ["tsx", "jsx", "js", "ts"],
|
|
45
45
|
rsOptions: normalizeRsOptions(options.rsOptions || {}),
|
|
46
|
-
extractCSS: (_d = options.extractCSS) != null ? _d : true
|
|
46
|
+
extractCSS: (_d = options.extractCSS) != null ? _d : true,
|
|
47
|
+
useViteCssPipeline: (_e = options.useViteCssPipeline) != null ? _e : false
|
|
47
48
|
});
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -59,6 +60,12 @@ function generateHash(content) {
|
|
|
59
60
|
// src/index.ts
|
|
60
61
|
import crypto2 from "crypto";
|
|
61
62
|
var { writeFile, mkdir } = promises;
|
|
63
|
+
var VIRTUAL_CSS_MODULE_ID = "virtual:stylex.css";
|
|
64
|
+
var RESOLVED_VIRTUAL_CSS_MODULE_ID = "\0" + VIRTUAL_CSS_MODULE_ID;
|
|
65
|
+
var VIRTUAL_CSS_MARKER_VAR = "--stylex-placeholder";
|
|
66
|
+
var VIRTUAL_CSS_MARKER = `:root{${VIRTUAL_CSS_MARKER_VAR}:1}`;
|
|
67
|
+
var viteDevServer = null;
|
|
68
|
+
var hasInvalidatedInitialCSS = false;
|
|
62
69
|
function replaceFileName(original, css) {
|
|
63
70
|
if (!original.includes("[hash]")) {
|
|
64
71
|
return original;
|
|
@@ -123,6 +130,29 @@ var unpluginFactory = (options = {}) => {
|
|
|
123
130
|
]
|
|
124
131
|
});
|
|
125
132
|
}
|
|
133
|
+
if (normalizedOptions.useViteCssPipeline && viteDevServer && !hasInvalidatedInitialCSS) {
|
|
134
|
+
const hasStyleXCode2 = code !== inputCode;
|
|
135
|
+
if (hasStyleXCode2) {
|
|
136
|
+
hasInvalidatedInitialCSS = true;
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
const mod = viteDevServer == null ? void 0 : viteDevServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
139
|
+
if (mod) {
|
|
140
|
+
viteDevServer == null ? void 0 : viteDevServer.moduleGraph.invalidateModule(mod);
|
|
141
|
+
viteDevServer == null ? void 0 : viteDevServer.ws.send({
|
|
142
|
+
type: "update",
|
|
143
|
+
updates: [
|
|
144
|
+
{
|
|
145
|
+
type: "js-update",
|
|
146
|
+
acceptedPath: RESOLVED_VIRTUAL_CSS_MODULE_ID,
|
|
147
|
+
path: RESOLVED_VIRTUAL_CSS_MODULE_ID,
|
|
148
|
+
timestamp: Date.now()
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, 50);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
126
156
|
return {
|
|
127
157
|
code,
|
|
128
158
|
map,
|
|
@@ -161,8 +191,53 @@ var unpluginFactory = (options = {}) => {
|
|
|
161
191
|
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
162
192
|
config.optimizeDeps.exclude.push("@stylexjs/open-props");
|
|
163
193
|
},
|
|
194
|
+
resolveId(id) {
|
|
195
|
+
if (id === VIRTUAL_CSS_MODULE_ID) {
|
|
196
|
+
return RESOLVED_VIRTUAL_CSS_MODULE_ID;
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
async load(id) {
|
|
200
|
+
var _a;
|
|
201
|
+
if (id === RESOLVED_VIRTUAL_CSS_MODULE_ID) {
|
|
202
|
+
const isDev = (_a = this.meta) == null ? void 0 : _a.watchMode;
|
|
203
|
+
if (isDev) {
|
|
204
|
+
const collectedCSS = getStyleXRules(stylexRules, normalizedOptions.useCSSLayers);
|
|
205
|
+
if (!collectedCSS || collectedCSS.trim().length === 0) {
|
|
206
|
+
return {
|
|
207
|
+
code: "/* StyleX styles will load after transformation */",
|
|
208
|
+
map: null
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
code: collectedCSS,
|
|
213
|
+
map: null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
code: VIRTUAL_CSS_MARKER,
|
|
218
|
+
map: null
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
generateBundle(_options, bundle) {
|
|
223
|
+
if (!normalizedOptions.useViteCssPipeline) return;
|
|
224
|
+
const collectedCSS = getStyleXRules(stylexRules, normalizedOptions.useCSSLayers);
|
|
225
|
+
if (!collectedCSS) return;
|
|
226
|
+
for (const [fileName, output] of Object.entries(bundle)) {
|
|
227
|
+
if (output.type === "asset" && fileName.endsWith(".css")) {
|
|
228
|
+
const source = output.source.toString();
|
|
229
|
+
if (source.includes(VIRTUAL_CSS_MARKER)) {
|
|
230
|
+
output.source = source.replace(VIRTUAL_CSS_MARKER, collectedCSS);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
164
236
|
buildEnd() {
|
|
165
237
|
var _a;
|
|
238
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
166
241
|
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
167
242
|
stylexRules,
|
|
168
243
|
normalizedOptions,
|
|
@@ -178,6 +253,8 @@ var unpluginFactory = (options = {}) => {
|
|
|
178
253
|
}
|
|
179
254
|
},
|
|
180
255
|
configureServer(server) {
|
|
256
|
+
viteDevServer = server;
|
|
257
|
+
hasInvalidatedInitialCSS = false;
|
|
181
258
|
server.middlewares.use((req, res, next) => {
|
|
182
259
|
var _a;
|
|
183
260
|
if (cssFileName && ((_a = req.url) == null ? void 0 : _a.includes(cssFileName))) {
|
|
@@ -189,8 +266,18 @@ var unpluginFactory = (options = {}) => {
|
|
|
189
266
|
next();
|
|
190
267
|
});
|
|
191
268
|
},
|
|
192
|
-
async handleHotUpdate({ file: id, file, server, read }) {
|
|
269
|
+
async handleHotUpdate({ file: id, file, server, read, modules }) {
|
|
193
270
|
var _a;
|
|
271
|
+
if (file.includes(".vue")) {
|
|
272
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
273
|
+
const virtualMod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
274
|
+
if (virtualMod) {
|
|
275
|
+
server.moduleGraph.invalidateModule(virtualMod);
|
|
276
|
+
return [...modules, virtualMod];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
194
281
|
const inputCode = await read();
|
|
195
282
|
if (!hasStyleXCode(normalizedOptions, inputCode)) {
|
|
196
283
|
return;
|
|
@@ -202,23 +289,34 @@ var unpluginFactory = (options = {}) => {
|
|
|
202
289
|
(_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir
|
|
203
290
|
);
|
|
204
291
|
if (!collectedCSS) return;
|
|
205
|
-
if (
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
292
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
293
|
+
const virtualMod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_MODULE_ID);
|
|
294
|
+
if (virtualMod) {
|
|
295
|
+
server.moduleGraph.invalidateModule(virtualMod);
|
|
296
|
+
return [...modules, virtualMod];
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
if (processedFileName) {
|
|
300
|
+
const normalizedFileName = ensureLeadingSlash(processedFileName);
|
|
301
|
+
server.ws.send({
|
|
302
|
+
type: "update",
|
|
303
|
+
updates: [
|
|
304
|
+
{
|
|
305
|
+
acceptedPath: normalizedFileName,
|
|
306
|
+
path: normalizedFileName,
|
|
307
|
+
timestamp: Date.now(),
|
|
308
|
+
type: "css-update"
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
}
|
|
218
313
|
}
|
|
219
314
|
},
|
|
220
315
|
transformIndexHtml: (html, ctx) => {
|
|
221
316
|
var _a, _b;
|
|
317
|
+
if (normalizedOptions.useViteCssPipeline) {
|
|
318
|
+
return html;
|
|
319
|
+
}
|
|
222
320
|
const isDev = !!ctx.server;
|
|
223
321
|
const { processedFileName } = generateCSSAssets(
|
|
224
322
|
stylexRules,
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/esbuild.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0,
|
|
8
|
+
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = esbuild_default;
|
package/dist/esbuild.js
CHANGED
package/dist/farm.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/farm.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var plugin = _unplugin.createFarmPlugin.call(void 0,
|
|
8
|
+
var plugin = _unplugin.createFarmPlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
9
9
|
var farm_default = plugin;
|
|
10
10
|
|
|
11
11
|
|
package/dist/farm.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
6
6
|
require('./chunk-ZBPRDZS4.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.default =
|
|
11
|
+
exports.default = _chunk55H2YGNWcjs.index_default; exports.unplugin = _chunk55H2YGNWcjs.unplugin; exports.unpluginFactory = _chunk55H2YGNWcjs.unpluginFactory;
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk56CEC7LUcjs = require('./chunk-56CEC7LU.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('./chunk-
|
|
6
|
+
var _chunkMZPFT5OYcjs = require('./chunk-MZPFT5OY.cjs');
|
|
7
|
+
require('./chunk-55H2YGNW.cjs');
|
|
8
8
|
require('./chunk-ZBPRDZS4.cjs');
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
|
@@ -19,8 +19,8 @@ var nuxt_default = _kit.defineNuxtModule.call(void 0, {
|
|
|
19
19
|
// ...default options
|
|
20
20
|
},
|
|
21
21
|
setup(options, _nuxt) {
|
|
22
|
-
_kit.addVitePlugin.call(void 0, () =>
|
|
23
|
-
_kit.addWebpackPlugin.call(void 0, () =>
|
|
22
|
+
_kit.addVitePlugin.call(void 0, () => _chunk56CEC7LUcjs.vite_default.call(void 0, options));
|
|
23
|
+
_kit.addWebpackPlugin.call(void 0, () => _chunkMZPFT5OYcjs.webpack_default.call(void 0, options));
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
package/dist/nuxt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AHX3RGCT.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-3EDKY6TH.js";
|
|
7
|
+
import "./chunk-NM6UYBKL.js";
|
|
8
8
|
import "./chunk-6F4PWJZI.js";
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/rollup.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var rollup_default = _unplugin.createRollupPlugin.call(void 0,
|
|
8
|
+
var rollup_default = _unplugin.createRollupPlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = rollup_default;
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk55H2YGNWcjs = require('./chunk-55H2YGNW.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/rspack.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var rspack_default = _unplugin.createRspackPlugin.call(void 0,
|
|
8
|
+
var rspack_default = _unplugin.createRspackPlugin.call(void 0, _chunk55H2YGNWcjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = rspack_default;
|
package/dist/rspack.js
CHANGED
package/dist/types.d.cts
CHANGED
|
@@ -6,6 +6,13 @@ interface UnpluginStylexRSOptions {
|
|
|
6
6
|
pageExtensions?: string[];
|
|
7
7
|
rsOptions?: StyleXOptions;
|
|
8
8
|
extractCSS?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Use Vite's CSS pipeline for processing StyleX CSS.
|
|
11
|
+
* When enabled, StyleX CSS will be processed through Vite's transforms (LightningCSS, PostCSS, etc.)
|
|
12
|
+
* instead of being directly injected into HTML.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
useViteCssPipeline?: boolean;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
export type { UnpluginStylexRSOptions };
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ interface UnpluginStylexRSOptions {
|
|
|
6
6
|
pageExtensions?: string[];
|
|
7
7
|
rsOptions?: StyleXOptions;
|
|
8
8
|
extractCSS?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Use Vite's CSS pipeline for processing StyleX CSS.
|
|
11
|
+
* When enabled, StyleX CSS will be processed through Vite's transforms (LightningCSS, PostCSS, etc.)
|
|
12
|
+
* instead of being directly injected into HTML.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
useViteCssPipeline?: boolean;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
export type { UnpluginStylexRSOptions };
|
package/dist/vite.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var _chunk56CEC7LUcjs = require('./chunk-56CEC7LU.cjs');
|
|
4
|
+
require('./chunk-55H2YGNW.cjs');
|
|
5
5
|
require('./chunk-ZBPRDZS4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = _chunk56CEC7LUcjs.vite_default;
|
|
9
9
|
|
|
10
10
|
module.exports = exports.default;
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var _chunkMZPFT5OYcjs = require('./chunk-MZPFT5OY.cjs');
|
|
4
|
+
require('./chunk-55H2YGNW.cjs');
|
|
5
5
|
require('./chunk-ZBPRDZS4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = _chunkMZPFT5OYcjs.webpack_default;
|
|
9
9
|
|
|
10
10
|
module.exports = exports.default;
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/unplugin",
|
|
3
3
|
"description": "Unplugin for StyleX RS compiler",
|
|
4
|
-
"version": "0.11.2-rc.
|
|
4
|
+
"version": "0.11.2-rc.3",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -58,10 +58,14 @@
|
|
|
58
58
|
"import": "./dist/types.js",
|
|
59
59
|
"require": "./dist/types.cjs"
|
|
60
60
|
},
|
|
61
|
+
"./virtual-css": {
|
|
62
|
+
"types": "./virtual-css.d.ts"
|
|
63
|
+
},
|
|
61
64
|
"./*": "./*"
|
|
62
65
|
},
|
|
63
66
|
"files": [
|
|
64
|
-
"dist"
|
|
67
|
+
"dist",
|
|
68
|
+
"virtual-css.d.ts"
|
|
65
69
|
],
|
|
66
70
|
"publishConfig": {
|
|
67
71
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -74,7 +78,7 @@
|
|
|
74
78
|
},
|
|
75
79
|
"dependencies": {
|
|
76
80
|
"@stylexjs/babel-plugin": "^0.15.4",
|
|
77
|
-
"@stylexswc/rs-compiler": "0.11.2-rc.
|
|
81
|
+
"@stylexswc/rs-compiler": "0.11.2-rc.3",
|
|
78
82
|
"unplugin": "^2.3.5",
|
|
79
83
|
"vite": "^7.1.9",
|
|
80
84
|
"vite-plugin-inspect": "^11.3.3"
|
package/virtual-css.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript declaration for StyleX virtual CSS module
|
|
3
|
+
*
|
|
4
|
+
* When using `useViteCssPipeline: true`, you can import the virtual CSS module:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import 'virtual:stylex.css';
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
declare module 'virtual:stylex.css' {
|
|
12
|
+
const css: string;
|
|
13
|
+
export default css;
|
|
14
|
+
}
|
|
15
|
+
|