@vizejs/unplugin 0.665.0 → 0.666.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,7 +115,7 @@ 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
- - 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.
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
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.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-D1CMvI6_.cjs");
1
+ const require_unplugin = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-C3FO9qAL.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-D1CMvI6_.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.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-D1CMvI6_.cjs");
5
+ const require_unplugin = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.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-D1CMvI6_.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.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-D1CMvI6_.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -1,13 +1,13 @@
1
- const require_webpack_styles = require("./webpack-styles-DVh6lFXt.cjs");
2
- let node_fs = require("node:fs");
3
- node_fs = require_webpack_styles.__toESM(node_fs, 1);
1
+ const require_webpack_styles = require("./webpack-styles-B4946o00.cjs");
4
2
  let node_module = require("node:module");
5
- let node_path = require("node:path");
6
- node_path = require_webpack_styles.__toESM(node_path, 1);
7
- let _vizejs_native = require("@vizejs/native");
8
- _vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
9
3
  let unplugin = require("unplugin");
10
4
  let node_crypto = require("node:crypto");
5
+ let _vizejs_native = require("@vizejs/native");
6
+ _vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
7
+ let node_path = require("node:path");
8
+ node_path = require_webpack_styles.__toESM(node_path, 1);
9
+ let node_fs = require("node:fs");
10
+ node_fs = require_webpack_styles.__toESM(node_fs, 1);
11
11
  let oxc_transform = require("oxc-transform");
12
12
  //#region src/filter.ts
13
13
  function createFilter(include, exclude) {
@@ -490,7 +490,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
490
490
  dependencies
491
491
  };
492
492
  }
493
- function compileJsxModule(filePath, source, options) {
493
+ function compileJsxModule(filePath, source, options, output) {
494
494
  const result = compileJsx(source, {
495
495
  filename: filePath,
496
496
  lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
@@ -500,20 +500,99 @@ function compileJsxModule(filePath, source, options) {
500
500
  sourceMap: options.sourceMap
501
501
  });
502
502
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
503
- const css = (result.scopedStyles ?? []).map((style) => style.css).join("\n");
504
- let code = result.code;
505
- let map = result.map ?? null;
506
- if (css) {
507
- const styleKey = result.scopedStyles[0].scopeId.replace(/^data-v-/, "");
508
- ({code, map} = prependMappedJsxCode(code, map, prependInlineStyleInjection("", css, styleKey)));
503
+ const scoped = result.scopedStyles ?? [];
504
+ const styles = scoped.map((style, index) => ({
505
+ content: style.css,
506
+ src: null,
507
+ lang: "css",
508
+ scoped: false,
509
+ module: false,
510
+ index
511
+ }));
512
+ let prefix = "";
513
+ if (styles.length > 0 && output.hostCss === "none") prefix = prependInlineStyleInjection("", styles.map((style) => style.content).join("\n"), scoped[0].scopeId.replace(/^data-v-/, ""));
514
+ else for (const block of styles) {
515
+ const id = output.styleRequest?.(block, null) ?? styleRequestId(filePath, block, null, output.hostCss);
516
+ prefix += `import ${JSON.stringify(id)};\n`;
509
517
  }
518
+ const { code, map } = prependMappedJsxCode(result.code, result.map ?? null, prefix);
510
519
  return {
511
520
  code,
512
521
  map,
513
- warnings: result.warnings
522
+ warnings: result.warnings,
523
+ styles
514
524
  };
515
525
  }
516
526
  //#endregion
527
+ //#region src/host.ts
528
+ /**
529
+ * What the host does with an imported stylesheet. esbuild without `bundle`
530
+ * never follows an import, and its CSS loaders compile no preprocessor.
531
+ */
532
+ function hostCss(context, framework) {
533
+ if (framework !== "esbuild") return "preprocessors";
534
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
535
+ }
536
+ 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.";
537
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
538
+ function isStylePipelineError(error) {
539
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
540
+ }
541
+ /** The bundler's own module resolver, or null for a host that offers none. */
542
+ function hostResolver(context) {
543
+ const ctx = context;
544
+ if (typeof ctx.resolve === "function") {
545
+ const resolve = ctx.resolve;
546
+ return async (request, importer) => {
547
+ const result = await resolve.call(context, request, importer, { skipSelf: true });
548
+ return result && !result.external ? result.id : null;
549
+ };
550
+ }
551
+ const native = ctx.getNativeBuildContext?.();
552
+ if (native && "loaderContext" in native && native.loaderContext) {
553
+ const resolve = native.loaderContext.getResolve();
554
+ return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
555
+ }
556
+ if (native && "build" in native) {
557
+ const { build } = native;
558
+ return async (request, importer) => {
559
+ const result = await build.resolve(request, {
560
+ kind: "import-statement",
561
+ resolveDir: node_path.default.dirname(importer),
562
+ importer
563
+ });
564
+ return result.errors.length > 0 || result.external ? null : result.path;
565
+ };
566
+ }
567
+ return null;
568
+ }
569
+ /** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
570
+ async function resolveSrcRequests(context, importer, source) {
571
+ const requests = listSfcSrcRequests(_vizejs_native.parseSfc, importer, source);
572
+ const resolve = requests.length > 0 ? hostResolver(context) : null;
573
+ return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
574
+ }
575
+ //#endregion
576
+ //#region src/style-module.ts
577
+ async function loadStyleBlock(context, id, options, cache, jsxStyles) {
578
+ const request = parseVueRequest(id);
579
+ const index = request.query.index ?? -1;
580
+ if (index < 0) return "";
581
+ if (isJsxFile(request.filename)) return (jsxStyles.get(request.filename) ?? (node_fs.default.existsSync(request.filename) ? compileJsxModule(request.filename, node_fs.default.readFileSync(request.filename, "utf8"), options, { hostCss: "preprocessors" }).styles : []))[index]?.content ?? "";
582
+ let compiled = cache.get(request.filename)?.compiled;
583
+ if (!compiled && node_fs.default.existsSync(request.filename)) {
584
+ const source = node_fs.default.readFileSync(request.filename, "utf8");
585
+ const resolutions = await resolveSrcRequests(context, request.filename, source);
586
+ compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
587
+ }
588
+ const block = compiled?.styles[index];
589
+ if (!compiled || !block) return "";
590
+ const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
591
+ 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;
592
+ const scoped = request.query.scoped;
593
+ return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
594
+ }
595
+ //#endregion
517
596
  //#region src/strip-types.ts
518
597
  function formatErrorMessage(error) {
519
598
  const parts = [error.message];
@@ -609,76 +688,20 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
609
688
  for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
610
689
  if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
611
690
  }
612
- async function loadStyleBlock(context, id, options, cache) {
613
- const request = parseVueRequest(id);
614
- const index = request.query.index ?? -1;
615
- if (index < 0) return "";
616
- let compiled = cache.get(request.filename)?.compiled;
617
- if (!compiled && node_fs.default.existsSync(request.filename)) {
618
- const source = node_fs.default.readFileSync(request.filename, "utf8");
619
- const resolutions = await resolveSrcRequests(context, request.filename, source);
620
- compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
621
- }
622
- const block = compiled?.styles[index];
623
- if (!compiled || !block) return "";
624
- const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
625
- 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;
626
- const scoped = request.query.scoped;
627
- return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
628
- }
629
- /**
630
- * What the host does with an imported stylesheet. esbuild without `bundle`
631
- * never follows an import, and its CSS loaders compile no preprocessor.
632
- */
633
- function hostCss(context, framework) {
634
- if (framework !== "esbuild") return "preprocessors";
635
- return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
636
- }
637
- 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.";
638
- /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
639
- function isStylePipelineError(error) {
640
- return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
641
- }
642
- /** The bundler's own module resolver, or null for a host that offers none. */
643
- function hostResolver(context) {
644
- const ctx = context;
645
- if (typeof ctx.resolve === "function") {
646
- const resolve = ctx.resolve;
647
- return async (request, importer) => {
648
- const result = await resolve.call(context, request, importer, { skipSelf: true });
649
- return result && !result.external ? result.id : null;
650
- };
651
- }
652
- const native = ctx.getNativeBuildContext?.();
653
- if (native && "loaderContext" in native && native.loaderContext) {
654
- const resolve = native.loaderContext.getResolve();
655
- return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
656
- }
657
- if (native && "build" in native) {
658
- const { build } = native;
659
- return async (request, importer) => {
660
- const result = await build.resolve(request, {
661
- kind: "import-statement",
662
- resolveDir: node_path.default.dirname(importer),
663
- importer
664
- });
665
- return result.errors.length > 0 || result.external ? null : result.path;
666
- };
667
- }
668
- return null;
669
- }
670
- /** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
671
- async function resolveSrcRequests(context, importer, source) {
672
- const requests = listSfcSrcRequests(_vizejs_native.parseSfc, importer, source);
673
- const resolve = requests.length > 0 ? hostResolver(context) : null;
674
- return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
675
- }
676
691
  const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
677
692
  const options = normalizeOptions(rawOptions);
678
693
  const filter = createFilter(options.include, options.exclude);
679
694
  const cache = /* @__PURE__ */ new Map();
695
+ const jsxStyles = /* @__PURE__ */ new Map();
680
696
  const webpackStyleFiles = meta.framework === "webpack";
681
697
  let virtualModules;
698
+ /** A webpack style block is a virtual file the host's rules match (webpack-styles.ts). */
699
+ const writeWebpackStyle = (id, block, scoped, content) => {
700
+ const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
701
+ if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
702
+ virtualModules.writeModule(stylePath, content);
703
+ return require_webpack_styles.webpackStyleRequest(stylePath, block);
704
+ };
682
705
  let loadedStyles = false;
683
706
  const rollupHooks = {
684
707
  buildStart() {
@@ -703,7 +726,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
703
726
  if (!isVueStyleRequest(id)) return null;
704
727
  loadedStyles = true;
705
728
  return {
706
- code: await loadStyleBlock(this, id, options, cache),
729
+ code: await loadStyleBlock(this, id, options, cache, jsxStyles),
707
730
  map: null
708
731
  };
709
732
  },
@@ -718,7 +741,11 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
718
741
  if (options.hostCompiler) return null;
719
742
  if (isJsxFile(id)) {
720
743
  if (!filter(id)) return null;
721
- const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options);
744
+ const { code: jsxCode, map: jsxMap, warnings, styles } = compileJsxModule(id, code, options, {
745
+ hostCss: hostCss(this, meta.framework),
746
+ styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, block.content) : void 0
747
+ });
748
+ jsxStyles.set(id, styles);
722
749
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
723
750
  return {
724
751
  code: jsxCode,
@@ -734,12 +761,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
734
761
  isDev: false,
735
762
  hostCss: hostCss(this, meta.framework),
736
763
  filePath: id,
737
- styleRequest: webpackStyleFiles ? (block, scoped) => {
738
- const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
739
- if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
740
- virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
741
- return require_webpack_styles.webpackStyleRequest(stylePath, block);
742
- } : void 0
764
+ styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0)) : void 0
743
765
  }), options.sourceMap);
744
766
  return {
745
767
  code: transformed.code,
@@ -748,6 +770,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
748
770
  },
749
771
  watchChange(id) {
750
772
  if (isVueFile(id)) cache.delete(id);
773
+ jsxStyles.delete(id);
751
774
  },
752
775
  rollup: rollupHooks,
753
776
  rolldown: rollupHooks,
@@ -1,11 +1,11 @@
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";
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";
2
2
  import { createRequire } from "node:module";
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import * as native from "@vizejs/native";
6
- import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
7
3
  import { createUnplugin } from "unplugin";
8
4
  import { createHash } from "node:crypto";
5
+ import * as native from "@vizejs/native";
6
+ import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
7
+ import path from "node:path";
8
+ import fs from "node:fs";
9
9
  import { transform } from "oxc-transform";
10
10
  //#region src/filter.ts
11
11
  function createFilter(include, exclude) {
@@ -488,7 +488,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
488
488
  dependencies
489
489
  };
490
490
  }
491
- function compileJsxModule(filePath, source, options) {
491
+ function compileJsxModule(filePath, source, options, output) {
492
492
  const result = compileJsx(source, {
493
493
  filename: filePath,
494
494
  lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
@@ -498,20 +498,99 @@ function compileJsxModule(filePath, source, options) {
498
498
  sourceMap: options.sourceMap
499
499
  });
500
500
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
501
- const css = (result.scopedStyles ?? []).map((style) => style.css).join("\n");
502
- let code = result.code;
503
- let map = result.map ?? null;
504
- if (css) {
505
- const styleKey = result.scopedStyles[0].scopeId.replace(/^data-v-/, "");
506
- ({code, map} = prependMappedJsxCode(code, map, prependInlineStyleInjection("", css, styleKey)));
501
+ const scoped = result.scopedStyles ?? [];
502
+ const styles = scoped.map((style, index) => ({
503
+ content: style.css,
504
+ src: null,
505
+ lang: "css",
506
+ scoped: false,
507
+ module: false,
508
+ index
509
+ }));
510
+ let prefix = "";
511
+ if (styles.length > 0 && output.hostCss === "none") prefix = prependInlineStyleInjection("", styles.map((style) => style.content).join("\n"), scoped[0].scopeId.replace(/^data-v-/, ""));
512
+ else for (const block of styles) {
513
+ const id = output.styleRequest?.(block, null) ?? styleRequestId(filePath, block, null, output.hostCss);
514
+ prefix += `import ${JSON.stringify(id)};\n`;
507
515
  }
516
+ const { code, map } = prependMappedJsxCode(result.code, result.map ?? null, prefix);
508
517
  return {
509
518
  code,
510
519
  map,
511
- warnings: result.warnings
520
+ warnings: result.warnings,
521
+ styles
512
522
  };
513
523
  }
514
524
  //#endregion
525
+ //#region src/host.ts
526
+ /**
527
+ * What the host does with an imported stylesheet. esbuild without `bundle`
528
+ * never follows an import, and its CSS loaders compile no preprocessor.
529
+ */
530
+ function hostCss(context, framework) {
531
+ if (framework !== "esbuild") return "preprocessors";
532
+ return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
533
+ }
534
+ 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.";
535
+ /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
536
+ function isStylePipelineError(error) {
537
+ return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
538
+ }
539
+ /** The bundler's own module resolver, or null for a host that offers none. */
540
+ function hostResolver(context) {
541
+ const ctx = context;
542
+ if (typeof ctx.resolve === "function") {
543
+ const resolve = ctx.resolve;
544
+ return async (request, importer) => {
545
+ const result = await resolve.call(context, request, importer, { skipSelf: true });
546
+ return result && !result.external ? result.id : null;
547
+ };
548
+ }
549
+ const native = ctx.getNativeBuildContext?.();
550
+ if (native && "loaderContext" in native && native.loaderContext) {
551
+ const resolve = native.loaderContext.getResolve();
552
+ return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
553
+ }
554
+ if (native && "build" in native) {
555
+ const { build } = native;
556
+ return async (request, importer) => {
557
+ const result = await build.resolve(request, {
558
+ kind: "import-statement",
559
+ resolveDir: path.dirname(importer),
560
+ importer
561
+ });
562
+ return result.errors.length > 0 || result.external ? null : result.path;
563
+ };
564
+ }
565
+ return null;
566
+ }
567
+ /** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
568
+ async function resolveSrcRequests(context, importer, source) {
569
+ const requests = listSfcSrcRequests(parseSfc, importer, source);
570
+ const resolve = requests.length > 0 ? hostResolver(context) : null;
571
+ return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
572
+ }
573
+ //#endregion
574
+ //#region src/style-module.ts
575
+ async function loadStyleBlock(context, id, options, cache, jsxStyles) {
576
+ const request = parseVueRequest(id);
577
+ const index = request.query.index ?? -1;
578
+ if (index < 0) return "";
579
+ if (isJsxFile(request.filename)) return (jsxStyles.get(request.filename) ?? (fs.existsSync(request.filename) ? compileJsxModule(request.filename, fs.readFileSync(request.filename, "utf8"), options, { hostCss: "preprocessors" }).styles : []))[index]?.content ?? "";
580
+ let compiled = cache.get(request.filename)?.compiled;
581
+ if (!compiled && fs.existsSync(request.filename)) {
582
+ const source = fs.readFileSync(request.filename, "utf8");
583
+ const resolutions = await resolveSrcRequests(context, request.filename, source);
584
+ compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
585
+ }
586
+ const block = compiled?.styles[index];
587
+ if (!compiled || !block) return "";
588
+ const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
589
+ const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
590
+ const scoped = request.query.scoped;
591
+ return scoped ? scopeCss(css, scoped) : css;
592
+ }
593
+ //#endregion
515
594
  //#region src/strip-types.ts
516
595
  function formatErrorMessage(error) {
517
596
  const parts = [error.message];
@@ -607,76 +686,20 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
607
686
  for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
608
687
  if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
609
688
  }
610
- async function loadStyleBlock(context, id, options, cache) {
611
- const request = parseVueRequest(id);
612
- const index = request.query.index ?? -1;
613
- if (index < 0) return "";
614
- let compiled = cache.get(request.filename)?.compiled;
615
- if (!compiled && fs.existsSync(request.filename)) {
616
- const source = fs.readFileSync(request.filename, "utf8");
617
- const resolutions = await resolveSrcRequests(context, request.filename, source);
618
- compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
619
- }
620
- const block = compiled?.styles[index];
621
- if (!compiled || !block) return "";
622
- const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
623
- const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
624
- const scoped = request.query.scoped;
625
- return scoped ? scopeCss(css, scoped) : css;
626
- }
627
- /**
628
- * What the host does with an imported stylesheet. esbuild without `bundle`
629
- * never follows an import, and its CSS loaders compile no preprocessor.
630
- */
631
- function hostCss(context, framework) {
632
- if (framework !== "esbuild") return "preprocessors";
633
- return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
634
- }
635
- const CSS_PIPELINE_HINT = "[vize] <style> blocks are stylesheet modules for the bundler's CSS pipeline, and this build did not bundle one. tsdown needs @tsdown/css; Rollup needs a CSS plugin such as rollup-plugin-postcss; Rolldown alone does not bundle CSS, so build through tsdown or Vite.";
636
- /** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
637
- function isStylePipelineError(error) {
638
- return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
639
- }
640
- /** The bundler's own module resolver, or null for a host that offers none. */
641
- function hostResolver(context) {
642
- const ctx = context;
643
- if (typeof ctx.resolve === "function") {
644
- const resolve = ctx.resolve;
645
- return async (request, importer) => {
646
- const result = await resolve.call(context, request, importer, { skipSelf: true });
647
- return result && !result.external ? result.id : null;
648
- };
649
- }
650
- const native = ctx.getNativeBuildContext?.();
651
- if (native && "loaderContext" in native && native.loaderContext) {
652
- const resolve = native.loaderContext.getResolve();
653
- return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
654
- }
655
- if (native && "build" in native) {
656
- const { build } = native;
657
- return async (request, importer) => {
658
- const result = await build.resolve(request, {
659
- kind: "import-statement",
660
- resolveDir: path.dirname(importer),
661
- importer
662
- });
663
- return result.errors.length > 0 || result.external ? null : result.path;
664
- };
665
- }
666
- return null;
667
- }
668
- /** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
669
- async function resolveSrcRequests(context, importer, source) {
670
- const requests = listSfcSrcRequests(parseSfc, importer, source);
671
- const resolve = requests.length > 0 ? hostResolver(context) : null;
672
- return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
673
- }
674
689
  const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
675
690
  const options = normalizeOptions(rawOptions);
676
691
  const filter = createFilter(options.include, options.exclude);
677
692
  const cache = /* @__PURE__ */ new Map();
693
+ const jsxStyles = /* @__PURE__ */ new Map();
678
694
  const webpackStyleFiles = meta.framework === "webpack";
679
695
  let virtualModules;
696
+ /** A webpack style block is a virtual file the host's rules match (webpack-styles.ts). */
697
+ const writeWebpackStyle = (id, block, scoped, content) => {
698
+ const stylePath = webpackStylePath(id, block, scoped);
699
+ if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
700
+ virtualModules.writeModule(stylePath, content);
701
+ return webpackStyleRequest(stylePath, block);
702
+ };
680
703
  let loadedStyles = false;
681
704
  const rollupHooks = {
682
705
  buildStart() {
@@ -701,7 +724,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
701
724
  if (!isVueStyleRequest(id)) return null;
702
725
  loadedStyles = true;
703
726
  return {
704
- code: await loadStyleBlock(this, id, options, cache),
727
+ code: await loadStyleBlock(this, id, options, cache, jsxStyles),
705
728
  map: null
706
729
  };
707
730
  },
@@ -716,7 +739,11 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
716
739
  if (options.hostCompiler) return null;
717
740
  if (isJsxFile(id)) {
718
741
  if (!filter(id)) return null;
719
- const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options);
742
+ const { code: jsxCode, map: jsxMap, warnings, styles } = compileJsxModule(id, code, options, {
743
+ hostCss: hostCss(this, meta.framework),
744
+ styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, block.content) : void 0
745
+ });
746
+ jsxStyles.set(id, styles);
720
747
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
721
748
  return {
722
749
  code: jsxCode,
@@ -732,12 +759,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
732
759
  isDev: false,
733
760
  hostCss: hostCss(this, meta.framework),
734
761
  filePath: id,
735
- styleRequest: webpackStyleFiles ? (block, scoped) => {
736
- const stylePath = webpackStylePath(id, block, scoped);
737
- if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
738
- virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
739
- return webpackStyleRequest(stylePath, block);
740
- } : void 0
762
+ styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0)) : void 0
741
763
  }), options.sourceMap);
742
764
  return {
743
765
  code: transformed.code,
@@ -746,6 +768,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
746
768
  },
747
769
  watchChange(id) {
748
770
  if (isVueFile(id)) cache.delete(id);
771
+ jsxStyles.delete(id);
749
772
  },
750
773
  rollup: rollupHooks,
751
774
  rolldown: rollupHooks,
@@ -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-DVh6lFXt.cjs");
5
+ const require_webpack_styles = require("./webpack-styles-B4946o00.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-CoRj2un6.mjs";
1
+ import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-qKeVgHc7.mjs";
2
2
  //#region src/webpack-style-loader.ts
3
3
  const SCOPE_QUERY = "?scope";
4
4
  const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-D1CMvI6_.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-BMJB8--1.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-CuhaOxEl.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.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.665.0",
3
+ "version": "0.666.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.665.0",
71
+ "@vizejs/native": "0.666.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },
@@ -21,9 +21,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
  //#endregion
23
23
  let node_module = require("node:module");
24
+ let _vizejs_native = require("@vizejs/native");
24
25
  let node_path = require("node:path");
25
26
  node_path = __toESM(node_path, 1);
26
- let _vizejs_native = require("@vizejs/native");
27
27
  let node_url = require("node:url");
28
28
  //#region src/style-scope.ts
29
29
  const PREPROCESSOR_LANGS = new Set([
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
- import path from "node:path";
3
2
  import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
3
+ import path from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  //#region src/style-scope.ts
6
6
  const PREPROCESSOR_LANGS = new Set([