@vizejs/unplugin 0.443.0 → 0.457.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,5 +116,6 @@ 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
  - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
119
+ - 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`.
119
120
  - 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.
120
121
  - Test carefully before depending on this package in production.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-BZZSLylM.cjs");
1
+ const require_unplugin = require("./unplugin-BMwc3bUL.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-LGSCePN4.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BMBg2ffv.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-BZZSLylM.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-BMwc3bUL.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-LGSCePN4.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BMBg2ffv.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-BZZSLylM.cjs");
5
+ const require_unplugin = require("./unplugin-BMwc3bUL.cjs");
6
6
  exports.default = require_unplugin.vizeUnplugin;
7
7
  exports.vizeUnplugin = require_unplugin.vizeUnplugin;
package/dist/index.d.cts CHANGED
@@ -2,6 +2,7 @@ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOp
2
2
  import { Compiler } from "webpack";
3
3
 
4
4
  //#region src/unplugin.d.ts
5
- declare const vizeUnplugin: import("unplugin").UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
5
+ type VizeUnpluginInput = VizeUnpluginOptions | undefined;
6
+ declare const vizeUnplugin: import("unplugin").UnpluginInstance<VizeUnpluginInput, boolean>;
6
7
  //#endregion
7
8
  export { type MacroArtifact, type VizeCompatibilityOptions, type VizeUnpluginOptions, type VizeVueVersion, vizeUnplugin as default, vizeUnplugin };
package/dist/index.d.mts CHANGED
@@ -2,6 +2,7 @@ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOp
2
2
  import { Compiler } from "webpack";
3
3
 
4
4
  //#region src/unplugin.d.ts
5
- declare const vizeUnplugin: import("unplugin").UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
5
+ type VizeUnpluginInput = VizeUnpluginOptions | undefined;
6
+ declare const vizeUnplugin: import("unplugin").UnpluginInstance<VizeUnpluginInput, boolean>;
6
7
  //#endregion
7
8
  export { type MacroArtifact, type VizeCompatibilityOptions, type VizeUnpluginOptions, type VizeVueVersion, vizeUnplugin as default, vizeUnplugin };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-LGSCePN4.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BMBg2ffv.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-BZZSLylM.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-BMwc3bUL.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-LGSCePN4.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BMBg2ffv.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-BZZSLylM.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-BMwc3bUL.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-LGSCePN4.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BMBg2ffv.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -1,9 +1,10 @@
1
+ import { a as isPreprocessorLang, c as transformStyleVars, n as registerWebpackStyleRule, o as preprocessStyle, r as webpackStylePath, s as scopeCss, t as findVirtualModules } from "./webpack-styles-8kxctaA7.mjs";
1
2
  import { createRequire } from "node:module";
2
3
  import fs from "node:fs";
3
4
  import { createUnplugin } from "unplugin";
4
5
  import { createHash } from "node:crypto";
5
6
  import * as native from "@vizejs/native";
6
- import { generateSfcScopeId, wrapSfcScopedPreprocessorStyle } from "@vizejs/native";
7
+ import { generateSfcScopeId } from "@vizejs/native";
7
8
  import { transform } from "oxc-transform";
8
9
  //#region src/filter.ts
9
10
  function createFilter(include, exclude) {
@@ -92,15 +93,8 @@ function prependMappedJsxCode(code, mapJson, prefix) {
92
93
  }
93
94
  //#endregion
94
95
  //#region src/style.ts
95
- const PREPROCESSOR_LANGS = new Set([
96
- "scss",
97
- "sass",
98
- "less",
99
- "stylus",
100
- "styl"
101
- ]);
102
96
  function needsPreprocessor(block) {
103
- return block.lang !== null && PREPROCESSOR_LANGS.has(block.lang);
97
+ return isPreprocessorLang(block.lang);
104
98
  }
105
99
  function isCssModule(block) {
106
100
  return block.module !== false;
@@ -143,8 +137,14 @@ const __vize_css_id__ = ${JSON.stringify(`vize-style-${styleKey}`)};
143
137
  })();
144
138
  ${output}`;
145
139
  }
140
+ const CSS_MODULE_LOCALS = "__vize_css_module_locals__";
141
+ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
142
+ ns.default?.locals ??
143
+ (ns.default && typeof ns.default === "object" && !Array.isArray(ns.default)
144
+ ? ns.default
145
+ : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
146
146
  function generateOutput(compiled, options) {
147
- const { isProduction, isDev, extractCss, filePath } = options;
147
+ const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
148
148
  let output = compiled.code;
149
149
  const exportDefaultRegex = /^export default /m;
150
150
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -172,14 +172,22 @@ function generateOutput(compiled, options) {
172
172
  params.set("index", String(block.index));
173
173
  params.set("lang", lang);
174
174
  if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
175
- const importUrl = `${filePath}?${params.toString()}`;
175
+ const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
176
+ const styleFile = styleRequest?.(block, scoped);
176
177
  if (isCssModule(block)) {
177
178
  const bindingName = typeof block.module === "string" ? block.module : "$style";
178
- const moduleParams = new URLSearchParams(params);
179
- moduleParams.set("module", typeof block.module === "string" ? block.module : "");
180
- cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(`${filePath}?${moduleParams.toString()}`)};`);
181
- } else styleImports.push(`import ${JSON.stringify(importUrl)};`);
179
+ if (styleFile) {
180
+ const namespace = `__vize_css_module_${block.index}__`;
181
+ cssModuleImports.push(`import * as ${namespace} from ${JSON.stringify(styleFile)};`, `const ${bindingName} = ${CSS_MODULE_LOCALS}(${namespace});`);
182
+ } else {
183
+ const moduleParams = new URLSearchParams(params);
184
+ moduleParams.set("module", typeof block.module === "string" ? block.module : "");
185
+ const moduleUrl = `${filePath}?${moduleParams.toString()}`;
186
+ cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(moduleUrl)};`);
187
+ }
188
+ } else styleImports.push(`import ${JSON.stringify(styleFile ?? `${filePath}?${params.toString()}`)};`);
182
189
  }
190
+ if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
183
191
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
184
192
  if (allImports) output = `${allImports}\n${output}`;
185
193
  if (cssModuleImports.length > 0) {
@@ -193,9 +201,6 @@ function generateOutput(compiled, options) {
193
201
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
194
202
  return output;
195
203
  }
196
- function wrapScopedPreprocessorStyle(content, scoped, lang) {
197
- return wrapSfcScopedPreprocessorStyle(content, scoped, lang);
198
- }
199
204
  function toStyleBlockInfo(block) {
200
205
  return {
201
206
  content: block.content,
@@ -348,7 +353,8 @@ function createVirtualStyleId(id) {
348
353
  const { filename, query } = parseVueRequest(id);
349
354
  const index = query.index ?? 0;
350
355
  const lang = query.lang ?? "css";
351
- const suffix = query.module !== false ? `.module.${lang}` : `.${lang}`;
356
+ const fileLang = query.scoped && isPreprocessorLang(lang) ? "css" : lang;
357
+ const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
352
358
  const params = new URLSearchParams();
353
359
  params.set("vue", "");
354
360
  params.set("type", "style");
@@ -465,13 +471,18 @@ async function loadStyleBlock(id, options, cache) {
465
471
  compiled = compileVueModule(request.filename, source, options, cache).compiled;
466
472
  }
467
473
  const block = compiled?.styles[index];
468
- if (!block) return "";
469
- return wrapScopedPreprocessorStyle(block.content, request.query.scoped, block.lang);
474
+ if (!compiled || !block) return "";
475
+ const source = transformStyleVars(block.content, compiled.scopeId);
476
+ const scoped = request.query.scoped;
477
+ if (!scoped) return source;
478
+ return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
470
479
  }
471
- const vizeUnplugin = createUnplugin((rawOptions = {}) => {
480
+ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
472
481
  const options = normalizeOptions(rawOptions);
473
482
  const filter = createFilter(options.include, options.exclude);
474
483
  const cache = /* @__PURE__ */ new Map();
484
+ const webpackStyleFiles = meta.framework === "webpack";
485
+ let virtualModules;
475
486
  return {
476
487
  name: "unplugin-vize",
477
488
  resolveId(id) {
@@ -481,7 +492,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
481
492
  },
482
493
  loadInclude(id) {
483
494
  if (options.hostCompiler) return false;
484
- return isVirtualStyleId(id);
495
+ return !webpackStyleFiles && isVirtualStyleId(id);
485
496
  },
486
497
  async load(id) {
487
498
  if (options.hostCompiler) return null;
@@ -515,7 +526,13 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
515
526
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
516
527
  isProduction: options.isProduction,
517
528
  isDev: false,
518
- filePath: id
529
+ filePath: id,
530
+ styleRequest: webpackStyleFiles ? (block, scoped) => {
531
+ const stylePath = webpackStylePath(id, block, scoped);
532
+ if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
533
+ virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId));
534
+ return stylePath;
535
+ } : void 0
519
536
  }), options.sourceMap);
520
537
  return {
521
538
  code: transformed.code,
@@ -526,11 +543,15 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
526
543
  if (isVueFile(id)) cache.delete(id);
527
544
  },
528
545
  webpack(compiler) {
529
- if (!options.hostCompiler) injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
546
+ if (!options.hostCompiler) {
547
+ virtualModules = findVirtualModules(compiler);
548
+ registerWebpackStyleRule(compiler);
549
+ injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
550
+ }
530
551
  },
531
552
  esbuild: {
532
553
  onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
533
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
554
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\./,
534
555
  loader(_code, id) {
535
556
  const request = parseVueRequest(id);
536
557
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -1,32 +1,11 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
1
+ const require_webpack_styles = require("./webpack-styles-BeXQWFdv.cjs");
23
2
  let node_fs = require("node:fs");
24
- node_fs = __toESM(node_fs, 1);
3
+ node_fs = require_webpack_styles.__toESM(node_fs, 1);
25
4
  let node_module = require("node:module");
26
5
  let unplugin = require("unplugin");
27
6
  let node_crypto = require("node:crypto");
28
7
  let _vizejs_native = require("@vizejs/native");
29
- _vizejs_native = __toESM(_vizejs_native, 1);
8
+ _vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
30
9
  let oxc_transform = require("oxc-transform");
31
10
  //#region src/filter.ts
32
11
  function createFilter(include, exclude) {
@@ -115,15 +94,8 @@ function prependMappedJsxCode(code, mapJson, prefix) {
115
94
  }
116
95
  //#endregion
117
96
  //#region src/style.ts
118
- const PREPROCESSOR_LANGS = new Set([
119
- "scss",
120
- "sass",
121
- "less",
122
- "stylus",
123
- "styl"
124
- ]);
125
97
  function needsPreprocessor(block) {
126
- return block.lang !== null && PREPROCESSOR_LANGS.has(block.lang);
98
+ return require_webpack_styles.isPreprocessorLang(block.lang);
127
99
  }
128
100
  function isCssModule(block) {
129
101
  return block.module !== false;
@@ -166,8 +138,14 @@ const __vize_css_id__ = ${JSON.stringify(`vize-style-${styleKey}`)};
166
138
  })();
167
139
  ${output}`;
168
140
  }
141
+ const CSS_MODULE_LOCALS = "__vize_css_module_locals__";
142
+ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
143
+ ns.default?.locals ??
144
+ (ns.default && typeof ns.default === "object" && !Array.isArray(ns.default)
145
+ ? ns.default
146
+ : Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
169
147
  function generateOutput(compiled, options) {
170
- const { isProduction, isDev, extractCss, filePath } = options;
148
+ const { isProduction, isDev, extractCss, filePath, styleRequest } = options;
171
149
  let output = compiled.code;
172
150
  const exportDefaultRegex = /^export default /m;
173
151
  const hasExportDefault = exportDefaultRegex.test(output);
@@ -195,14 +173,22 @@ function generateOutput(compiled, options) {
195
173
  params.set("index", String(block.index));
196
174
  params.set("lang", lang);
197
175
  if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
198
- const importUrl = `${filePath}?${params.toString()}`;
176
+ const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
177
+ const styleFile = styleRequest?.(block, scoped);
199
178
  if (isCssModule(block)) {
200
179
  const bindingName = typeof block.module === "string" ? block.module : "$style";
201
- const moduleParams = new URLSearchParams(params);
202
- moduleParams.set("module", typeof block.module === "string" ? block.module : "");
203
- cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(`${filePath}?${moduleParams.toString()}`)};`);
204
- } else styleImports.push(`import ${JSON.stringify(importUrl)};`);
180
+ if (styleFile) {
181
+ const namespace = `__vize_css_module_${block.index}__`;
182
+ 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()}`)};`);
205
190
  }
191
+ if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
206
192
  const allImports = [...styleImports, ...cssModuleImports].join("\n");
207
193
  if (allImports) output = `${allImports}\n${output}`;
208
194
  if (cssModuleImports.length > 0) {
@@ -216,9 +202,6 @@ function generateOutput(compiled, options) {
216
202
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
217
203
  return output;
218
204
  }
219
- function wrapScopedPreprocessorStyle(content, scoped, lang) {
220
- return (0, _vizejs_native.wrapSfcScopedPreprocessorStyle)(content, scoped, lang);
221
- }
222
205
  function toStyleBlockInfo(block) {
223
206
  return {
224
207
  content: block.content,
@@ -371,7 +354,8 @@ function createVirtualStyleId(id) {
371
354
  const { filename, query } = parseVueRequest(id);
372
355
  const index = query.index ?? 0;
373
356
  const lang = query.lang ?? "css";
374
- const suffix = query.module !== false ? `.module.${lang}` : `.${lang}`;
357
+ const fileLang = query.scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
358
+ const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
375
359
  const params = new URLSearchParams();
376
360
  params.set("vue", "");
377
361
  params.set("type", "style");
@@ -488,13 +472,18 @@ async function loadStyleBlock(id, options, cache) {
488
472
  compiled = compileVueModule(request.filename, source, options, cache).compiled;
489
473
  }
490
474
  const block = compiled?.styles[index];
491
- if (!block) return "";
492
- return wrapScopedPreprocessorStyle(block.content, request.query.scoped, block.lang);
475
+ if (!compiled || !block) return "";
476
+ const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId);
477
+ const scoped = request.query.scoped;
478
+ if (!scoped) return source;
479
+ 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);
493
480
  }
494
- const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}) => {
481
+ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
495
482
  const options = normalizeOptions(rawOptions);
496
483
  const filter = createFilter(options.include, options.exclude);
497
484
  const cache = /* @__PURE__ */ new Map();
485
+ const webpackStyleFiles = meta.framework === "webpack";
486
+ let virtualModules;
498
487
  return {
499
488
  name: "unplugin-vize",
500
489
  resolveId(id) {
@@ -504,7 +493,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}) => {
504
493
  },
505
494
  loadInclude(id) {
506
495
  if (options.hostCompiler) return false;
507
- return isVirtualStyleId(id);
496
+ return !webpackStyleFiles && isVirtualStyleId(id);
508
497
  },
509
498
  async load(id) {
510
499
  if (options.hostCompiler) return null;
@@ -538,7 +527,13 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}) => {
538
527
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
539
528
  isProduction: options.isProduction,
540
529
  isDev: false,
541
- filePath: id
530
+ filePath: id,
531
+ styleRequest: webpackStyleFiles ? (block, scoped) => {
532
+ const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
533
+ if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
534
+ virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId));
535
+ return stylePath;
536
+ } : void 0
542
537
  }), options.sourceMap);
543
538
  return {
544
539
  code: transformed.code,
@@ -549,11 +544,15 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}) => {
549
544
  if (isVueFile(id)) cache.delete(id);
550
545
  },
551
546
  webpack(compiler) {
552
- if (!options.hostCompiler) injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
547
+ if (!options.hostCompiler) {
548
+ virtualModules = require_webpack_styles.findVirtualModules(compiler);
549
+ require_webpack_styles.registerWebpackStyleRule(compiler);
550
+ injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
551
+ }
553
552
  },
554
553
  esbuild: {
555
554
  onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
556
- onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
555
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)|\.__vize_style_\d+\./,
557
556
  loader(_code, id) {
558
557
  const request = parseVueRequest(id);
559
558
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -0,0 +1,27 @@
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
5
+ const require_webpack_styles = require("./webpack-styles-BeXQWFdv.cjs");
6
+ //#region src/webpack-style-loader.ts
7
+ const SCOPE_QUERY = "?scope";
8
+ const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
9
+ function pitch() {
10
+ if (this.query === SCOPE_QUERY) return;
11
+ const self = this.loaders[this.loaderIndex];
12
+ const rest = this.loaders.filter((_, index) => index !== this.loaderIndex);
13
+ const cssLoaderIndex = rest.findIndex((loader) => CSS_LOADER.test(loader.path));
14
+ if (!self || cssLoaderIndex < 0) return;
15
+ const requests = rest.map((loader) => loader.request);
16
+ requests.splice(cssLoaderIndex + 1, 0, `${self.path}${SCOPE_QUERY}`);
17
+ const request = `!!${requests.join("!")}!${this.resource}`;
18
+ const specifier = JSON.stringify(this.utils?.contextify(this.context, request) ?? request);
19
+ return /\.module\.\w+$/.test(this.resourcePath) ? `export { default } from ${specifier};\nexport * from ${specifier};` : `export * from ${specifier};`;
20
+ }
21
+ function vizeStyleLoader(source) {
22
+ const scoped = require_webpack_styles.webpackStyleScope(this.resourcePath);
23
+ return scoped ? require_webpack_styles.scopeCss(source, scoped) : source;
24
+ }
25
+ //#endregion
26
+ exports.default = vizeStyleLoader;
27
+ exports.pitch = pitch;
@@ -0,0 +1,20 @@
1
+ //#region src/webpack-style-loader.d.ts
2
+ interface LoaderEntry {
3
+ path: string;
4
+ request: string;
5
+ }
6
+ interface StyleLoaderContext {
7
+ loaders: LoaderEntry[];
8
+ loaderIndex: number;
9
+ query: string | Record<string, unknown>;
10
+ resource: string;
11
+ resourcePath: string;
12
+ context: string;
13
+ utils?: {
14
+ contextify(context: string, request: string): string;
15
+ };
16
+ }
17
+ declare function pitch(this: StyleLoaderContext): string | undefined;
18
+ declare function vizeStyleLoader(this: StyleLoaderContext, source: string): string;
19
+ //#endregion
20
+ export { vizeStyleLoader as default, pitch };
@@ -0,0 +1,20 @@
1
+ //#region src/webpack-style-loader.d.ts
2
+ interface LoaderEntry {
3
+ path: string;
4
+ request: string;
5
+ }
6
+ interface StyleLoaderContext {
7
+ loaders: LoaderEntry[];
8
+ loaderIndex: number;
9
+ query: string | Record<string, unknown>;
10
+ resource: string;
11
+ resourcePath: string;
12
+ context: string;
13
+ utils?: {
14
+ contextify(context: string, request: string): string;
15
+ };
16
+ }
17
+ declare function pitch(this: StyleLoaderContext): string | undefined;
18
+ declare function vizeStyleLoader(this: StyleLoaderContext, source: string): string;
19
+ //#endregion
20
+ export { vizeStyleLoader as default, pitch };
@@ -0,0 +1,22 @@
1
+ import { i as webpackStyleScope, s as scopeCss } from "./webpack-styles-8kxctaA7.mjs";
2
+ //#region src/webpack-style-loader.ts
3
+ const SCOPE_QUERY = "?scope";
4
+ const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
5
+ function pitch() {
6
+ if (this.query === SCOPE_QUERY) return;
7
+ const self = this.loaders[this.loaderIndex];
8
+ const rest = this.loaders.filter((_, index) => index !== this.loaderIndex);
9
+ const cssLoaderIndex = rest.findIndex((loader) => CSS_LOADER.test(loader.path));
10
+ if (!self || cssLoaderIndex < 0) return;
11
+ const requests = rest.map((loader) => loader.request);
12
+ requests.splice(cssLoaderIndex + 1, 0, `${self.path}${SCOPE_QUERY}`);
13
+ const request = `!!${requests.join("!")}!${this.resource}`;
14
+ const specifier = JSON.stringify(this.utils?.contextify(this.context, request) ?? request);
15
+ return /\.module\.\w+$/.test(this.resourcePath) ? `export { default } from ${specifier};\nexport * from ${specifier};` : `export * from ${specifier};`;
16
+ }
17
+ function vizeStyleLoader(source) {
18
+ const scoped = webpackStyleScope(this.resourcePath);
19
+ return scoped ? scopeCss(source, scoped) : source;
20
+ }
21
+ //#endregion
22
+ export { vizeStyleLoader as default, pitch };
@@ -0,0 +1,72 @@
1
+ import { createRequire } from "node:module";
2
+ import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ //#region src/style-scope.ts
6
+ const PREPROCESSOR_LANGS = new Set([
7
+ "scss",
8
+ "sass",
9
+ "less",
10
+ "stylus",
11
+ "styl"
12
+ ]);
13
+ function isPreprocessorLang(lang) {
14
+ return lang != null && PREPROCESSOR_LANGS.has(lang);
15
+ }
16
+ function scopeCss(css, scoped) {
17
+ return scopeViteCssForPipeline(css, scoped);
18
+ }
19
+ /**
20
+ * `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
21
+ * The plugin compiles without `isProd`, so both sides use the dev names.
22
+ */
23
+ function transformStyleVars(css, scopeId) {
24
+ return transformViteCssVarsForPipeline(css, scopeId);
25
+ }
26
+ function loadPreprocessor(root, names, lang) {
27
+ const requireFromRoot = createRequire(path.join(root, "package.json"));
28
+ for (const name of names) try {
29
+ const loaded = requireFromRoot(name);
30
+ return loaded.default ?? loaded;
31
+ } catch (error) {
32
+ if (error.code !== "MODULE_NOT_FOUND") throw error;
33
+ }
34
+ throw new Error(`[vize] <style scoped lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
35
+ }
36
+ async function preprocessStyle(source, lang, filename, root) {
37
+ const dir = path.dirname(filename);
38
+ if (lang === "scss" || lang === "sass") return loadPreprocessor(root, ["sass", "sass-embedded"], lang).compileString(source, {
39
+ syntax: lang === "sass" ? "indented" : "scss",
40
+ url: pathToFileURL(filename),
41
+ loadPaths: [dir, root]
42
+ }).css;
43
+ if (lang === "less") return (await loadPreprocessor(root, ["less"], lang).render(source, {
44
+ filename,
45
+ paths: [dir, root]
46
+ })).css;
47
+ return loadPreprocessor(root, ["stylus"], lang)(source).set("filename", filename).include(dir).render();
48
+ }
49
+ //#endregion
50
+ //#region src/webpack-styles.ts
51
+ const SCOPED_STYLE_FILE = /\.__vize_style_\d+\.(data-v-[0-9a-f]+)(?:\.module)?\.\w+$/;
52
+ function webpackStylePath(filePath, block, scoped) {
53
+ const scope = scoped ? `.${scoped}` : "";
54
+ const module = block.module === false ? "" : ".module";
55
+ return `${filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
56
+ }
57
+ function webpackStyleScope(resourcePath) {
58
+ return SCOPED_STYLE_FILE.exec(resourcePath)?.[1] ?? null;
59
+ }
60
+ function findVirtualModules(compiler) {
61
+ return compiler.options.plugins.find((plugin) => typeof plugin?.writeModule === "function");
62
+ }
63
+ /** Scope styles after the host's preprocessor loader; see webpack-style-loader.ts. */
64
+ function registerWebpackStyleRule(compiler) {
65
+ const self = fileURLToPath(import.meta.url);
66
+ compiler.options.module?.rules?.unshift({
67
+ test: SCOPED_STYLE_FILE,
68
+ loader: path.join(path.dirname(self), `webpack-style-loader${path.extname(self)}`)
69
+ });
70
+ }
71
+ //#endregion
72
+ export { isPreprocessorLang as a, transformStyleVars as c, webpackStyleScope as i, registerWebpackStyleRule as n, preprocessStyle as o, webpackStylePath as r, scopeCss as s, findVirtualModules as t };
@@ -0,0 +1,148 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let node_module = require("node:module");
24
+ let _vizejs_native = require("@vizejs/native");
25
+ let node_path = require("node:path");
26
+ node_path = __toESM(node_path, 1);
27
+ let node_url = require("node:url");
28
+ //#region src/style-scope.ts
29
+ const PREPROCESSOR_LANGS = new Set([
30
+ "scss",
31
+ "sass",
32
+ "less",
33
+ "stylus",
34
+ "styl"
35
+ ]);
36
+ function isPreprocessorLang(lang) {
37
+ return lang != null && PREPROCESSOR_LANGS.has(lang);
38
+ }
39
+ function scopeCss(css, scoped) {
40
+ return (0, _vizejs_native.scopeViteCssForPipeline)(css, scoped);
41
+ }
42
+ /**
43
+ * `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
44
+ * The plugin compiles without `isProd`, so both sides use the dev names.
45
+ */
46
+ function transformStyleVars(css, scopeId) {
47
+ return (0, _vizejs_native.transformViteCssVarsForPipeline)(css, scopeId);
48
+ }
49
+ function loadPreprocessor(root, names, lang) {
50
+ const requireFromRoot = (0, node_module.createRequire)(node_path.default.join(root, "package.json"));
51
+ for (const name of names) try {
52
+ const loaded = requireFromRoot(name);
53
+ return loaded.default ?? loaded;
54
+ } catch (error) {
55
+ if (error.code !== "MODULE_NOT_FOUND") throw error;
56
+ }
57
+ throw new Error(`[vize] <style scoped lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
58
+ }
59
+ async function preprocessStyle(source, lang, filename, root) {
60
+ const dir = node_path.default.dirname(filename);
61
+ if (lang === "scss" || lang === "sass") return loadPreprocessor(root, ["sass", "sass-embedded"], lang).compileString(source, {
62
+ syntax: lang === "sass" ? "indented" : "scss",
63
+ url: (0, node_url.pathToFileURL)(filename),
64
+ loadPaths: [dir, root]
65
+ }).css;
66
+ if (lang === "less") return (await loadPreprocessor(root, ["less"], lang).render(source, {
67
+ filename,
68
+ paths: [dir, root]
69
+ })).css;
70
+ return loadPreprocessor(root, ["stylus"], lang)(source).set("filename", filename).include(dir).render();
71
+ }
72
+ //#endregion
73
+ //#region src/webpack-styles.ts
74
+ const SCOPED_STYLE_FILE = /\.__vize_style_\d+\.(data-v-[0-9a-f]+)(?:\.module)?\.\w+$/;
75
+ function webpackStylePath(filePath, block, scoped) {
76
+ const scope = scoped ? `.${scoped}` : "";
77
+ const module = block.module === false ? "" : ".module";
78
+ return `${filePath}.__vize_style_${block.index}${scope}${module}.${block.lang ?? "css"}`;
79
+ }
80
+ function webpackStyleScope(resourcePath) {
81
+ return SCOPED_STYLE_FILE.exec(resourcePath)?.[1] ?? null;
82
+ }
83
+ function findVirtualModules(compiler) {
84
+ return compiler.options.plugins.find((plugin) => typeof plugin?.writeModule === "function");
85
+ }
86
+ /** Scope styles after the host's preprocessor loader; see webpack-style-loader.ts. */
87
+ function registerWebpackStyleRule(compiler) {
88
+ const self = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
89
+ compiler.options.module?.rules?.unshift({
90
+ test: SCOPED_STYLE_FILE,
91
+ loader: node_path.default.join(node_path.default.dirname(self), `webpack-style-loader${node_path.default.extname(self)}`)
92
+ });
93
+ }
94
+ //#endregion
95
+ Object.defineProperty(exports, "__toESM", {
96
+ enumerable: true,
97
+ get: function() {
98
+ return __toESM;
99
+ }
100
+ });
101
+ Object.defineProperty(exports, "findVirtualModules", {
102
+ enumerable: true,
103
+ get: function() {
104
+ return findVirtualModules;
105
+ }
106
+ });
107
+ Object.defineProperty(exports, "isPreprocessorLang", {
108
+ enumerable: true,
109
+ get: function() {
110
+ return isPreprocessorLang;
111
+ }
112
+ });
113
+ Object.defineProperty(exports, "preprocessStyle", {
114
+ enumerable: true,
115
+ get: function() {
116
+ return preprocessStyle;
117
+ }
118
+ });
119
+ Object.defineProperty(exports, "registerWebpackStyleRule", {
120
+ enumerable: true,
121
+ get: function() {
122
+ return registerWebpackStyleRule;
123
+ }
124
+ });
125
+ Object.defineProperty(exports, "scopeCss", {
126
+ enumerable: true,
127
+ get: function() {
128
+ return scopeCss;
129
+ }
130
+ });
131
+ Object.defineProperty(exports, "transformStyleVars", {
132
+ enumerable: true,
133
+ get: function() {
134
+ return transformStyleVars;
135
+ }
136
+ });
137
+ Object.defineProperty(exports, "webpackStylePath", {
138
+ enumerable: true,
139
+ get: function() {
140
+ return webpackStylePath;
141
+ }
142
+ });
143
+ Object.defineProperty(exports, "webpackStyleScope", {
144
+ enumerable: true,
145
+ get: function() {
146
+ return webpackStyleScope;
147
+ }
148
+ });
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-BZZSLylM.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-BMwc3bUL.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-LGSCePN4.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BMBg2ffv.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.443.0",
3
+ "version": "0.457.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.443.0",
71
+ "@vizejs/native": "0.457.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },