@vizejs/unplugin 0.663.0 → 0.665.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 +1 -1
- package/dist/babel.cjs +2 -2
- package/dist/babel.mjs +2 -2
- package/dist/esbuild.cjs +1 -1
- package/dist/esbuild.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/rolldown.cjs +1 -1
- package/dist/rolldown.mjs +1 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.mjs +1 -1
- package/dist/{unplugin-hYMgbR_K.mjs → unplugin-CuhaOxEl.mjs} +44 -42
- package/dist/{unplugin-7UpIpoaj.cjs → unplugin-D1CMvI6_.cjs} +45 -43
- package/dist/webpack-style-loader.cjs +1 -1
- package/dist/webpack-style-loader.mjs +1 -1
- package/dist/{webpack-styles-Ca7spvMb.mjs → webpack-styles-CoRj2un6.mjs} +1 -1
- package/dist/{webpack-styles-IFEnxDay.cjs → webpack-styles-DVh6lFXt.cjs} +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -119,6 +119,6 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
|
|
|
119
119
|
- `<style src>`, `<script src>` and `<template src>` follow Vue's SFC spec, as in `@vitejs/plugin-vue`: a `./` or `../` path is read next to the SFC, and any other `src` (a package such as `modern-normalize/modern-normalize.css`, an alias, an absolute path, or a bare `foo.css`) is a module request resolved by the bundler's own resolver. The file is inlined before compilation and watched. A request that resolves to no file, including an external module, is a build error.
|
|
120
120
|
- Babel and esbuild without `bundle` bundle no stylesheet, so there plain CSS is injected into JavaScript at run time, and an `@import` in it is a build error. Preprocessor and CSS Module blocks still need a CSS pipeline.
|
|
121
121
|
- CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
|
|
122
|
-
- Scoped preprocessor styles are compiled before they are scoped, as in Vue: Webpack uses your `.scss`/`.less`/`.styl` rules, while Rollup, Rolldown and esbuild run the project's installed `sass` (or `sass-embedded`), `less` or `stylus`.
|
|
122
|
+
- Scoped preprocessor styles are compiled before they are scoped, as in Vue: Webpack uses your `.scss`/`.less`/`.styl` rules, while Rollup, Rolldown and esbuild run the project's installed `sass` (or `sass-embedded`), `less` or `stylus`. Unscoped preprocessor blocks go to the host's preprocessor (`@tsdown/css`, `rollup-plugin-postcss`, your webpack rules), except under esbuild, whose CSS loaders compile none, so the plugin runs the installed preprocessor there too.
|
|
123
123
|
- If your bundler inlines the Vue runtime, Vize injects the usual Vue 3 compile-time feature flags for Rollup-like and Webpack hosts when its compiler is active.
|
|
124
124
|
- Test carefully before depending on this package in production.
|
package/dist/babel.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_unplugin = require("./unplugin-
|
|
1
|
+
const require_unplugin = require("./unplugin-D1CMvI6_.cjs");
|
|
2
2
|
//#region src/babel.ts
|
|
3
3
|
function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
4
4
|
const options = require_unplugin.normalizeOptions(rawOptions);
|
|
@@ -18,7 +18,7 @@ function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
|
18
18
|
return parse(require_unplugin.generateOutput(compiled, {
|
|
19
19
|
isProduction: options.isProduction,
|
|
20
20
|
isDev: false,
|
|
21
|
-
|
|
21
|
+
hostCss: "none",
|
|
22
22
|
filePath: filename
|
|
23
23
|
}), {
|
|
24
24
|
...parserOptions,
|
package/dist/babel.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-
|
|
1
|
+
import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-CuhaOxEl.mjs";
|
|
2
2
|
//#region src/babel.ts
|
|
3
3
|
function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
4
4
|
const options = normalizeOptions(rawOptions);
|
|
@@ -18,7 +18,7 @@ function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
|
18
18
|
return parse(generateOutput(compiled, {
|
|
19
19
|
isProduction: options.isProduction,
|
|
20
20
|
isDev: false,
|
|
21
|
-
|
|
21
|
+
hostCss: "none",
|
|
22
22
|
filePath: filename
|
|
23
23
|
}), {
|
|
24
24
|
...parserOptions,
|
package/dist/esbuild.cjs
CHANGED
package/dist/esbuild.mjs
CHANGED
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-
|
|
5
|
+
const require_unplugin = require("./unplugin-D1CMvI6_.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-
|
|
1
|
+
import { n as vizeUnplugin } from "./unplugin-CuhaOxEl.mjs";
|
|
2
2
|
export { vizeUnplugin as default, vizeUnplugin };
|
package/dist/rolldown.cjs
CHANGED
package/dist/rolldown.mjs
CHANGED
package/dist/rollup.cjs
CHANGED
package/dist/rollup.mjs
CHANGED
|
@@ -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-
|
|
1
|
+
import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-CoRj2un6.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { createUnplugin } from "unplugin";
|
|
6
|
-
import { createHash } from "node:crypto";
|
|
7
5
|
import * as native from "@vizejs/native";
|
|
8
6
|
import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
|
|
7
|
+
import { createUnplugin } from "unplugin";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
9
|
import { transform } from "oxc-transform";
|
|
10
10
|
//#region src/filter.ts
|
|
11
11
|
function createFilter(include, exclude) {
|
|
@@ -111,12 +111,13 @@ function isVueStyleRequest(id) {
|
|
|
111
111
|
*
|
|
112
112
|
* CSS pipelines classify a module by the extension that ends the id, and treat
|
|
113
113
|
* a query on a stylesheet path as another import kind (`?raw`, `?inline`), so
|
|
114
|
-
* the path stays the SFC and `<ext>` names what `load` returns
|
|
115
|
-
*
|
|
114
|
+
* the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
|
|
115
|
+
* block arrives compiled when it is scoped (scoping follows preprocessing) or
|
|
116
|
+
* when the host compiles no preprocessor language.
|
|
116
117
|
*/
|
|
117
|
-
function styleRequestId(filePath, block, scoped) {
|
|
118
|
+
function styleRequestId(filePath, block, scoped, hostCss) {
|
|
118
119
|
const lang = block.lang ?? "css";
|
|
119
|
-
const delivered = scoped && isPreprocessorLang(lang) ? "css" : lang;
|
|
120
|
+
const delivered = (scoped !== null || hostCss !== "preprocessors") && isPreprocessorLang(lang) ? "css" : lang;
|
|
120
121
|
let query = `vue&type=style&index=${block.index}`;
|
|
121
122
|
if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
|
|
122
123
|
if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
|
|
@@ -128,12 +129,14 @@ function parseVueRequest(id) {
|
|
|
128
129
|
const params = new URLSearchParams(rawQuery);
|
|
129
130
|
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
130
131
|
const indexValue = params.get("index");
|
|
132
|
+
const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
|
|
131
133
|
return {
|
|
132
134
|
filename,
|
|
133
135
|
query: {
|
|
134
136
|
vue: params.has("vue"),
|
|
135
137
|
type: params.get("type"),
|
|
136
138
|
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
139
|
+
lang: langKey?.replace(/^lang\.(?:module\.)?/, "") ?? null,
|
|
137
140
|
module: moduleValue,
|
|
138
141
|
scoped: params.get("scoped")
|
|
139
142
|
}
|
|
@@ -210,7 +213,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
|
|
|
210
213
|
? ns.default
|
|
211
214
|
: Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
|
|
212
215
|
function generateOutput(compiled, options) {
|
|
213
|
-
const { isProduction, isDev,
|
|
216
|
+
const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
|
|
214
217
|
let output = compiled.code;
|
|
215
218
|
const exportDefaultRegex = /^export default /m;
|
|
216
219
|
const hasExportDefault = exportDefaultRegex.test(output);
|
|
@@ -227,13 +230,13 @@ function generateOutput(compiled, options) {
|
|
|
227
230
|
output += "\n_sfc_main.render = render;";
|
|
228
231
|
output += "\nexport default _sfc_main;";
|
|
229
232
|
}
|
|
230
|
-
if (
|
|
233
|
+
if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
|
|
231
234
|
const styleImports = [];
|
|
232
235
|
const cssModuleImports = [];
|
|
233
236
|
for (const block of compiled.styles) {
|
|
234
237
|
const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
|
|
235
238
|
const styleFile = styleRequest?.(block, scoped);
|
|
236
|
-
const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
|
|
239
|
+
const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
|
|
237
240
|
if (isCssModule(block)) {
|
|
238
241
|
const bindingName = typeof block.module === "string" ? block.module : "$style";
|
|
239
242
|
if (styleFile) {
|
|
@@ -296,8 +299,6 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
|
296
299
|
}
|
|
297
300
|
return resolutions;
|
|
298
301
|
}
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/src-blocks.ts
|
|
301
302
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
302
303
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
303
304
|
/** Split an opening tag into its `src` value and the tag without it. */
|
|
@@ -320,18 +321,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
320
321
|
openTag: `${head}${rest}>`
|
|
321
322
|
};
|
|
322
323
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
try {
|
|
326
|
-
return {
|
|
327
|
-
path: resolved,
|
|
328
|
-
content: fs.readFileSync(resolved, "utf8")
|
|
329
|
-
};
|
|
330
|
-
} catch {
|
|
331
|
-
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function collectSrcBlocks(filePath, bytes, source) {
|
|
324
|
+
/** The `src` blocks the native parser finds, so `src` text in scripts or comments is not one. */
|
|
325
|
+
function collectSrcBlocks(parseSfc, filePath, bytes, source) {
|
|
335
326
|
let parsed;
|
|
336
327
|
try {
|
|
337
328
|
parsed = parseSfc(source, { filename: filePath });
|
|
@@ -341,6 +332,7 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
341
332
|
const blocks = [
|
|
342
333
|
["template", parsed.template],
|
|
343
334
|
["script", parsed.script],
|
|
335
|
+
["script", parsed.scriptSetup],
|
|
344
336
|
...parsed.styles.map((style) => ["style", style])
|
|
345
337
|
];
|
|
346
338
|
const found = [];
|
|
@@ -357,18 +349,28 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
357
349
|
}
|
|
358
350
|
return found;
|
|
359
351
|
}
|
|
360
|
-
/** The `src`
|
|
361
|
-
function
|
|
352
|
+
/** The `src` module requests (not relative paths) of an SFC's blocks, in source order. */
|
|
353
|
+
function listSfcSrcRequests(parseSfc, filePath, source) {
|
|
362
354
|
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
363
|
-
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
355
|
+
return collectSrcBlocks(parseSfc, filePath, Buffer.from(source), source).map((block) => block.src).filter((src) => !isRelativeSfcSrc(src));
|
|
356
|
+
}
|
|
357
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
358
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
359
|
+
try {
|
|
360
|
+
return {
|
|
361
|
+
path: resolved,
|
|
362
|
+
content: fs.readFileSync(resolved, "utf8")
|
|
363
|
+
};
|
|
364
|
+
} catch {
|
|
365
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
366
|
+
}
|
|
364
367
|
}
|
|
365
368
|
/**
|
|
366
369
|
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
367
|
-
* source
|
|
368
|
-
*
|
|
369
|
-
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
370
|
+
* source. Blocks are located by the native parser. Module requests come from
|
|
371
|
+
* the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
370
372
|
*/
|
|
371
|
-
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
373
|
+
function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
|
|
372
374
|
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
373
375
|
source,
|
|
374
376
|
dependencies: []
|
|
@@ -376,7 +378,7 @@ function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
|
376
378
|
const bytes = Buffer.from(source);
|
|
377
379
|
const edits = [];
|
|
378
380
|
const dependencies = [];
|
|
379
|
-
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
381
|
+
for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
|
|
380
382
|
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
381
383
|
dependencies.push(file.path);
|
|
382
384
|
edits.push({
|
|
@@ -431,7 +433,7 @@ function buildSourceHash(source) {
|
|
|
431
433
|
return createHash("sha256").update(source).digest("hex");
|
|
432
434
|
}
|
|
433
435
|
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
434
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
436
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(native.parseSfc, filePath, source, srcResolutions);
|
|
435
437
|
const sourceHash = buildSourceHash(inlined);
|
|
436
438
|
const signature = buildSignature(options);
|
|
437
439
|
const cached = cache.get(filePath);
|
|
@@ -618,17 +620,17 @@ async function loadStyleBlock(context, id, options, cache) {
|
|
|
618
620
|
const block = compiled?.styles[index];
|
|
619
621
|
if (!compiled || !block) return "";
|
|
620
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;
|
|
621
624
|
const scoped = request.query.scoped;
|
|
622
|
-
|
|
623
|
-
return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
|
|
625
|
+
return scoped ? scopeCss(css, scoped) : css;
|
|
624
626
|
}
|
|
625
627
|
/**
|
|
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.
|
|
628
630
|
*/
|
|
629
|
-
function
|
|
630
|
-
if (framework !== "esbuild") return
|
|
631
|
-
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
|
|
631
|
+
function hostCss(context, framework) {
|
|
632
|
+
if (framework !== "esbuild") return "preprocessors";
|
|
633
|
+
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
632
634
|
}
|
|
633
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.";
|
|
634
636
|
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
@@ -665,7 +667,7 @@ function hostResolver(context) {
|
|
|
665
667
|
}
|
|
666
668
|
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
667
669
|
async function resolveSrcRequests(context, importer, source) {
|
|
668
|
-
const requests =
|
|
670
|
+
const requests = listSfcSrcRequests(parseSfc, importer, source);
|
|
669
671
|
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
670
672
|
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
671
673
|
}
|
|
@@ -728,7 +730,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
728
730
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
729
731
|
isProduction: options.isProduction,
|
|
730
732
|
isDev: false,
|
|
731
|
-
|
|
733
|
+
hostCss: hostCss(this, meta.framework),
|
|
732
734
|
filePath: id,
|
|
733
735
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
734
736
|
const stylePath = webpackStylePath(id, block, scoped);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
1
|
+
const require_webpack_styles = require("./webpack-styles-DVh6lFXt.cjs");
|
|
2
2
|
let node_fs = require("node:fs");
|
|
3
3
|
node_fs = require_webpack_styles.__toESM(node_fs, 1);
|
|
4
4
|
let node_module = require("node:module");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
7
|
-
let unplugin = require("unplugin");
|
|
8
|
-
let node_crypto = require("node:crypto");
|
|
9
7
|
let _vizejs_native = require("@vizejs/native");
|
|
10
8
|
_vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
|
|
9
|
+
let unplugin = require("unplugin");
|
|
10
|
+
let node_crypto = require("node:crypto");
|
|
11
11
|
let oxc_transform = require("oxc-transform");
|
|
12
12
|
//#region src/filter.ts
|
|
13
13
|
function createFilter(include, exclude) {
|
|
@@ -113,12 +113,13 @@ function isVueStyleRequest(id) {
|
|
|
113
113
|
*
|
|
114
114
|
* CSS pipelines classify a module by the extension that ends the id, and treat
|
|
115
115
|
* a query on a stylesheet path as another import kind (`?raw`, `?inline`), so
|
|
116
|
-
* the path stays the SFC and `<ext>` names what `load` returns
|
|
117
|
-
*
|
|
116
|
+
* the path stays the SFC and `<ext>` names what `load` returns. A preprocessor
|
|
117
|
+
* block arrives compiled when it is scoped (scoping follows preprocessing) or
|
|
118
|
+
* when the host compiles no preprocessor language.
|
|
118
119
|
*/
|
|
119
|
-
function styleRequestId(filePath, block, scoped) {
|
|
120
|
+
function styleRequestId(filePath, block, scoped, hostCss) {
|
|
120
121
|
const lang = block.lang ?? "css";
|
|
121
|
-
const delivered = scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
|
|
122
|
+
const delivered = (scoped !== null || hostCss !== "preprocessors") && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
|
|
122
123
|
let query = `vue&type=style&index=${block.index}`;
|
|
123
124
|
if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
|
|
124
125
|
if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
|
|
@@ -130,12 +131,14 @@ function parseVueRequest(id) {
|
|
|
130
131
|
const params = new URLSearchParams(rawQuery);
|
|
131
132
|
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
132
133
|
const indexValue = params.get("index");
|
|
134
|
+
const langKey = [...params.keys()].find((key) => key.startsWith("lang."));
|
|
133
135
|
return {
|
|
134
136
|
filename,
|
|
135
137
|
query: {
|
|
136
138
|
vue: params.has("vue"),
|
|
137
139
|
type: params.get("type"),
|
|
138
140
|
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
141
|
+
lang: langKey?.replace(/^lang\.(?:module\.)?/, "") ?? null,
|
|
139
142
|
module: moduleValue,
|
|
140
143
|
scoped: params.get("scoped")
|
|
141
144
|
}
|
|
@@ -212,7 +215,7 @@ const CSS_MODULE_LOCALS_HELPER = `const ${CSS_MODULE_LOCALS} = (ns) =>
|
|
|
212
215
|
? ns.default
|
|
213
216
|
: Object.fromEntries(Object.entries(ns).filter(([key]) => key !== "default")));`;
|
|
214
217
|
function generateOutput(compiled, options) {
|
|
215
|
-
const { isProduction, isDev,
|
|
218
|
+
const { isProduction, isDev, hostCss, filePath, styleRequest } = options;
|
|
216
219
|
let output = compiled.code;
|
|
217
220
|
const exportDefaultRegex = /^export default /m;
|
|
218
221
|
const hasExportDefault = exportDefaultRegex.test(output);
|
|
@@ -229,13 +232,13 @@ function generateOutput(compiled, options) {
|
|
|
229
232
|
output += "\n_sfc_main.render = render;";
|
|
230
233
|
output += "\nexport default _sfc_main;";
|
|
231
234
|
}
|
|
232
|
-
if (
|
|
235
|
+
if (hostCss !== "none" || hasDelegatedStyles(compiled)) {
|
|
233
236
|
const styleImports = [];
|
|
234
237
|
const cssModuleImports = [];
|
|
235
238
|
for (const block of compiled.styles) {
|
|
236
239
|
const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
|
|
237
240
|
const styleFile = styleRequest?.(block, scoped);
|
|
238
|
-
const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
|
|
241
|
+
const styleId = styleFile ?? styleRequestId(filePath, block, scoped, hostCss);
|
|
239
242
|
if (isCssModule(block)) {
|
|
240
243
|
const bindingName = typeof block.module === "string" ? block.module : "$style";
|
|
241
244
|
if (styleFile) {
|
|
@@ -298,8 +301,6 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
|
298
301
|
}
|
|
299
302
|
return resolutions;
|
|
300
303
|
}
|
|
301
|
-
//#endregion
|
|
302
|
-
//#region src/src-blocks.ts
|
|
303
304
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
304
305
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
305
306
|
/** Split an opening tag into its `src` value and the tag without it. */
|
|
@@ -322,27 +323,18 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
322
323
|
openTag: `${head}${rest}>`
|
|
323
324
|
};
|
|
324
325
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
try {
|
|
328
|
-
return {
|
|
329
|
-
path: resolved,
|
|
330
|
-
content: node_fs.default.readFileSync(resolved, "utf8")
|
|
331
|
-
};
|
|
332
|
-
} catch {
|
|
333
|
-
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
function collectSrcBlocks(filePath, bytes, source) {
|
|
326
|
+
/** The `src` blocks the native parser finds, so `src` text in scripts or comments is not one. */
|
|
327
|
+
function collectSrcBlocks(parseSfc, filePath, bytes, source) {
|
|
337
328
|
let parsed;
|
|
338
329
|
try {
|
|
339
|
-
parsed =
|
|
330
|
+
parsed = parseSfc(source, { filename: filePath });
|
|
340
331
|
} catch {
|
|
341
332
|
return [];
|
|
342
333
|
}
|
|
343
334
|
const blocks = [
|
|
344
335
|
["template", parsed.template],
|
|
345
336
|
["script", parsed.script],
|
|
337
|
+
["script", parsed.scriptSetup],
|
|
346
338
|
...parsed.styles.map((style) => ["style", style])
|
|
347
339
|
];
|
|
348
340
|
const found = [];
|
|
@@ -359,18 +351,28 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
359
351
|
}
|
|
360
352
|
return found;
|
|
361
353
|
}
|
|
362
|
-
/** The `src`
|
|
363
|
-
function
|
|
354
|
+
/** The `src` module requests (not relative paths) of an SFC's blocks, in source order. */
|
|
355
|
+
function listSfcSrcRequests(parseSfc, filePath, source) {
|
|
364
356
|
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
365
|
-
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
357
|
+
return collectSrcBlocks(parseSfc, filePath, Buffer.from(source), source).map((block) => block.src).filter((src) => !isRelativeSfcSrc(src));
|
|
358
|
+
}
|
|
359
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
360
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
361
|
+
try {
|
|
362
|
+
return {
|
|
363
|
+
path: resolved,
|
|
364
|
+
content: node_fs.default.readFileSync(resolved, "utf8")
|
|
365
|
+
};
|
|
366
|
+
} catch {
|
|
367
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
368
|
+
}
|
|
366
369
|
}
|
|
367
370
|
/**
|
|
368
371
|
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
369
|
-
* source
|
|
370
|
-
*
|
|
371
|
-
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
372
|
+
* source. Blocks are located by the native parser. Module requests come from
|
|
373
|
+
* the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
372
374
|
*/
|
|
373
|
-
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
375
|
+
function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
|
|
374
376
|
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
375
377
|
source,
|
|
376
378
|
dependencies: []
|
|
@@ -378,7 +380,7 @@ function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
|
378
380
|
const bytes = Buffer.from(source);
|
|
379
381
|
const edits = [];
|
|
380
382
|
const dependencies = [];
|
|
381
|
-
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
383
|
+
for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
|
|
382
384
|
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
383
385
|
dependencies.push(file.path);
|
|
384
386
|
edits.push({
|
|
@@ -433,7 +435,7 @@ function buildSourceHash(source) {
|
|
|
433
435
|
return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
|
|
434
436
|
}
|
|
435
437
|
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
436
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
438
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(_vizejs_native.parseSfc, filePath, source, srcResolutions);
|
|
437
439
|
const sourceHash = buildSourceHash(inlined);
|
|
438
440
|
const signature = buildSignature(options);
|
|
439
441
|
const cached = cache.get(filePath);
|
|
@@ -620,17 +622,17 @@ async function loadStyleBlock(context, id, options, cache) {
|
|
|
620
622
|
const block = compiled?.styles[index];
|
|
621
623
|
if (!compiled || !block) return "";
|
|
622
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;
|
|
623
626
|
const scoped = request.query.scoped;
|
|
624
|
-
|
|
625
|
-
return require_webpack_styles.scopeCss(block.lang && require_webpack_styles.isPreprocessorLang(block.lang) ? await require_webpack_styles.preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
|
|
627
|
+
return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
|
|
626
628
|
}
|
|
627
629
|
/**
|
|
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.
|
|
630
632
|
*/
|
|
631
|
-
function
|
|
632
|
-
if (framework !== "esbuild") return
|
|
633
|
-
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true;
|
|
633
|
+
function hostCss(context, framework) {
|
|
634
|
+
if (framework !== "esbuild") return "preprocessors";
|
|
635
|
+
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
634
636
|
}
|
|
635
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.";
|
|
636
638
|
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
@@ -667,7 +669,7 @@ function hostResolver(context) {
|
|
|
667
669
|
}
|
|
668
670
|
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
669
671
|
async function resolveSrcRequests(context, importer, source) {
|
|
670
|
-
const requests =
|
|
672
|
+
const requests = listSfcSrcRequests(_vizejs_native.parseSfc, importer, source);
|
|
671
673
|
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
672
674
|
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
673
675
|
}
|
|
@@ -730,7 +732,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
730
732
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
731
733
|
isProduction: options.isProduction,
|
|
732
734
|
isDev: false,
|
|
733
|
-
|
|
735
|
+
hostCss: hostCss(this, meta.framework),
|
|
734
736
|
filePath: id,
|
|
735
737
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
736
738
|
const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
|
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
5
|
+
const require_webpack_styles = require("./webpack-styles-DVh6lFXt.cjs");
|
|
6
6
|
//#region src/webpack-style-loader.ts
|
|
7
7
|
const SCOPE_QUERY = "?scope";
|
|
8
8
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-
|
|
1
|
+
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-CoRj2un6.mjs";
|
|
2
2
|
//#region src/webpack-style-loader.ts
|
|
3
3
|
const SCOPE_QUERY = "?scope";
|
|
4
4
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -32,7 +32,7 @@ function loadPreprocessor(root, names, lang) {
|
|
|
32
32
|
} catch (error) {
|
|
33
33
|
if (error.code !== "MODULE_NOT_FOUND") throw error;
|
|
34
34
|
}
|
|
35
|
-
throw new Error(`[vize] <style
|
|
35
|
+
throw new Error(`[vize] <style lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
|
|
36
36
|
}
|
|
37
37
|
async function preprocessStyle(source, lang, filename, root) {
|
|
38
38
|
const dir = path.dirname(filename);
|
|
@@ -55,7 +55,7 @@ function loadPreprocessor(root, names, lang) {
|
|
|
55
55
|
} catch (error) {
|
|
56
56
|
if (error.code !== "MODULE_NOT_FOUND") throw error;
|
|
57
57
|
}
|
|
58
|
-
throw new Error(`[vize] <style
|
|
58
|
+
throw new Error(`[vize] <style lang="${lang}"> needs ${names.join(" or ")} installed in ${root}.`);
|
|
59
59
|
}
|
|
60
60
|
async function preprocessStyle(source, lang, filename, root) {
|
|
61
61
|
const dir = node_path.default.dirname(filename);
|
package/dist/webpack.cjs
CHANGED
package/dist/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/unplugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.665.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.
|
|
71
|
+
"@vizejs/native": "0.665.0",
|
|
72
72
|
"oxc-transform": "0.144.0",
|
|
73
73
|
"unplugin": "3.3.0"
|
|
74
74
|
},
|