@vizejs/unplugin 0.661.0 → 0.663.0

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 CHANGED
@@ -115,9 +115,9 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
115
115
  ## Caveats
116
116
 
117
117
  - Vite is still the recommended integration if you need the most complete behavior today.
118
- - Plain inline CSS is injected into JavaScript at runtime; CSS asset extraction and SSR stylesheet delivery are not provided by this path.
118
+ - Every `<style>` block is a stylesheet module for the bundler's CSS pipeline, which writes the CSS file, as with `unplugin-vue`. The module is named like Vue's style requests, `App.vue?vue&type=style&index=0&lang.css` (`lang.module.css`, `lang.scss`), so a pipeline that handles a `.css` or `.scss` file handles the block: tsdown with `@tsdown/css` writes `style.css`, esbuild writes `<entry>.css` (set `outdir` or `outfile`), Rollup needs a CSS plugin such as `rollup-plugin-postcss`, and webpack uses your `.css` rule. A build with no CSS pipeline fails on the first style block. Rolldown alone does not bundle CSS, so build through tsdown or Vite.
119
119
  - `<style src>`, `<script src>` and `<template src>` follow Vue's SFC spec, as in `@vitejs/plugin-vue`: a `./` or `../` path is read next to the SFC, and any other `src` (a package such as `modern-normalize/modern-normalize.css`, an alias, an absolute path, or a bare `foo.css`) is a module request resolved by the bundler's own resolver. The file is inlined before compilation and watched. A request that resolves to no file, including an external module, is a build error.
120
- - `@import` in plain CSS is a build error. Plain CSS is injected at runtime as a string, so an `@import` would be fetched relative to the page. Inline the imported CSS, move the block to a preprocessor or CSS Module (handled by the host CSS pipeline), or use `@vizejs/vite-plugin`.
120
+ - Babel and esbuild without `bundle` bundle no stylesheet, so there plain CSS is injected into JavaScript at run time, and an `@import` in it is a build error. Preprocessor and CSS Module blocks still need a CSS pipeline.
121
121
  - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
122
122
  - Scoped preprocessor styles are compiled before they are scoped, as in Vue: Webpack uses your `.scss`/`.less`/`.styl` rules, while Rollup, Rolldown and esbuild run the project's installed `sass` (or `sass-embedded`), `less` or `stylus`.
123
123
  - If your bundler inlines the Vue runtime, Vize injects the usual Vue 3 compile-time feature flags for Rollup-like and Webpack hosts when its compiler is active.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-CpAttP-g.cjs");
1
+ const require_unplugin = require("./unplugin-7UpIpoaj.cjs");
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = require_unplugin.normalizeOptions(rawOptions);
@@ -18,6 +18,7 @@ function vizeBabelPlugin(_api, rawOptions = {}) {
18
18
  return parse(require_unplugin.generateOutput(compiled, {
19
19
  isProduction: options.isProduction,
20
20
  isDev: false,
21
+ cssPipeline: false,
21
22
  filePath: filename
22
23
  }), {
23
24
  ...parserOptions,
package/dist/babel.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-Bs967qTR.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-hYMgbR_K.mjs";
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = normalizeOptions(rawOptions);
@@ -18,6 +18,7 @@ function vizeBabelPlugin(_api, rawOptions = {}) {
18
18
  return parse(generateOutput(compiled, {
19
19
  isProduction: options.isProduction,
20
20
  isDev: false,
21
+ cssPipeline: false,
21
22
  filePath: filename
22
23
  }), {
23
24
  ...parserOptions,
package/dist/esbuild.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/esbuild.ts
2
- var esbuild_default = require("./unplugin-CpAttP-g.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-7UpIpoaj.cjs").vizeUnplugin.esbuild;
3
3
  //#endregion
4
4
  module.exports = esbuild_default;
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-hYMgbR_K.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.cjs CHANGED
@@ -2,6 +2,6 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_unplugin = require("./unplugin-CpAttP-g.cjs");
5
+ const require_unplugin = require("./unplugin-7UpIpoaj.cjs");
6
6
  exports.default = require_unplugin.vizeUnplugin;
7
7
  exports.vizeUnplugin = require_unplugin.vizeUnplugin;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-hYMgbR_K.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
package/dist/rolldown.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/rolldown.ts
2
- var rolldown_default = require("./unplugin-CpAttP-g.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-7UpIpoaj.cjs").vizeUnplugin.rollup;
3
3
  //#endregion
4
4
  module.exports = rolldown_default;
package/dist/rolldown.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-hYMgbR_K.mjs";
2
2
  //#region src/rolldown.ts
3
3
  var rolldown_default = vizeUnplugin.rollup;
4
4
  //#endregion
package/dist/rollup.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/rollup.ts
2
- var rollup_default = require("./unplugin-CpAttP-g.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-7UpIpoaj.cjs").vizeUnplugin.rollup;
3
3
  //#endregion
4
4
  module.exports = rollup_default;
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-hYMgbR_K.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -95,6 +95,70 @@ function prependMappedJsxCode(code, mapJson, prefix) {
95
95
  };
96
96
  }
97
97
  //#endregion
98
+ //#region src/request.ts
99
+ function isVueFile(id) {
100
+ return id.endsWith(".vue");
101
+ }
102
+ function isJsxFile(id) {
103
+ return id.endsWith(".jsx") || id.endsWith(".tsx");
104
+ }
105
+ function isVueStyleRequest(id) {
106
+ if (!id.includes("?vue")) return false;
107
+ const { query } = parseVueRequest(id);
108
+ return query.vue && query.type === "style";
109
+ }
110
+ /**
111
+ * The module id of a delegated style block, in Vue's request shape:
112
+ * `App.vue?vue&type=style&index=0[&scoped=…][&module[=name]]&lang.<ext>`.
113
+ *
114
+ * CSS pipelines classify a module by the extension that ends the id, and treat
115
+ * a query on a stylesheet path as another import kind (`?raw`, `?inline`), so
116
+ * the path stays the SFC and `<ext>` names what `load` returns: a scoped
117
+ * preprocessor block is compiled before scoping, so it is CSS.
118
+ */
119
+ function styleRequestId(filePath, block, scoped) {
120
+ const lang = block.lang ?? "css";
121
+ const delivered = scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
122
+ let query = `vue&type=style&index=${block.index}`;
123
+ if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
124
+ if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
125
+ const ext = block.module === false ? delivered : `module.${delivered}`;
126
+ return `${filePath}?${query}&lang.${ext}`;
127
+ }
128
+ function parseVueRequest(id) {
129
+ const [filename, rawQuery = ""] = id.split("?", 2);
130
+ const params = new URLSearchParams(rawQuery);
131
+ const moduleValue = params.has("module") ? params.get("module") || true : false;
132
+ const indexValue = params.get("index");
133
+ return {
134
+ filename,
135
+ query: {
136
+ vue: params.has("vue"),
137
+ type: params.get("type"),
138
+ index: indexValue === null ? null : Number.parseInt(indexValue, 10),
139
+ module: moduleValue,
140
+ scoped: params.get("scoped")
141
+ }
142
+ };
143
+ }
144
+ //#endregion
145
+ //#region src/style-dependencies.ts
146
+ function hasImportRule(ast) {
147
+ if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
148
+ return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
149
+ }
150
+ /** `src` blocks are inlined before compilation; one left here was unreadable. */
151
+ function assertInlinedStyleSrc(styles, filename) {
152
+ for (const style of styles) if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
153
+ }
154
+ /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
155
+ function assertInjectableCss(styles, filename) {
156
+ for (const style of styles) {
157
+ if (!style.content.includes("@")) continue;
158
+ if (hasImportRule((0, _vizejs_native.parseCssAst)(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing resolves the import. Inline the imported CSS, bundle the build, or use @vizejs/vite-plugin.`);
159
+ }
160
+ }
161
+ //#endregion
98
162
  //#region src/style.ts
99
163
  function needsPreprocessor(block) {
100
164
  return require_webpack_styles.isPreprocessorLang(block.lang);
@@ -102,6 +166,7 @@ function needsPreprocessor(block) {
102
166
  function isCssModule(block) {
103
167
  return block.module !== false;
104
168
  }
169
+ /** Blocks only a host CSS pipeline can serve. */
105
170
  function hasDelegatedStyles(compiled) {
106
171
  return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
107
172
  }
@@ -147,7 +212,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
147
212
  ? ns.default
148
213
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
149
214
  function generateOutput(compiled, options) {
150
- const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
215
+ const { isProduction, isDev, cssPipeline, filePath, styleRequest } = options;
151
216
  let output = compiled.code;
152
217
  const exportDefaultRegex = /^export default /m;
153
218
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -164,31 +229,20 @@ function generateOutput(compiled, options) {
164
229
  output += "\n_sfc_main.render = render;";
165
230
  output += "\nexport default _sfc_main;";
166
231
  }
167
- if (hasDelegatedStyles(compiled) && filePath) {
232
+ if (cssPipeline || hasDelegatedStyles(compiled)) {
168
233
  const styleImports = [];
169
234
  const cssModuleImports = [];
170
235
  for (const block of compiled.styles) {
171
- const lang = block.lang ?? "css";
172
- const params = new URLSearchParams();
173
- params.set("vue", "");
174
- params.set("type", "style");
175
- params.set("index", String(block.index));
176
- params.set("lang", lang);
177
- if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
178
236
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
179
237
  const styleFile = styleRequest?.(block, scoped);
238
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
180
239
  if (isCssModule(block)) {
181
240
  const bindingName = typeof block.module === "string" ? block.module : "$style";
182
241
  if (styleFile) {
183
242
  const namespace = `__vize_css_module_${block.index}__`;
184
243
  cssModuleImports.push(`import * as ${namespace} from ${JSON.stringify(styleFile)};`, `const ${bindingName} = ${CSS_MODULE_LOCALS}(${namespace});`);
185
- } else {
186
- const moduleParams = new URLSearchParams(params);
187
- moduleParams.set("module", typeof block.module === "string" ? block.module : "");
188
- const moduleUrl = `${filePath}?${moduleParams.toString()}`;
189
- cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(moduleUrl)};`);
190
- }
191
- } else styleImports.push(`import ${JSON.stringify(styleFile ?? `${filePath}?${params.toString()}`)};`);
244
+ } else cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(styleId)};`);
245
+ } else styleImports.push(`import ${JSON.stringify(styleId)};`);
192
246
  }
193
247
  if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
194
248
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
@@ -200,7 +254,10 @@ function generateOutput(compiled, options) {
200
254
  }).join("\n");
201
255
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
202
256
  }
203
- } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
257
+ } else if (compiled.css) {
258
+ assertInjectableCss(compiled.styles, filePath);
259
+ output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
260
+ }
204
261
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
205
262
  return output;
206
263
  }
@@ -215,20 +272,6 @@ function toStyleBlockInfo(block) {
215
272
  };
216
273
  }
217
274
  //#endregion
218
- //#region src/style-dependencies.ts
219
- function hasImportRule(ast) {
220
- if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
221
- return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
222
- }
223
- /** The inline runtime style path cannot resolve external CSS dependencies. */
224
- function assertSupportedStyleDependencies(styles, filename) {
225
- for (const style of styles) {
226
- if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
227
- if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
228
- if (hasImportRule((0, _vizejs_native.parseCssAst)(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> is not supported by @vizejs/unplugin's inline style output. Inline the imported CSS, or use @vizejs/vite-plugin for stylesheet dependency resolution.`);
229
- }
230
- }
231
- //#endregion
232
275
  //#region ../shared/sfc-src.ts
233
276
  /**
234
277
  * Whether a block `src` is a path relative to the SFC. Any other `src`
@@ -422,7 +465,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
422
465
  inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
423
466
  });
424
467
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
425
- assertSupportedStyleDependencies(result.styles, filePath);
468
+ assertInlinedStyleSrc(result.styles, filePath);
426
469
  const compiled = {
427
470
  code: result.code,
428
471
  css: result.css,
@@ -469,59 +512,6 @@ function compileJsxModule(filePath, source, options) {
469
512
  };
470
513
  }
471
514
  //#endregion
472
- //#region src/request.ts
473
- const STYLE_MARKER = ".__vize_style_";
474
- function isVueFile(id) {
475
- return id.endsWith(".vue");
476
- }
477
- function isJsxFile(id) {
478
- return id.endsWith(".jsx") || id.endsWith(".tsx");
479
- }
480
- function isVueStyleRequest(id) {
481
- if (!id.includes("?vue")) return false;
482
- const { query } = parseVueRequest(id);
483
- return query.vue && query.type === "style";
484
- }
485
- function isVirtualStyleId(id) {
486
- return id.includes(STYLE_MARKER);
487
- }
488
- function parseVueRequest(id) {
489
- const [path, rawQuery = ""] = id.split("?", 2);
490
- const params = new URLSearchParams(rawQuery);
491
- const filename = params.get("vize-file") ?? path;
492
- const moduleValue = params.has("module") ? params.get("module") || true : false;
493
- const indexValue = params.get("index");
494
- return {
495
- filename,
496
- path,
497
- query: {
498
- vue: params.has("vue"),
499
- type: params.get("type"),
500
- index: indexValue === null ? null : Number.parseInt(indexValue, 10),
501
- lang: params.get("lang"),
502
- module: moduleValue,
503
- scoped: params.get("scoped"),
504
- vizeFile: params.get("vize-file")
505
- }
506
- };
507
- }
508
- function createVirtualStyleId(id) {
509
- const { filename, query } = parseVueRequest(id);
510
- const index = query.index ?? 0;
511
- const lang = query.lang ?? "css";
512
- const fileLang = query.scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
513
- const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
514
- const params = new URLSearchParams();
515
- params.set("vue", "");
516
- params.set("type", "style");
517
- params.set("index", String(index));
518
- params.set("lang", lang);
519
- params.set("vize-file", filename);
520
- if (query.scoped) params.set("scoped", query.scoped);
521
- if (query.module !== false) params.set("module", typeof query.module === "string" ? query.module : "");
522
- return `${filename}${STYLE_MARKER}${index}${suffix}?${params.toString()}`;
523
- }
524
- //#endregion
525
515
  //#region src/strip-types.ts
526
516
  function formatErrorMessage(error) {
527
517
  const parts = [error.message];
@@ -634,6 +624,19 @@ async function loadStyleBlock(context, id, options, cache) {
634
624
  if (!scoped) return source;
635
625
  return require_webpack_styles.scopeCss(block.lang && require_webpack_styles.isPreprocessorLang(block.lang) ? await require_webpack_styles.preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
636
626
  }
627
+ /**
628
+ * Whether the host bundles the stylesheets a module imports. esbuild without
629
+ * `bundle` never follows an import, so its CSS can only be injected.
630
+ */
631
+ function bundlesStylesheets(context, framework) {
632
+ if (framework !== "esbuild") return true;
633
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
634
+ }
635
+ const CSS_PIPELINE_HINT = "[vize] <style> blocks are stylesheet modules for the bundler's CSS pipeline, and this build did not bundle one. tsdown needs @tsdown/css; Rollup needs a CSS plugin such as rollup-plugin-postcss; Rolldown alone does not bundle CSS, so build through tsdown or Vite.";
636
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
637
+ function isStylePipelineError(error) {
638
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
639
+ }
637
640
  /** The bundler's own module resolver, or null for a host that offers none. */
638
641
  function hostResolver(context) {
639
642
  const ctx = context;
@@ -674,20 +677,29 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
674
677
  const cache = /* @__PURE__ */ new Map();
675
678
  const webpackStyleFiles = meta.framework === "webpack";
676
679
  let virtualModules;
680
+ let loadedStyles = false;
681
+ const rollupHooks = {
682
+ buildStart() {
683
+ loadedStyles = false;
684
+ },
685
+ buildEnd(error) {
686
+ if (error && loadedStyles && isStylePipelineError(error)) this.warn(CSS_PIPELINE_HINT);
687
+ }
688
+ };
677
689
  return {
678
690
  name: "unplugin-vize",
679
691
  resolveId(id) {
680
692
  if (options.hostCompiler) return null;
681
- if (isVueStyleRequest(id)) return createVirtualStyleId(id);
682
- return null;
693
+ return isVueStyleRequest(id) ? id : null;
683
694
  },
684
695
  loadInclude(id) {
685
696
  if (options.hostCompiler) return false;
686
- return !webpackStyleFiles && isVirtualStyleId(id);
697
+ return !webpackStyleFiles && isVueStyleRequest(id);
687
698
  },
688
699
  async load(id) {
689
700
  if (options.hostCompiler) return null;
690
- if (!isVirtualStyleId(id)) return null;
701
+ if (!isVueStyleRequest(id)) return null;
702
+ loadedStyles = true;
691
703
  return {
692
704
  code: await loadStyleBlock(this, id, options, cache),
693
705
  map: null
@@ -718,6 +730,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
718
730
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
719
731
  isProduction: options.isProduction,
720
732
  isDev: false,
733
+ cssPipeline: bundlesStylesheets(this, meta.framework),
721
734
  filePath: id,
722
735
  styleRequest: webpackStyleFiles ? (block, scoped) => {
723
736
  const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
@@ -734,6 +747,8 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
734
747
  watchChange(id) {
735
748
  if (isVueFile(id)) cache.delete(id);
736
749
  },
750
+ rollup: rollupHooks,
751
+ rolldown: rollupHooks,
737
752
  webpack(compiler) {
738
753
  if (!options.hostCompiler) {
739
754
  virtualModules = require_webpack_styles.findVirtualModules(compiler);
@@ -743,7 +758,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
743
758
  },
744
759
  esbuild: {
745
760
  onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
746
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\./,
761
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
747
762
  loader(_code, id) {
748
763
  const request = parseVueRequest(id);
749
764
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -93,6 +93,70 @@ function prependMappedJsxCode(code, mapJson, prefix) {
93
93
  };
94
94
  }
95
95
  //#endregion
96
+ //#region src/request.ts
97
+ function isVueFile(id) {
98
+ return id.endsWith(".vue");
99
+ }
100
+ function isJsxFile(id) {
101
+ return id.endsWith(".jsx") || id.endsWith(".tsx");
102
+ }
103
+ function isVueStyleRequest(id) {
104
+ if (!id.includes("?vue")) return false;
105
+ const { query } = parseVueRequest(id);
106
+ return query.vue && query.type === "style";
107
+ }
108
+ /**
109
+ * The module id of a delegated style block, in Vue's request shape:
110
+ * `App.vue?vue&type=style&index=0[&scoped=…][&module[=name]]&lang.<ext>`.
111
+ *
112
+ * CSS pipelines classify a module by the extension that ends the id, and treat
113
+ * a query on a stylesheet path as another import kind (`?raw`, `?inline`), so
114
+ * the path stays the SFC and `<ext>` names what `load` returns: a scoped
115
+ * preprocessor block is compiled before scoping, so it is CSS.
116
+ */
117
+ function styleRequestId(filePath, block, scoped) {
118
+ const lang = block.lang ?? "css";
119
+ const delivered = scoped && isPreprocessorLang(lang) ? "css" : lang;
120
+ let query = `vue&type=style&index=${block.index}`;
121
+ if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
122
+ if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
123
+ const ext = block.module === false ? delivered : `module.${delivered}`;
124
+ return `${filePath}?${query}&lang.${ext}`;
125
+ }
126
+ function parseVueRequest(id) {
127
+ const [filename, rawQuery = ""] = id.split("?", 2);
128
+ const params = new URLSearchParams(rawQuery);
129
+ const moduleValue = params.has("module") ? params.get("module") || true : false;
130
+ const indexValue = params.get("index");
131
+ return {
132
+ filename,
133
+ query: {
134
+ vue: params.has("vue"),
135
+ type: params.get("type"),
136
+ index: indexValue === null ? null : Number.parseInt(indexValue, 10),
137
+ module: moduleValue,
138
+ scoped: params.get("scoped")
139
+ }
140
+ };
141
+ }
142
+ //#endregion
143
+ //#region src/style-dependencies.ts
144
+ function hasImportRule(ast) {
145
+ if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
146
+ return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
147
+ }
148
+ /** `src` blocks are inlined before compilation; one left here was unreadable. */
149
+ function assertInlinedStyleSrc(styles, filename) {
150
+ for (const style of styles) if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
151
+ }
152
+ /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
153
+ function assertInjectableCss(styles, filename) {
154
+ for (const style of styles) {
155
+ if (!style.content.includes("@")) continue;
156
+ if (hasImportRule(parseCssAst(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing resolves the import. Inline the imported CSS, bundle the build, or use @vizejs/vite-plugin.`);
157
+ }
158
+ }
159
+ //#endregion
96
160
  //#region src/style.ts
97
161
  function needsPreprocessor(block) {
98
162
  return isPreprocessorLang(block.lang);
@@ -100,6 +164,7 @@ function needsPreprocessor(block) {
100
164
  function isCssModule(block) {
101
165
  return block.module !== false;
102
166
  }
167
+ /** Blocks only a host CSS pipeline can serve. */
103
168
  function hasDelegatedStyles(compiled) {
104
169
  return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
105
170
  }
@@ -145,7 +210,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
145
210
  ? ns.default
146
211
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
147
212
  function generateOutput(compiled, options) {
148
- const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
213
+ const { isProduction, isDev, cssPipeline, filePath, styleRequest } = options;
149
214
  let output = compiled.code;
150
215
  const exportDefaultRegex = /^export default /m;
151
216
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -162,31 +227,20 @@ function generateOutput(compiled, options) {
162
227
  output += "\n_sfc_main.render = render;";
163
228
  output += "\nexport default _sfc_main;";
164
229
  }
165
- if (hasDelegatedStyles(compiled) && filePath) {
230
+ if (cssPipeline || hasDelegatedStyles(compiled)) {
166
231
  const styleImports = [];
167
232
  const cssModuleImports = [];
168
233
  for (const block of compiled.styles) {
169
- const lang = block.lang ?? "css";
170
- const params = new URLSearchParams();
171
- params.set("vue", "");
172
- params.set("type", "style");
173
- params.set("index", String(block.index));
174
- params.set("lang", lang);
175
- if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
176
234
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
177
235
  const styleFile = styleRequest?.(block, scoped);
236
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
178
237
  if (isCssModule(block)) {
179
238
  const bindingName = typeof block.module === "string" ? block.module : "$style";
180
239
  if (styleFile) {
181
240
  const namespace = `__vize_css_module_${block.index}__`;
182
241
  cssModuleImports.push(`import * as ${namespace} from ${JSON.stringify(styleFile)};`, `const ${bindingName} = ${CSS_MODULE_LOCALS}(${namespace});`);
183
- } else {
184
- const moduleParams = new URLSearchParams(params);
185
- moduleParams.set("module", typeof block.module === "string" ? block.module : "");
186
- const moduleUrl = `${filePath}?${moduleParams.toString()}`;
187
- cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(moduleUrl)};`);
188
- }
189
- } else styleImports.push(`import ${JSON.stringify(styleFile ?? `${filePath}?${params.toString()}`)};`);
242
+ } else cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(styleId)};`);
243
+ } else styleImports.push(`import ${JSON.stringify(styleId)};`);
190
244
  }
191
245
  if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
192
246
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
@@ -198,7 +252,10 @@ function generateOutput(compiled, options) {
198
252
  }).join("\n");
199
253
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
200
254
  }
201
- } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
255
+ } else if (compiled.css) {
256
+ assertInjectableCss(compiled.styles, filePath);
257
+ output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
258
+ }
202
259
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
203
260
  return output;
204
261
  }
@@ -213,20 +270,6 @@ function toStyleBlockInfo(block) {
213
270
  };
214
271
  }
215
272
  //#endregion
216
- //#region src/style-dependencies.ts
217
- function hasImportRule(ast) {
218
- if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
219
- return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
220
- }
221
- /** The inline runtime style path cannot resolve external CSS dependencies. */
222
- function assertSupportedStyleDependencies(styles, filename) {
223
- for (const style of styles) {
224
- if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
225
- if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
226
- if (hasImportRule(parseCssAst(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> is not supported by @vizejs/unplugin's inline style output. Inline the imported CSS, or use @vizejs/vite-plugin for stylesheet dependency resolution.`);
227
- }
228
- }
229
- //#endregion
230
273
  //#region ../shared/sfc-src.ts
231
274
  /**
232
275
  * Whether a block `src` is a path relative to the SFC. Any other `src`
@@ -420,7 +463,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
420
463
  inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
421
464
  });
422
465
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
423
- assertSupportedStyleDependencies(result.styles, filePath);
466
+ assertInlinedStyleSrc(result.styles, filePath);
424
467
  const compiled = {
425
468
  code: result.code,
426
469
  css: result.css,
@@ -467,59 +510,6 @@ function compileJsxModule(filePath, source, options) {
467
510
  };
468
511
  }
469
512
  //#endregion
470
- //#region src/request.ts
471
- const STYLE_MARKER = ".__vize_style_";
472
- function isVueFile(id) {
473
- return id.endsWith(".vue");
474
- }
475
- function isJsxFile(id) {
476
- return id.endsWith(".jsx") || id.endsWith(".tsx");
477
- }
478
- function isVueStyleRequest(id) {
479
- if (!id.includes("?vue")) return false;
480
- const { query } = parseVueRequest(id);
481
- return query.vue && query.type === "style";
482
- }
483
- function isVirtualStyleId(id) {
484
- return id.includes(STYLE_MARKER);
485
- }
486
- function parseVueRequest(id) {
487
- const [path, rawQuery = ""] = id.split("?", 2);
488
- const params = new URLSearchParams(rawQuery);
489
- const filename = params.get("vize-file") ?? path;
490
- const moduleValue = params.has("module") ? params.get("module") || true : false;
491
- const indexValue = params.get("index");
492
- return {
493
- filename,
494
- path,
495
- query: {
496
- vue: params.has("vue"),
497
- type: params.get("type"),
498
- index: indexValue === null ? null : Number.parseInt(indexValue, 10),
499
- lang: params.get("lang"),
500
- module: moduleValue,
501
- scoped: params.get("scoped"),
502
- vizeFile: params.get("vize-file")
503
- }
504
- };
505
- }
506
- function createVirtualStyleId(id) {
507
- const { filename, query } = parseVueRequest(id);
508
- const index = query.index ?? 0;
509
- const lang = query.lang ?? "css";
510
- const fileLang = query.scoped && isPreprocessorLang(lang) ? "css" : lang;
511
- const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
512
- const params = new URLSearchParams();
513
- params.set("vue", "");
514
- params.set("type", "style");
515
- params.set("index", String(index));
516
- params.set("lang", lang);
517
- params.set("vize-file", filename);
518
- if (query.scoped) params.set("scoped", query.scoped);
519
- if (query.module !== false) params.set("module", typeof query.module === "string" ? query.module : "");
520
- return `${filename}${STYLE_MARKER}${index}${suffix}?${params.toString()}`;
521
- }
522
- //#endregion
523
513
  //#region src/strip-types.ts
524
514
  function formatErrorMessage(error) {
525
515
  const parts = [error.message];
@@ -632,6 +622,19 @@ async function loadStyleBlock(context, id, options, cache) {
632
622
  if (!scoped) return source;
633
623
  return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
634
624
  }
625
+ /**
626
+ * Whether the host bundles the stylesheets a module imports. esbuild without
627
+ * `bundle` never follows an import, so its CSS can only be injected.
628
+ */
629
+ function bundlesStylesheets(context, framework) {
630
+ if (framework !== "esbuild") return true;
631
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
632
+ }
633
+ const CSS_PIPELINE_HINT = "[vize] <style> blocks are stylesheet modules for the bundler's CSS pipeline, and this build did not bundle one. tsdown needs @tsdown/css; Rollup needs a CSS plugin such as rollup-plugin-postcss; Rolldown alone does not bundle CSS, so build through tsdown or Vite.";
634
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
635
+ function isStylePipelineError(error) {
636
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
637
+ }
635
638
  /** The bundler's own module resolver, or null for a host that offers none. */
636
639
  function hostResolver(context) {
637
640
  const ctx = context;
@@ -672,20 +675,29 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
672
675
  const cache = /* @__PURE__ */ new Map();
673
676
  const webpackStyleFiles = meta.framework === "webpack";
674
677
  let virtualModules;
678
+ let loadedStyles = false;
679
+ const rollupHooks = {
680
+ buildStart() {
681
+ loadedStyles = false;
682
+ },
683
+ buildEnd(error) {
684
+ if (error && loadedStyles && isStylePipelineError(error)) this.warn(CSS_PIPELINE_HINT);
685
+ }
686
+ };
675
687
  return {
676
688
  name: "unplugin-vize",
677
689
  resolveId(id) {
678
690
  if (options.hostCompiler) return null;
679
- if (isVueStyleRequest(id)) return createVirtualStyleId(id);
680
- return null;
691
+ return isVueStyleRequest(id) ? id : null;
681
692
  },
682
693
  loadInclude(id) {
683
694
  if (options.hostCompiler) return false;
684
- return !webpackStyleFiles && isVirtualStyleId(id);
695
+ return !webpackStyleFiles && isVueStyleRequest(id);
685
696
  },
686
697
  async load(id) {
687
698
  if (options.hostCompiler) return null;
688
- if (!isVirtualStyleId(id)) return null;
699
+ if (!isVueStyleRequest(id)) return null;
700
+ loadedStyles = true;
689
701
  return {
690
702
  code: await loadStyleBlock(this, id, options, cache),
691
703
  map: null
@@ -716,6 +728,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
716
728
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
717
729
  isProduction: options.isProduction,
718
730
  isDev: false,
731
+ cssPipeline: bundlesStylesheets(this, meta.framework),
719
732
  filePath: id,
720
733
  styleRequest: webpackStyleFiles ? (block, scoped) => {
721
734
  const stylePath = webpackStylePath(id, block, scoped);
@@ -732,6 +745,8 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
732
745
  watchChange(id) {
733
746
  if (isVueFile(id)) cache.delete(id);
734
747
  },
748
+ rollup: rollupHooks,
749
+ rolldown: rollupHooks,
735
750
  webpack(compiler) {
736
751
  if (!options.hostCompiler) {
737
752
  virtualModules = findVirtualModules(compiler);
@@ -741,7 +756,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
741
756
  },
742
757
  esbuild: {
743
758
  onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
744
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\./,
759
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
745
760
  loader(_code, id) {
746
761
  const request = parseVueRequest(id);
747
762
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-CpAttP-g.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-7UpIpoaj.cjs").vizeUnplugin.webpack;
3
3
  //#endregion
4
4
  module.exports = webpack_default;
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-Bs967qTR.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-hYMgbR_K.mjs";
2
2
  //#region src/webpack.ts
3
3
  var webpack_default = vizeUnplugin.webpack;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/unplugin",
3
- "version": "0.661.0",
3
+ "version": "0.663.0",
4
4
  "description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
5
5
  "keywords": [
6
6
  "babel",
@@ -68,7 +68,7 @@
68
68
  "access": "public"
69
69
  },
70
70
  "dependencies": {
71
- "@vizejs/native": "0.661.0",
71
+ "@vizejs/native": "0.663.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },