@vizejs/unplugin 0.663.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
@@ -119,6 +119,6 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
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
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
- - 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`.
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-7UpIpoaj.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,7 +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
+ hostCss: "none",
22
22
  filePath: filename
23
23
  }), {
24
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-hYMgbR_K.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,7 +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
+ hostCss: "none",
22
22
  filePath: filename
23
23
  }), {
24
24
  ...parserOptions,
package/dist/esbuild.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/esbuild.ts
2
- var esbuild_default = require("./unplugin-7UpIpoaj.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-hYMgbR_K.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-7UpIpoaj.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-hYMgbR_K.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-7UpIpoaj.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-hYMgbR_K.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-7UpIpoaj.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-hYMgbR_K.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,12 +129,14 @@ 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
  }
@@ -210,7 +213,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
210
213
  ? ns.default
211
214
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
212
215
  function generateOutput(compiled, options) {
213
- const { isProduction, isDev, cssPipeline, filePath, styleRequest } = options;
216
+ const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
214
217
  let output = compiled.code;
215
218
  const exportDefaultRegex = /^export default /m;
216
219
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -227,13 +230,13 @@ function generateOutput(compiled, options) {
227
230
  output += "\n_sfc_main.render = render;";
228
231
  output += "\nexport default _sfc_main;";
229
232
  }
230
- if (cssPipeline || hasDelegatedStyles(compiled)) {
233
+ if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
231
234
  const styleImports = [];
232
235
  const cssModuleImports = [];
233
236
  for (const block of compiled.styles) {
234
237
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
235
238
  const styleFile = styleRequest?.(block, scoped);
236
- const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
239
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
237
240
  if (isCssModule(block)) {
238
241
  const bindingName = typeof block.module === "string" ? block.module : "$style";
239
242
  if (styleFile) {
@@ -618,17 +621,17 @@ async function loadStyleBlock(context, id, options, cache) {
618
621
  const block = compiled?.styles[index];
619
622
  if (!compiled || !block) return "";
620
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;
621
625
  const scoped = request.query.scoped;
622
- if (!scoped) return source;
623
- 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;
624
627
  }
625
628
  /**
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.
629
+ * What the host does with an imported stylesheet. esbuild without `bundle`
630
+ * never follows an import, and its CSS loaders compile no preprocessor.
628
631
  */
629
- function bundlesStylesheets(context, framework) {
630
- if (framework !== "esbuild") return true;
631
- return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
632
+ function hostCss(context, framework) {
633
+ if (framework !== "esbuild") return "preprocessors";
634
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
632
635
  }
633
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.";
634
637
  /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
@@ -728,7 +731,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
728
731
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
729
732
  isProduction: options.isProduction,
730
733
  isDev: false,
731
- cssPipeline: bundlesStylesheets(this, meta.framework),
734
+ hostCss: hostCss(this, meta.framework),
732
735
  filePath: id,
733
736
  styleRequest: webpackStyleFiles ? (block, scoped) => {
734
737
  const stylePath = webpackStylePath(id, block, scoped);
@@ -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,12 +131,14 @@ 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
  }
@@ -212,7 +215,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
212
215
  ? ns.default
213
216
  : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
214
217
  function generateOutput(compiled, options) {
215
- const { isProduction, isDev, cssPipeline, filePath, styleRequest } = options;
218
+ const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
216
219
  let output = compiled.code;
217
220
  const exportDefaultRegex = /^export default /m;
218
221
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -229,13 +232,13 @@ function generateOutput(compiled, options) {
229
232
  output += "\n_sfc_main.render = render;";
230
233
  output += "\nexport default _sfc_main;";
231
234
  }
232
- if (cssPipeline || hasDelegatedStyles(compiled)) {
235
+ if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
233
236
  const styleImports = [];
234
237
  const cssModuleImports = [];
235
238
  for (const block of compiled.styles) {
236
239
  const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
237
240
  const styleFile = styleRequest?.(block, scoped);
238
- const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
241
+ const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
239
242
  if (isCssModule(block)) {
240
243
  const bindingName = typeof block.module === "string" ? block.module : "$style";
241
244
  if (styleFile) {
@@ -620,17 +623,17 @@ async function loadStyleBlock(context, id, options, cache) {
620
623
  const block = compiled?.styles[index];
621
624
  if (!compiled || !block) return "";
622
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;
623
627
  const scoped = request.query.scoped;
624
- if (!scoped) return source;
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);
628
+ return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
626
629
  }
627
630
  /**
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.
631
+ * What the host does with an imported stylesheet. esbuild without `bundle`
632
+ * never follows an import, and its CSS loaders compile no preprocessor.
630
633
  */
631
- function bundlesStylesheets(context, framework) {
632
- if (framework !== "esbuild") return true;
633
- return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
634
+ function hostCss(context, framework) {
635
+ if (framework !== "esbuild") return "preprocessors";
636
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
634
637
  }
635
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.";
636
639
  /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
@@ -730,7 +733,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
730
733
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
731
734
  isProduction: options.isProduction,
732
735
  isDev: false,
733
- cssPipeline: bundlesStylesheets(this, meta.framework),
736
+ hostCss: hostCss(this, meta.framework),
734
737
  filePath: id,
735
738
  styleRequest: webpackStyleFiles ? (block, scoped) => {
736
739
  const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
@@ -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-7UpIpoaj.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-hYMgbR_K.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.663.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.663.0",
71
+ "@vizejs/native": "0.664.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },