@vizejs/unplugin 0.662.0 → 0.664.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,10 +115,10 @@ 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`.
121
- - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path. Each block is a module 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 (`@tsdown/css`, `rollup-plugin-postcss`, esbuild) handles the block, and a host without one reports the same error it reports for such a file.
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`.
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
+ - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
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`. Unscoped preprocessor blocks go to the host's preprocessor (`@tsdown/css`, `rollup-plugin-postcss`, your webpack rules), except under esbuild, whose CSS loaders compile none, so the plugin runs the installed preprocessor there too.
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.
124
124
  - Test carefully before depending on this package in production.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-Dl8hs9VI.cjs");
1
+ const require_unplugin = require("./unplugin-COZmphjF.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
+ hostCss: "none",
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-BbWP410q.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BVGBB7oG.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
+ hostCss: "none",
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-Dl8hs9VI.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-COZmphjF.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-BbWP410q.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BVGBB7oG.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-Dl8hs9VI.cjs");
5
+ const require_unplugin = require("./unplugin-COZmphjF.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-BbWP410q.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BVGBB7oG.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-Dl8hs9VI.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-COZmphjF.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-BbWP410q.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BVGBB7oG.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-Dl8hs9VI.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-COZmphjF.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-BbWP410q.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BVGBB7oG.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-Ca7spvMb.mjs";
1
+ import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-CoRj2un6.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
@@ -111,12 +111,13 @@ function isVueStyleRequest(id) {
111
111
  *
112
112
  * CSS pipelines classify a module by the extension that ends the id, and treat
113
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.
114
+ * the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
115
+ * block arrives compiled when it is scoped (scoping follows preprocessing) or
116
+ * when the host compiles no preprocessor language.
116
117
  */
117
- function styleRequestId(filePath, block, scoped) {
118
+ function styleRequestId(filePath, block, scoped, hostCss) {
118
119
  const lang = block.lang ?? "css";
119
- const delivered = scoped && isPreprocessorLang(lang) ? "css" : lang;
120
+ const delivered = (scoped !== null || hostCss !== "preprocessors") && isPreprocessorLang(lang) ? "css" : lang;
120
121
  let query = `vue&type=style&index=${block.index}`;
121
122
  if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
122
123
  if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
@@ -128,18 +129,37 @@ function parseVueRequest(id) {
128
129
  const params = new URLSearchParams(rawQuery);
129
130
  const moduleValue = params.has("module") ? params.get("module") || true : false;
130
131
  const indexValue = params.get("index");
132
+ const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
131
133
  return {
132
134
  filename,
133
135
  query: {
134
136
  vue: params.has("vue"),
135
137
  type: params.get("type"),
136
138
  index: indexValue === null ? null : Number.parseInt(indexValue, 10),
139
+ lang: langKey?.replace(/^lang\.(?:module\.)?/, "") ?? null,
137
140
  module: moduleValue,
138
141
  scoped: params.get("scoped")
139
142
  }
140
143
  };
141
144
  }
142
145
  //#endregion
146
+ //#region src/style-dependencies.ts
147
+ function hasImportRule(ast) {
148
+ if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
149
+ return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
150
+ }
151
+ /** `src` blocks are inlined before compilation; one left here was unreadable. */
152
+ function assertInlinedStyleSrc(styles, filename) {
153
+ 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.`);
154
+ }
155
+ /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
156
+ function assertInjectableCss(styles, filename) {
157
+ for (const style of styles) {
158
+ if (!style.content.includes("@")) continue;
159
+ 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.`);
160
+ }
161
+ }
162
+ //#endregion
143
163
  //#region src/style.ts
144
164
  function needsPreprocessor(block) {
145
165
  return isPreprocessorLang(block.lang);
@@ -147,6 +167,7 @@ function needsPreprocessor(block) {
147
167
  function isCssModule(block) {
148
168
  return block.module !== false;
149
169
  }
170
+ /** Blocks only a host CSS pipeline can serve. */
150
171
  function hasDelegatedStyles(compiled) {
151
172
  return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
152
173
  }
@@ -192,7 +213,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
192
213
  ? ns.default
193
214
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
194
215
  function generateOutput(compiled, options) {
195
- const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
216
+ const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
196
217
  let output = compiled.code;
197
218
  const exportDefaultRegex = /^export default /m;
198
219
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -209,13 +230,13 @@ function generateOutput(compiled, options) {
209
230
  output += "\n_sfc_main.render = render;";
210
231
  output += "\nexport default _sfc_main;";
211
232
  }
212
- if (hasDelegatedStyles(compiled) && filePath) {
233
+ if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
213
234
  const styleImports = [];
214
235
  const cssModuleImports = [];
215
236
  for (const block of compiled.styles) {
216
237
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
217
238
  const styleFile = styleRequest?.(block, scoped);
218
- const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
239
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
219
240
  if (isCssModule(block)) {
220
241
  const bindingName = typeof block.module === "string" ? block.module : "$style";
221
242
  if (styleFile) {
@@ -234,7 +255,10 @@ function generateOutput(compiled, options) {
234
255
  }).join("\n");
235
256
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
236
257
  }
237
- } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
258
+ } else if (compiled.css) {
259
+ assertInjectableCss(compiled.styles, filePath);
260
+ output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
261
+ }
238
262
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
239
263
  return output;
240
264
  }
@@ -249,20 +273,6 @@ function toStyleBlockInfo(block) {
249
273
  };
250
274
  }
251
275
  //#endregion
252
- //#region src/style-dependencies.ts
253
- function hasImportRule(ast) {
254
- if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
255
- return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
256
- }
257
- /** The inline runtime style path cannot resolve external CSS dependencies. */
258
- function assertSupportedStyleDependencies(styles, filename) {
259
- for (const style of styles) {
260
- 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.`);
261
- if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
262
- 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.`);
263
- }
264
- }
265
- //#endregion
266
276
  //#region ../shared/sfc-src.ts
267
277
  /**
268
278
  * Whether a block `src` is a path relative to the SFC. Any other `src`
@@ -456,7 +466,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
456
466
  inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
457
467
  });
458
468
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
459
- assertSupportedStyleDependencies(result.styles, filePath);
469
+ assertInlinedStyleSrc(result.styles, filePath);
460
470
  const compiled = {
461
471
  code: result.code,
462
472
  css: result.css,
@@ -611,9 +621,22 @@ async function loadStyleBlock(context, id, options, cache) {
611
621
  const block = compiled?.styles[index];
612
622
  if (!compiled || !block) return "";
613
623
  const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
624
+ const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
614
625
  const scoped = request.query.scoped;
615
- if (!scoped) return source;
616
- return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
626
+ return scoped ? scopeCss(css, scoped) : css;
627
+ }
628
+ /**
629
+ * What the host does with an imported stylesheet. esbuild without `bundle`
630
+ * never follows an import, and its CSS loaders compile no preprocessor.
631
+ */
632
+ function hostCss(context, framework) {
633
+ if (framework !== "esbuild") return "preprocessors";
634
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
635
+ }
636
+ 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.";
637
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
638
+ function isStylePipelineError(error) {
639
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
617
640
  }
618
641
  /** The bundler's own module resolver, or null for a host that offers none. */
619
642
  function hostResolver(context) {
@@ -655,6 +678,15 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
655
678
  const cache = /* @__PURE__ */ new Map();
656
679
  const webpackStyleFiles = meta.framework === "webpack";
657
680
  let virtualModules;
681
+ let loadedStyles = false;
682
+ const rollupHooks = {
683
+ buildStart() {
684
+ loadedStyles = false;
685
+ },
686
+ buildEnd(error) {
687
+ if (error && loadedStyles && isStylePipelineError(error)) this.warn(CSS_PIPELINE_HINT);
688
+ }
689
+ };
658
690
  return {
659
691
  name: "unplugin-vize",
660
692
  resolveId(id) {
@@ -668,6 +700,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
668
700
  async load(id) {
669
701
  if (options.hostCompiler) return null;
670
702
  if (!isVueStyleRequest(id)) return null;
703
+ loadedStyles = true;
671
704
  return {
672
705
  code: await loadStyleBlock(this, id, options, cache),
673
706
  map: null
@@ -698,6 +731,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
698
731
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
699
732
  isProduction: options.isProduction,
700
733
  isDev: false,
734
+ hostCss: hostCss(this, meta.framework),
701
735
  filePath: id,
702
736
  styleRequest: webpackStyleFiles ? (block, scoped) => {
703
737
  const stylePath = webpackStylePath(id, block, scoped);
@@ -714,6 +748,8 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
714
748
  watchChange(id) {
715
749
  if (isVueFile(id)) cache.delete(id);
716
750
  },
751
+ rollup: rollupHooks,
752
+ rolldown: rollupHooks,
717
753
  webpack(compiler) {
718
754
  if (!options.hostCompiler) {
719
755
  virtualModules = findVirtualModules(compiler);
@@ -1,4 +1,4 @@
1
- const require_webpack_styles = require("./webpack-styles-IFEnxDay.cjs");
1
+ const require_webpack_styles = require("./webpack-styles-DVh6lFXt.cjs");
2
2
  let node_fs = require("node:fs");
3
3
  node_fs = require_webpack_styles.__toESM(node_fs, 1);
4
4
  let node_module = require("node:module");
@@ -113,12 +113,13 @@ function isVueStyleRequest(id) {
113
113
  *
114
114
  * CSS pipelines classify a module by the extension that ends the id, and treat
115
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.
116
+ * the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
117
+ * block arrives compiled when it is scoped (scoping follows preprocessing) or
118
+ * when the host compiles no preprocessor language.
118
119
  */
119
- function styleRequestId(filePath, block, scoped) {
120
+ function styleRequestId(filePath, block, scoped, hostCss) {
120
121
  const lang = block.lang ?? "css";
121
- const delivered = scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
122
+ const delivered = (scoped !== null || hostCss !== "preprocessors") && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
122
123
  let query = `vue&type=style&index=${block.index}`;
123
124
  if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
124
125
  if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
@@ -130,18 +131,37 @@ function parseVueRequest(id) {
130
131
  const params = new URLSearchParams(rawQuery);
131
132
  const moduleValue = params.has("module") ? params.get("module") || true : false;
132
133
  const indexValue = params.get("index");
134
+ const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
133
135
  return {
134
136
  filename,
135
137
  query: {
136
138
  vue: params.has("vue"),
137
139
  type: params.get("type"),
138
140
  index: indexValue === null ? null : Number.parseInt(indexValue, 10),
141
+ lang: langKey?.replace(/^lang\.(?:module\.)?/, "") ?? null,
139
142
  module: moduleValue,
140
143
  scoped: params.get("scoped")
141
144
  }
142
145
  };
143
146
  }
144
147
  //#endregion
148
+ //#region src/style-dependencies.ts
149
+ function hasImportRule(ast) {
150
+ if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
151
+ return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
152
+ }
153
+ /** `src` blocks are inlined before compilation; one left here was unreadable. */
154
+ function assertInlinedStyleSrc(styles, filename) {
155
+ 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.`);
156
+ }
157
+ /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
158
+ function assertInjectableCss(styles, filename) {
159
+ for (const style of styles) {
160
+ if (!style.content.includes("@")) continue;
161
+ 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.`);
162
+ }
163
+ }
164
+ //#endregion
145
165
  //#region src/style.ts
146
166
  function needsPreprocessor(block) {
147
167
  return require_webpack_styles.isPreprocessorLang(block.lang);
@@ -149,6 +169,7 @@ function needsPreprocessor(block) {
149
169
  function isCssModule(block) {
150
170
  return block.module !== false;
151
171
  }
172
+ /** Blocks only a host CSS pipeline can serve. */
152
173
  function hasDelegatedStyles(compiled) {
153
174
  return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
154
175
  }
@@ -194,7 +215,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
194
215
  ? ns.default
195
216
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
196
217
  function generateOutput(compiled, options) {
197
- const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
218
+ const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
198
219
  let output = compiled.code;
199
220
  const exportDefaultRegex = /^export default /m;
200
221
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -211,13 +232,13 @@ function generateOutput(compiled, options) {
211
232
  output += "\n_sfc_main.render = render;";
212
233
  output += "\nexport default _sfc_main;";
213
234
  }
214
- if (hasDelegatedStyles(compiled) && filePath) {
235
+ if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
215
236
  const styleImports = [];
216
237
  const cssModuleImports = [];
217
238
  for (const block of compiled.styles) {
218
239
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
219
240
  const styleFile = styleRequest?.(block, scoped);
220
- const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
241
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
221
242
  if (isCssModule(block)) {
222
243
  const bindingName = typeof block.module === "string" ? block.module : "$style";
223
244
  if (styleFile) {
@@ -236,7 +257,10 @@ function generateOutput(compiled, options) {
236
257
  }).join("\n");
237
258
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
238
259
  }
239
- } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
260
+ } else if (compiled.css) {
261
+ assertInjectableCss(compiled.styles, filePath);
262
+ output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
263
+ }
240
264
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
241
265
  return output;
242
266
  }
@@ -251,20 +275,6 @@ function toStyleBlockInfo(block) {
251
275
  };
252
276
  }
253
277
  //#endregion
254
- //#region src/style-dependencies.ts
255
- function hasImportRule(ast) {
256
- if (typeof ast !== "object" || ast === null || !("rules" in ast)) return false;
257
- return Array.isArray(ast.rules) && ast.rules.some((rule) => typeof rule === "object" && rule !== null && "type" in rule && rule.type === "import");
258
- }
259
- /** The inline runtime style path cannot resolve external CSS dependencies. */
260
- function assertSupportedStyleDependencies(styles, filename) {
261
- for (const style of styles) {
262
- 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.`);
263
- if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
264
- 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.`);
265
- }
266
- }
267
- //#endregion
268
278
  //#region ../shared/sfc-src.ts
269
279
  /**
270
280
  * Whether a block `src` is a path relative to the SFC. Any other `src`
@@ -458,7 +468,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
458
468
  inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
459
469
  });
460
470
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
461
- assertSupportedStyleDependencies(result.styles, filePath);
471
+ assertInlinedStyleSrc(result.styles, filePath);
462
472
  const compiled = {
463
473
  code: result.code,
464
474
  css: result.css,
@@ -613,9 +623,22 @@ async function loadStyleBlock(context, id, options, cache) {
613
623
  const block = compiled?.styles[index];
614
624
  if (!compiled || !block) return "";
615
625
  const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
626
+ const css = block.lang && require_webpack_styles.isPreprocessorLang(block.lang) && request.query.lang === "css" ? await require_webpack_styles.preprocessStyle(source, block.lang, request.filename, options.root) : source;
616
627
  const scoped = request.query.scoped;
617
- if (!scoped) return source;
618
- 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);
628
+ return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
629
+ }
630
+ /**
631
+ * What the host does with an imported stylesheet. esbuild without `bundle`
632
+ * never follows an import, and its CSS loaders compile no preprocessor.
633
+ */
634
+ function hostCss(context, framework) {
635
+ if (framework !== "esbuild") return "preprocessors";
636
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
637
+ }
638
+ 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.";
639
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
640
+ function isStylePipelineError(error) {
641
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
619
642
  }
620
643
  /** The bundler's own module resolver, or null for a host that offers none. */
621
644
  function hostResolver(context) {
@@ -657,6 +680,15 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
657
680
  const cache = /* @__PURE__ */ new Map();
658
681
  const webpackStyleFiles = meta.framework === "webpack";
659
682
  let virtualModules;
683
+ let loadedStyles = false;
684
+ const rollupHooks = {
685
+ buildStart() {
686
+ loadedStyles = false;
687
+ },
688
+ buildEnd(error) {
689
+ if (error && loadedStyles && isStylePipelineError(error)) this.warn(CSS_PIPELINE_HINT);
690
+ }
691
+ };
660
692
  return {
661
693
  name: "unplugin-vize",
662
694
  resolveId(id) {
@@ -670,6 +702,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
670
702
  async load(id) {
671
703
  if (options.hostCompiler) return null;
672
704
  if (!isVueStyleRequest(id)) return null;
705
+ loadedStyles = true;
673
706
  return {
674
707
  code: await loadStyleBlock(this, id, options, cache),
675
708
  map: null
@@ -700,6 +733,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
700
733
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
701
734
  isProduction: options.isProduction,
702
735
  isDev: false,
736
+ hostCss: hostCss(this, meta.framework),
703
737
  filePath: id,
704
738
  styleRequest: webpackStyleFiles ? (block, scoped) => {
705
739
  const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
@@ -716,6 +750,8 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
716
750
  watchChange(id) {
717
751
  if (isVueFile(id)) cache.delete(id);
718
752
  },
753
+ rollup: rollupHooks,
754
+ rolldown: rollupHooks,
719
755
  webpack(compiler) {
720
756
  if (!options.hostCompiler) {
721
757
  virtualModules = require_webpack_styles.findVirtualModules(compiler);
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_webpack_styles = require("./webpack-styles-IFEnxDay.cjs");
5
+ const require_webpack_styles = require("./webpack-styles-DVh6lFXt.cjs");
6
6
  //#region src/webpack-style-loader.ts
7
7
  const SCOPE_QUERY = "?scope";
8
8
  const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
@@ -1,4 +1,4 @@
1
- import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-Ca7spvMb.mjs";
1
+ import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-CoRj2un6.mjs";
2
2
  //#region src/webpack-style-loader.ts
3
3
  const SCOPE_QUERY = "?scope";
4
4
  const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
@@ -32,7 +32,7 @@ function loadPreprocessor(root, names, lang) {
32
32
  } catch (error) {
33
33
  if (error.code !== "MODULE_NOT_FOUND") throw error;
34
34
  }
35
- throw new Error(`[vize] <style scoped lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
35
+ throw new Error(`[vize] <style lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
36
36
  }
37
37
  async function preprocessStyle(source, lang, filename, root) {
38
38
  const dir = path.dirname(filename);
@@ -55,7 +55,7 @@ function loadPreprocessor(root, names, lang) {
55
55
  } catch (error) {
56
56
  if (error.code !== "MODULE_NOT_FOUND") throw error;
57
57
  }
58
- throw new Error(`[vize] <style scoped lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
58
+ throw new Error(`[vize] <style lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
59
59
  }
60
60
  async function preprocessStyle(source, lang, filename, root) {
61
61
  const dir = node_path.default.dirname(filename);
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-Dl8hs9VI.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-COZmphjF.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-BbWP410q.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BVGBB7oG.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.662.0",
3
+ "version": "0.664.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.662.0",
71
+ "@vizejs/native": "0.664.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },