@vizejs/unplugin 0.670.0 → 0.672.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
@@ -116,7 +116,7 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
116
116
 
117
117
  - Vite is still the recommended integration if you need the most complete behavior today.
118
118
  - Every `<style>` block, including a `<style scoped>` in a `.jsx` or `.tsx` component, 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
- - `<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 module the bundler keeps external (tsdown keeps `dependencies` external) stays an import, as in `@vitejs/plugin-vue`: `<style src>` becomes `import "…"` and `<script src>` imports the component from it. `<template src>`, `<script setup src>` and a scoped or module `<style src>` are compiled into the component, so an external one is a build error; let the bundler bundle it. A request that resolves to nothing is a build error.
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 `<style src>` block's stylesheet module sits beside its file, so its relative `@import`, `@use` and `url()` resolve from there, as when the file is imported directly. A module the bundler keeps external (tsdown keeps `dependencies` external) stays an import, as in `@vitejs/plugin-vue`: `<style src>` becomes `import "…"` and `<script src>` imports the component from it. `<template src>`, `<script setup src>` and a scoped or module `<style src>` are compiled into the component, so an external one is a build error; let the bundler bundle it. A request that resolves to nothing is a build error.
120
120
  - Babel and esbuild without `bundle` bundle no stylesheet, so there the compiled CSS is injected into JavaScript at run time, CSS Modules included. A preprocessor block or an `@import` is a build error there, since nothing compiles or resolves it.
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`. 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.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-BN6kq7_c.cjs");
1
+ const require_unplugin = require("./unplugin-C2D-Vdy1.cjs");
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = require_unplugin.normalizeOptions(rawOptions);
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-DNfg1NFI.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BjxDYvYs.mjs";
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = normalizeOptions(rawOptions);
package/dist/esbuild.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/esbuild.ts
2
- var esbuild_default = require("./unplugin-BN6kq7_c.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-C2D-Vdy1.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-DNfg1NFI.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BjxDYvYs.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-BN6kq7_c.cjs");
5
+ const require_unplugin = require("./unplugin-C2D-Vdy1.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-DNfg1NFI.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BjxDYvYs.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-BN6kq7_c.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-C2D-Vdy1.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-DNfg1NFI.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BjxDYvYs.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-BN6kq7_c.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-C2D-Vdy1.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-DNfg1NFI.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BjxDYvYs.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-qKeVgHc7.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-CJFdgoZm.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { createUnplugin } from "unplugin";
4
4
  import { createHash } from "node:crypto";
@@ -114,19 +114,31 @@ function isVueStyleRequest(id) {
114
114
  * the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
115
115
  * block arrives compiled when it is scoped (scoping follows preprocessing) or
116
116
  * when the host compiles no preprocessor language.
117
+ *
118
+ * A `<style src>` block's module sits beside its src file, as
119
+ * `styles/a.css.__vize_style_0?vue&type=style&index=0&owner=<SFC>&lang.css`,
120
+ * so every host resolves the file's relative `@import`, `@use` and `url()`
121
+ * from its own directory. The path names no real file and no SFC; `owner`
122
+ * names the SFC that holds the block.
117
123
  */
118
124
  function styleRequestId(filePath, block, scoped, hostCss) {
119
125
  const lang = block.lang ?? "css";
120
126
  const delivered = (scoped !== null || hostCss !== "preprocessors") && isPreprocessorLang(lang) ? "css" : lang;
121
127
  let query = `vue&type=style&index=${block.index}`;
128
+ if (block.srcFile) query += `&owner=${encodeURIComponent(filePath)}`;
122
129
  if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
123
130
  if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
124
131
  const ext = block.module === false ? delivered : `module.${delivered}`;
125
- return `${filePath}?${query}&lang.${ext}`;
132
+ return `${block.srcFile ? styleSrcModulePath(block.srcFile, block.index) : filePath}?${query}&lang.${ext}`;
133
+ }
134
+ /** Where a `<style src>` block's module sits: beside the src file, under no real name. */
135
+ function styleSrcModulePath(src, index) {
136
+ return `${src}.__vize_style_${index}`;
126
137
  }
127
138
  function parseVueRequest(id) {
128
- const [filename, rawQuery = ""] = id.split("?", 2);
139
+ const [path, rawQuery = ""] = id.split("?", 2);
129
140
  const params = new URLSearchParams(rawQuery);
141
+ const filename = params.get("owner") ?? path;
130
142
  const moduleValue = params.has("module") ? params.get("module") || true : false;
131
143
  const indexValue = params.get("index");
132
144
  const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
@@ -495,7 +507,7 @@ function buildSourceHash(source) {
495
507
  return createHash("sha256").update(source).digest("hex");
496
508
  }
497
509
  function compileVueModule(filePath, source, options, cache, srcResolutions) {
498
- const { source: inlined, dependencies, imports } = inlineSfcSrcBlocks(native.parseSfc, filePath, source, srcResolutions);
510
+ const { source: inlined, dependencies, imports, styleSrcs } = inlineSfcSrcBlocks(native.parseSfc, filePath, source, srcResolutions);
499
511
  const sourceHash = buildSourceHash(inlined);
500
512
  const signature = buildSignature(options);
501
513
  const cached = cache.get(filePath);
@@ -537,7 +549,10 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
537
549
  styleHash: result.styleHash,
538
550
  scriptHash: result.scriptHash,
539
551
  macroArtifacts: result.macroArtifacts ?? [],
540
- styles: result.styles.map(toStyleBlockInfo)
552
+ styles: result.styles.map((style) => ({
553
+ ...toStyleBlockInfo(style),
554
+ srcFile: styleSrcs.get(style.index) ?? null
555
+ }))
541
556
  };
542
557
  cache.set(filePath, {
543
558
  compiled,
@@ -647,8 +662,9 @@ async function loadStyleBlock(context, id, options, cache, jsxStyles) {
647
662
  }
648
663
  const block = compiled?.styles[index];
649
664
  if (!compiled || !block) return "";
665
+ if (block.srcFile) context.addWatchFile?.(block.srcFile);
650
666
  const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
651
- const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
667
+ const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, block.srcFile ?? request.filename, options.root) : source;
652
668
  const scoped = request.query.scoped;
653
669
  return scoped ? scopeCss(css, scoped) : css;
654
670
  }
@@ -842,8 +858,8 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
842
858
  }
843
859
  },
844
860
  esbuild: {
845
- onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
846
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
861
+ onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\?/,
862
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\?/,
847
863
  loader(_code, id) {
848
864
  const request = parseVueRequest(id);
849
865
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -1,4 +1,4 @@
1
- const require_webpack_styles = require("./webpack-styles-B4946o00.cjs");
1
+ const require_webpack_styles = require("./webpack-styles-CmdUBM2f.cjs");
2
2
  let node_module = require("node:module");
3
3
  let unplugin = require("unplugin");
4
4
  let node_crypto = require("node:crypto");
@@ -116,19 +116,31 @@ function isVueStyleRequest(id) {
116
116
  * the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
117
117
  * block arrives compiled when it is scoped (scoping follows preprocessing) or
118
118
  * when the host compiles no preprocessor language.
119
+ *
120
+ * A `<style src>` block's module sits beside its src file, as
121
+ * `styles/a.css.__vize_style_0?vue&type=style&index=0&owner=<SFC>&lang.css`,
122
+ * so every host resolves the file's relative `@import`, `@use` and `url()`
123
+ * from its own directory. The path names no real file and no SFC; `owner`
124
+ * names the SFC that holds the block.
119
125
  */
120
126
  function styleRequestId(filePath, block, scoped, hostCss) {
121
127
  const lang = block.lang ?? "css";
122
128
  const delivered = (scoped !== null || hostCss !== "preprocessors") && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
123
129
  let query = `vue&type=style&index=${block.index}`;
130
+ if (block.srcFile) query += `&owner=${encodeURIComponent(filePath)}`;
124
131
  if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
125
132
  if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
126
133
  const ext = block.module === false ? delivered : `module.${delivered}`;
127
- return `${filePath}?${query}&lang.${ext}`;
134
+ return `${block.srcFile ? styleSrcModulePath(block.srcFile, block.index) : filePath}?${query}&lang.${ext}`;
135
+ }
136
+ /** Where a `<style src>` block's module sits: beside the src file, under no real name. */
137
+ function styleSrcModulePath(src, index) {
138
+ return `${src}.__vize_style_${index}`;
128
139
  }
129
140
  function parseVueRequest(id) {
130
- const [filename, rawQuery = ""] = id.split("?", 2);
141
+ const [path, rawQuery = ""] = id.split("?", 2);
131
142
  const params = new URLSearchParams(rawQuery);
143
+ const filename = params.get("owner") ?? path;
132
144
  const moduleValue = params.has("module") ? params.get("module") || true : false;
133
145
  const indexValue = params.get("index");
134
146
  const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
@@ -497,7 +509,7 @@ function buildSourceHash(source) {
497
509
  return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
498
510
  }
499
511
  function compileVueModule(filePath, source, options, cache, srcResolutions) {
500
- const { source: inlined, dependencies, imports } = inlineSfcSrcBlocks(_vizejs_native.parseSfc, filePath, source, srcResolutions);
512
+ const { source: inlined, dependencies, imports, styleSrcs } = inlineSfcSrcBlocks(_vizejs_native.parseSfc, filePath, source, srcResolutions);
501
513
  const sourceHash = buildSourceHash(inlined);
502
514
  const signature = buildSignature(options);
503
515
  const cached = cache.get(filePath);
@@ -539,7 +551,10 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
539
551
  styleHash: result.styleHash,
540
552
  scriptHash: result.scriptHash,
541
553
  macroArtifacts: result.macroArtifacts ?? [],
542
- styles: result.styles.map(toStyleBlockInfo)
554
+ styles: result.styles.map((style) => ({
555
+ ...toStyleBlockInfo(style),
556
+ srcFile: styleSrcs.get(style.index) ?? null
557
+ }))
543
558
  };
544
559
  cache.set(filePath, {
545
560
  compiled,
@@ -649,8 +664,9 @@ async function loadStyleBlock(context, id, options, cache, jsxStyles) {
649
664
  }
650
665
  const block = compiled?.styles[index];
651
666
  if (!compiled || !block) return "";
667
+ if (block.srcFile) context.addWatchFile?.(block.srcFile);
652
668
  const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
653
- 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;
669
+ const css = block.lang && require_webpack_styles.isPreprocessorLang(block.lang) && request.query.lang === "css" ? await require_webpack_styles.preprocessStyle(source, block.lang, block.srcFile ?? request.filename, options.root) : source;
654
670
  const scoped = request.query.scoped;
655
671
  return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
656
672
  }
@@ -844,8 +860,8 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
844
860
  }
845
861
  },
846
862
  esbuild: {
847
- onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
848
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
863
+ onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\?/,
864
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\?/,
849
865
  loader(_code, id) {
850
866
  const request = parseVueRequest(id);
851
867
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -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-B4946o00.cjs");
5
+ const require_webpack_styles = require("./webpack-styles-CmdUBM2f.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-qKeVgHc7.mjs";
1
+ import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-CJFdgoZm.mjs";
2
2
  //#region src/webpack-style-loader.ts
3
3
  const SCOPE_QUERY = "?scope";
4
4
  const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
@@ -53,7 +53,7 @@ const SCOPED_STYLE_FILE = /\.__vize_style_\d+\.(data-v-[0-9a-f]+)(?:\.module)?\.
53
53
  function webpackStylePath(filePath, block, scoped) {
54
54
  const scope = scoped ? `.${scoped}` : "";
55
55
  const module = block.module === false ? "" : ".module";
56
- return `${filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
56
+ return `${block.srcFile ?? filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
57
57
  }
58
58
  function webpackStyleRequest(stylePath, block) {
59
59
  if (block.module === false) return stylePath;
@@ -76,7 +76,7 @@ const SCOPED_STYLE_FILE = /\.__vize_style_\d+\.(data-v-[0-9a-f]+)(?:\.module)?\.
76
76
  function webpackStylePath(filePath, block, scoped) {
77
77
  const scope = scoped ? `.${scoped}` : "";
78
78
  const module = block.module === false ? "" : ".module";
79
- return `${filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
79
+ return `${block.srcFile ?? filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
80
80
  }
81
81
  function webpackStyleRequest(stylePath, block) {
82
82
  if (block.module === false) return stylePath;
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-BN6kq7_c.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-C2D-Vdy1.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-DNfg1NFI.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BjxDYvYs.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.670.0",
3
+ "version": "0.672.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.670.0",
71
+ "@vizejs/native": "0.672.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },