@vizejs/unplugin 0.667.0 → 0.669.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
@@ -117,7 +117,7 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
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
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
- - 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.
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.
123
123
  - If your bundler inlines the Vue runtime, Vize injects the usual Vue 3 compile-time feature flags for Rollup-like and Webpack hosts when its compiler is active.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-BMJB8--1.cjs");
1
+ const require_unplugin = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-C0_aL3Si.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-BMJB8--1.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C0_aL3Si.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-BMJB8--1.cjs");
5
+ const require_unplugin = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C0_aL3Si.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-BMJB8--1.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C0_aL3Si.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-BMJB8--1.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C0_aL3Si.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -152,25 +152,22 @@ function hasImportRule(ast) {
152
152
  function assertInlinedStyleSrc(styles, filename) {
153
153
  for (const style of styles) if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
154
154
  }
155
- /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
155
+ /**
156
+ * CSS injected at run time is a string in the page: nothing compiles a
157
+ * preprocessor block or resolves an `@import` there.
158
+ */
156
159
  function assertInjectableCss(styles, filename) {
157
160
  for (const style of styles) {
161
+ if (isPreprocessorLang(style.lang)) throw new Error(`[vize] ${filename}: <style lang="${style.lang}"> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing compiles ${style.lang}. Bundle the build, write the block as CSS, or use @vizejs/vite-plugin.`);
158
162
  if (!style.content.includes("@")) continue;
159
163
  if (hasImportRule(parseCssAst(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing resolves the import. Inline the imported CSS, bundle the build, or use @vizejs/vite-plugin.`);
160
164
  }
161
165
  }
162
166
  //#endregion
163
167
  //#region src/style.ts
164
- function needsPreprocessor(block) {
165
- return isPreprocessorLang(block.lang);
166
- }
167
168
  function isCssModule(block) {
168
169
  return block.module !== false;
169
170
  }
170
- /** Blocks only a host CSS pipeline can serve. */
171
- function hasDelegatedStyles(compiled) {
172
- return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
173
- }
174
171
  function generateScopeId(filename, root, isProduction, source) {
175
172
  return generateSfcScopeId(filename, root, isProduction, source);
176
173
  }
@@ -230,7 +227,7 @@ function generateOutput(compiled, options) {
230
227
  output += "\n_sfc_main.render = render;";
231
228
  output += "\nexport default _sfc_main;";
232
229
  }
233
- if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
230
+ if (hostCss !== "none") {
234
231
  const styleImports = [];
235
232
  const cssModuleImports = [];
236
233
  for (const block of compiled.styles) {
@@ -255,9 +252,9 @@ function generateOutput(compiled, options) {
255
252
  }).join("\n");
256
253
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
257
254
  }
258
- } else if (compiled.css) {
255
+ } else {
259
256
  assertInjectableCss(compiled.styles, filePath);
260
- output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
257
+ if (compiled.css) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
261
258
  }
262
259
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
263
260
  return output;
@@ -333,10 +330,14 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
333
330
  ["template", parsed.template],
334
331
  ["script", parsed.script],
335
332
  ["script", parsed.scriptSetup],
336
- ...parsed.styles.map((style) => ["style", style])
333
+ ...parsed.styles.map((style, index) => [
334
+ "style",
335
+ style,
336
+ index
337
+ ])
337
338
  ];
338
339
  const found = [];
339
- for (const [tag, block] of blocks) {
340
+ for (const [tag, block, styleIndex] of blocks) {
340
341
  if (!block) continue;
341
342
  const { start, tagStart, tagEnd } = block.loc;
342
343
  const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
@@ -344,7 +345,8 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
344
345
  tag,
345
346
  ...split,
346
347
  tagStart,
347
- tagEnd
348
+ tagEnd,
349
+ styleIndex
348
350
  });
349
351
  }
350
352
  return found;
@@ -371,9 +373,11 @@ function readSrcBlock(filePath, tag, src, resolutions) {
371
373
  * the bundler's `resolutions` (see {@link sfcSrcFile}).
372
374
  */
373
375
  function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
376
+ const styleSrcs = /* @__PURE__ */ new Map();
374
377
  if (!SRC_BLOCK_HINT.test(source)) return {
375
378
  source,
376
- dependencies: []
379
+ dependencies: [],
380
+ styleSrcs
377
381
  };
378
382
  const bytes = Buffer.from(source);
379
383
  const edits = [];
@@ -381,6 +385,7 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
381
385
  for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
382
386
  const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
383
387
  dependencies.push(file.path);
388
+ if (block.styleIndex !== void 0) styleSrcs.set(block.styleIndex, file.path);
384
389
  edits.push({
385
390
  start: block.tagStart,
386
391
  end: block.tagEnd,
@@ -389,7 +394,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
389
394
  }
390
395
  if (edits.length === 0) return {
391
396
  source,
392
- dependencies
397
+ dependencies,
398
+ styleSrcs
393
399
  };
394
400
  edits.sort((a, b) => a.start - b.start);
395
401
  const parts = [];
@@ -401,7 +407,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
401
407
  parts.push(bytes.subarray(offset));
402
408
  return {
403
409
  source: Buffer.concat(parts).toString("utf8"),
404
- dependencies
410
+ dependencies,
411
+ styleSrcs
405
412
  };
406
413
  }
407
414
  //#endregion
@@ -154,25 +154,22 @@ function hasImportRule(ast) {
154
154
  function assertInlinedStyleSrc(styles, filename) {
155
155
  for (const style of styles) if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
156
156
  }
157
- /** CSS injected at run time is a string in the page, so nothing resolves its `@import`. */
157
+ /**
158
+ * CSS injected at run time is a string in the page: nothing compiles a
159
+ * preprocessor block or resolves an `@import` there.
160
+ */
158
161
  function assertInjectableCss(styles, filename) {
159
162
  for (const style of styles) {
163
+ if (require_webpack_styles.isPreprocessorLang(style.lang)) throw new Error(`[vize] ${filename}: <style lang="${style.lang}"> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing compiles ${style.lang}. Bundle the build, write the block as CSS, or use @vizejs/vite-plugin.`);
160
164
  if (!style.content.includes("@")) continue;
161
165
  if (hasImportRule((0, _vizejs_native.parseCssAst)(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> needs a bundler CSS pipeline. @vizejs/unplugin injects CSS at run time under Babel and esbuild without \`bundle\`, where nothing resolves the import. Inline the imported CSS, bundle the build, or use @vizejs/vite-plugin.`);
162
166
  }
163
167
  }
164
168
  //#endregion
165
169
  //#region src/style.ts
166
- function needsPreprocessor(block) {
167
- return require_webpack_styles.isPreprocessorLang(block.lang);
168
- }
169
170
  function isCssModule(block) {
170
171
  return block.module !== false;
171
172
  }
172
- /** Blocks only a host CSS pipeline can serve. */
173
- function hasDelegatedStyles(compiled) {
174
- return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
175
- }
176
173
  function generateScopeId(filename, root, isProduction, source) {
177
174
  return (0, _vizejs_native.generateSfcScopeId)(filename, root, isProduction, source);
178
175
  }
@@ -232,7 +229,7 @@ function generateOutput(compiled, options) {
232
229
  output += "\n_sfc_main.render = render;";
233
230
  output += "\nexport default _sfc_main;";
234
231
  }
235
- if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
232
+ if (hostCss !== "none") {
236
233
  const styleImports = [];
237
234
  const cssModuleImports = [];
238
235
  for (const block of compiled.styles) {
@@ -257,9 +254,9 @@ function generateOutput(compiled, options) {
257
254
  }).join("\n");
258
255
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
259
256
  }
260
- } else if (compiled.css) {
257
+ } else {
261
258
  assertInjectableCss(compiled.styles, filePath);
262
- output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
259
+ if (compiled.css) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
263
260
  }
264
261
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
265
262
  return output;
@@ -335,10 +332,14 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
335
332
  ["template", parsed.template],
336
333
  ["script", parsed.script],
337
334
  ["script", parsed.scriptSetup],
338
- ...parsed.styles.map((style) => ["style", style])
335
+ ...parsed.styles.map((style, index) => [
336
+ "style",
337
+ style,
338
+ index
339
+ ])
339
340
  ];
340
341
  const found = [];
341
- for (const [tag, block] of blocks) {
342
+ for (const [tag, block, styleIndex] of blocks) {
342
343
  if (!block) continue;
343
344
  const { start, tagStart, tagEnd } = block.loc;
344
345
  const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
@@ -346,7 +347,8 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
346
347
  tag,
347
348
  ...split,
348
349
  tagStart,
349
- tagEnd
350
+ tagEnd,
351
+ styleIndex
350
352
  });
351
353
  }
352
354
  return found;
@@ -373,9 +375,11 @@ function readSrcBlock(filePath, tag, src, resolutions) {
373
375
  * the bundler's `resolutions` (see {@link sfcSrcFile}).
374
376
  */
375
377
  function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
378
+ const styleSrcs = /* @__PURE__ */ new Map();
376
379
  if (!SRC_BLOCK_HINT.test(source)) return {
377
380
  source,
378
- dependencies: []
381
+ dependencies: [],
382
+ styleSrcs
379
383
  };
380
384
  const bytes = Buffer.from(source);
381
385
  const edits = [];
@@ -383,6 +387,7 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
383
387
  for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
384
388
  const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
385
389
  dependencies.push(file.path);
390
+ if (block.styleIndex !== void 0) styleSrcs.set(block.styleIndex, file.path);
386
391
  edits.push({
387
392
  start: block.tagStart,
388
393
  end: block.tagEnd,
@@ -391,7 +396,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
391
396
  }
392
397
  if (edits.length === 0) return {
393
398
  source,
394
- dependencies
399
+ dependencies,
400
+ styleSrcs
395
401
  };
396
402
  edits.sort((a, b) => a.start - b.start);
397
403
  const parts = [];
@@ -403,7 +409,8 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
403
409
  parts.push(bytes.subarray(offset));
404
410
  return {
405
411
  source: Buffer.concat(parts).toString("utf8"),
406
- dependencies
412
+ dependencies,
413
+ styleSrcs
407
414
  };
408
415
  }
409
416
  //#endregion
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-BMJB8--1.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-Cdo3QsZA.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-C3FO9qAL.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-C0_aL3Si.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.667.0",
3
+ "version": "0.669.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.667.0",
71
+ "@vizejs/native": "0.669.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },