@vizejs/unplugin 0.660.0 → 0.662.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 +2 -2
- package/dist/babel.cjs +1 -1
- package/dist/babel.mjs +1 -1
- 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-DPYDTPhZ.mjs → unplugin-BbWP410q.mjs} +167 -107
- package/dist/{unplugin-BErqvAH5.cjs → unplugin-Dl8hs9VI.cjs} +168 -108
- package/dist/webpack-style-loader.cjs +1 -1
- package/dist/webpack-style-loader.mjs +1 -1
- package/dist/{webpack-styles-ClGUhlPP.mjs → webpack-styles-Ca7spvMb.mjs} +4 -3
- package/dist/{webpack-styles-BzhQ3HGs.cjs → webpack-styles-IFEnxDay.cjs} +4 -3
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -116,9 +116,9 @@ 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
|
- Plain inline CSS is injected into JavaScript at runtime; CSS asset extraction and SSR stylesheet delivery are not provided by this path.
|
|
119
|
-
- `<style src>`, `<script src>` and `<template src>`
|
|
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
|
- `@import` in plain CSS is a build error. Plain CSS is injected at runtime as a string, so an `@import` would be fetched relative to the page. Inline the imported CSS, move the block to a preprocessor or CSS Module (handled by the host CSS pipeline), or use `@vizejs/vite-plugin`.
|
|
121
|
-
- CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
|
|
121
|
+
- CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path. Each block is a module 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 (`@tsdown/css`, `rollup-plugin-postcss`, esbuild) handles the block, and a host without one reports the same error it reports for such a file.
|
|
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`.
|
|
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
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-BbWP410q.mjs";
|
|
2
2
|
//#region src/babel.ts
|
|
3
3
|
function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
4
4
|
const options = normalizeOptions(rawOptions);
|
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-Dl8hs9VI.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-BbWP410q.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-Ca7spvMb.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
4
5
|
import { createUnplugin } from "unplugin";
|
|
5
6
|
import { createHash } from "node:crypto";
|
|
6
7
|
import * as native from "@vizejs/native";
|
|
7
8
|
import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
|
|
8
|
-
import path from "node:path";
|
|
9
9
|
import { transform } from "oxc-transform";
|
|
10
10
|
//#region src/filter.ts
|
|
11
11
|
function createFilter(include, exclude) {
|
|
@@ -93,6 +93,53 @@ function prependMappedJsxCode(code, mapJson, prefix) {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
//#endregion
|
|
96
|
+
//#region src/request.ts
|
|
97
|
+
function isVueFile(id) {
|
|
98
|
+
return id.endsWith(".vue");
|
|
99
|
+
}
|
|
100
|
+
function isJsxFile(id) {
|
|
101
|
+
return id.endsWith(".jsx") || id.endsWith(".tsx");
|
|
102
|
+
}
|
|
103
|
+
function isVueStyleRequest(id) {
|
|
104
|
+
if (!id.includes("?vue")) return false;
|
|
105
|
+
const { query } = parseVueRequest(id);
|
|
106
|
+
return query.vue && query.type === "style";
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The module id of a delegated style block, in Vue's request shape:
|
|
110
|
+
* `App.vue?vue&type=style&index=0[&scoped=…][&module[=name]]&lang.<ext>`.
|
|
111
|
+
*
|
|
112
|
+
* CSS pipelines classify a module by the extension that ends the id, and treat
|
|
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: a scoped
|
|
115
|
+
* preprocessor block is compiled before scoping, so it is CSS.
|
|
116
|
+
*/
|
|
117
|
+
function styleRequestId(filePath, block, scoped) {
|
|
118
|
+
const lang = block.lang ?? "css";
|
|
119
|
+
const delivered = scoped && isPreprocessorLang(lang) ? "css" : lang;
|
|
120
|
+
let query = `vue&type=style&index=${block.index}`;
|
|
121
|
+
if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
|
|
122
|
+
if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
|
|
123
|
+
const ext = block.module === false ? delivered : `module.${delivered}`;
|
|
124
|
+
return `${filePath}?${query}&lang.${ext}`;
|
|
125
|
+
}
|
|
126
|
+
function parseVueRequest(id) {
|
|
127
|
+
const [filename, rawQuery = ""] = id.split("?", 2);
|
|
128
|
+
const params = new URLSearchParams(rawQuery);
|
|
129
|
+
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
130
|
+
const indexValue = params.get("index");
|
|
131
|
+
return {
|
|
132
|
+
filename,
|
|
133
|
+
query: {
|
|
134
|
+
vue: params.has("vue"),
|
|
135
|
+
type: params.get("type"),
|
|
136
|
+
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
137
|
+
module: moduleValue,
|
|
138
|
+
scoped: params.get("scoped")
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
96
143
|
//#region src/style.ts
|
|
97
144
|
function needsPreprocessor(block) {
|
|
98
145
|
return isPreprocessorLang(block.lang);
|
|
@@ -166,27 +213,16 @@ function generateOutput(compiled, options) {
|
|
|
166
213
|
const styleImports = [];
|
|
167
214
|
const cssModuleImports = [];
|
|
168
215
|
for (const block of compiled.styles) {
|
|
169
|
-
const lang = block.lang ?? "css";
|
|
170
|
-
const params = new URLSearchParams();
|
|
171
|
-
params.set("vue", "");
|
|
172
|
-
params.set("type", "style");
|
|
173
|
-
params.set("index", String(block.index));
|
|
174
|
-
params.set("lang", lang);
|
|
175
|
-
if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
|
|
176
216
|
const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
|
|
177
217
|
const styleFile = styleRequest?.(block, scoped);
|
|
218
|
+
const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
|
|
178
219
|
if (isCssModule(block)) {
|
|
179
220
|
const bindingName = typeof block.module === "string" ? block.module : "$style";
|
|
180
221
|
if (styleFile) {
|
|
181
222
|
const namespace = `__vize_css_module_${block.index}__`;
|
|
182
223
|
cssModuleImports.push(`import * as ${namespace} from ${JSON.stringify(styleFile)};`, `const ${bindingName} = ${CSS_MODULE_LOCALS}(${namespace});`);
|
|
183
|
-
} else {
|
|
184
|
-
|
|
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()}`)};`);
|
|
224
|
+
} else cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(styleId)};`);
|
|
225
|
+
} else styleImports.push(`import ${JSON.stringify(styleId)};`);
|
|
190
226
|
}
|
|
191
227
|
if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
|
|
192
228
|
const allImports = [...styleImports, ...cssModuleImports].join("\n");
|
|
@@ -227,6 +263,33 @@ function assertSupportedStyleDependencies(styles, filename) {
|
|
|
227
263
|
}
|
|
228
264
|
}
|
|
229
265
|
//#endregion
|
|
266
|
+
//#region ../shared/sfc-src.ts
|
|
267
|
+
/**
|
|
268
|
+
* Whether a block `src` is a path relative to the SFC. Any other `src`
|
|
269
|
+
* (package, alias, absolute) is a module request that the bundler resolves,
|
|
270
|
+
* as in Vue's SFC spec and `@vitejs/plugin-vue`.
|
|
271
|
+
*/
|
|
272
|
+
function isRelativeSfcSrc(src) {
|
|
273
|
+
return src.startsWith("./") || src.startsWith("../");
|
|
274
|
+
}
|
|
275
|
+
/** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
|
|
276
|
+
function sfcSrcFile(importer, tag, src, resolutions) {
|
|
277
|
+
if (isRelativeSfcSrc(src)) return path.resolve(path.dirname(importer), src);
|
|
278
|
+
const file = resolutions?.get(src);
|
|
279
|
+
if (file !== void 0) return file;
|
|
280
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
|
|
281
|
+
}
|
|
282
|
+
/** Resolve an SFC's `src` module requests with the bundler's own resolver. */
|
|
283
|
+
async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
284
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
285
|
+
for (const request of new Set(requests)) {
|
|
286
|
+
if (isRelativeSfcSrc(request)) continue;
|
|
287
|
+
const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
|
|
288
|
+
if (file && path.isAbsolute(file)) resolutions.set(request, file);
|
|
289
|
+
}
|
|
290
|
+
return resolutions;
|
|
291
|
+
}
|
|
292
|
+
//#endregion
|
|
230
293
|
//#region src/src-blocks.ts
|
|
231
294
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
232
295
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
@@ -250,8 +313,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
250
313
|
openTag: `${head}${rest}>`
|
|
251
314
|
};
|
|
252
315
|
}
|
|
253
|
-
function readSrcBlock(filePath, tag, src) {
|
|
254
|
-
const resolved =
|
|
316
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
317
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
255
318
|
try {
|
|
256
319
|
return {
|
|
257
320
|
path: resolved,
|
|
@@ -261,44 +324,58 @@ function readSrcBlock(filePath, tag, src) {
|
|
|
261
324
|
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
262
325
|
}
|
|
263
326
|
}
|
|
264
|
-
|
|
265
|
-
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
266
|
-
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
267
|
-
* parser, so `src` text inside scripts or comments is left alone.
|
|
268
|
-
*/
|
|
269
|
-
function inlineSfcSrcBlocks(filePath, source) {
|
|
270
|
-
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
271
|
-
source,
|
|
272
|
-
dependencies: []
|
|
273
|
-
};
|
|
327
|
+
function collectSrcBlocks(filePath, bytes, source) {
|
|
274
328
|
let parsed;
|
|
275
329
|
try {
|
|
276
330
|
parsed = parseSfc(source, { filename: filePath });
|
|
277
331
|
} catch {
|
|
278
|
-
return
|
|
279
|
-
source,
|
|
280
|
-
dependencies: []
|
|
281
|
-
};
|
|
332
|
+
return [];
|
|
282
333
|
}
|
|
283
334
|
const blocks = [
|
|
284
335
|
["template", parsed.template],
|
|
285
336
|
["script", parsed.script],
|
|
286
337
|
...parsed.styles.map((style) => ["style", style])
|
|
287
338
|
];
|
|
288
|
-
const
|
|
289
|
-
const edits = [];
|
|
290
|
-
const dependencies = [];
|
|
339
|
+
const found = [];
|
|
291
340
|
for (const [tag, block] of blocks) {
|
|
292
341
|
if (!block) continue;
|
|
293
342
|
const { start, tagStart, tagEnd } = block.loc;
|
|
294
343
|
const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
|
|
295
|
-
if (
|
|
296
|
-
|
|
344
|
+
if (split) found.push({
|
|
345
|
+
tag,
|
|
346
|
+
...split,
|
|
347
|
+
tagStart,
|
|
348
|
+
tagEnd
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return found;
|
|
352
|
+
}
|
|
353
|
+
/** The `src` values of an SFC's blocks, in source order. */
|
|
354
|
+
function listSfcSrcBlocks(filePath, source) {
|
|
355
|
+
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
356
|
+
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
360
|
+
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
361
|
+
* parser, so `src` text inside scripts or comments is left alone. Module
|
|
362
|
+
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
363
|
+
*/
|
|
364
|
+
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
365
|
+
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
366
|
+
source,
|
|
367
|
+
dependencies: []
|
|
368
|
+
};
|
|
369
|
+
const bytes = Buffer.from(source);
|
|
370
|
+
const edits = [];
|
|
371
|
+
const dependencies = [];
|
|
372
|
+
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
373
|
+
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
297
374
|
dependencies.push(file.path);
|
|
298
375
|
edits.push({
|
|
299
|
-
start: tagStart,
|
|
300
|
-
end: tagEnd,
|
|
301
|
-
text: `${
|
|
376
|
+
start: block.tagStart,
|
|
377
|
+
end: block.tagEnd,
|
|
378
|
+
text: `${block.openTag}\n${file.content}\n</${block.tag}>`
|
|
302
379
|
});
|
|
303
380
|
}
|
|
304
381
|
if (edits.length === 0) return {
|
|
@@ -346,8 +423,8 @@ function buildSignature(options) {
|
|
|
346
423
|
function buildSourceHash(source) {
|
|
347
424
|
return createHash("sha256").update(source).digest("hex");
|
|
348
425
|
}
|
|
349
|
-
function compileVueModule(filePath, source, options, cache) {
|
|
350
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
|
|
426
|
+
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
427
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
351
428
|
const sourceHash = buildSourceHash(inlined);
|
|
352
429
|
const signature = buildSignature(options);
|
|
353
430
|
const cached = cache.get(filePath);
|
|
@@ -374,7 +451,9 @@ function compileVueModule(filePath, source, options, cache) {
|
|
|
374
451
|
runtimeModuleName: options.runtimeModuleName,
|
|
375
452
|
runtimeGlobalName: options.runtimeGlobalName,
|
|
376
453
|
vueVersion: String(options.vueVersion),
|
|
377
|
-
scopeId: `data-v-${scopeId}
|
|
454
|
+
scopeId: `data-v-${scopeId}`,
|
|
455
|
+
isProd: options.isProduction,
|
|
456
|
+
inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
|
|
378
457
|
});
|
|
379
458
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
380
459
|
assertSupportedStyleDependencies(result.styles, filePath);
|
|
@@ -424,59 +503,6 @@ function compileJsxModule(filePath, source, options) {
|
|
|
424
503
|
};
|
|
425
504
|
}
|
|
426
505
|
//#endregion
|
|
427
|
-
//#region src/request.ts
|
|
428
|
-
const STYLE_MARKER = ".__vize_style_";
|
|
429
|
-
function isVueFile(id) {
|
|
430
|
-
return id.endsWith(".vue");
|
|
431
|
-
}
|
|
432
|
-
function isJsxFile(id) {
|
|
433
|
-
return id.endsWith(".jsx") || id.endsWith(".tsx");
|
|
434
|
-
}
|
|
435
|
-
function isVueStyleRequest(id) {
|
|
436
|
-
if (!id.includes("?vue")) return false;
|
|
437
|
-
const { query } = parseVueRequest(id);
|
|
438
|
-
return query.vue && query.type === "style";
|
|
439
|
-
}
|
|
440
|
-
function isVirtualStyleId(id) {
|
|
441
|
-
return id.includes(STYLE_MARKER);
|
|
442
|
-
}
|
|
443
|
-
function parseVueRequest(id) {
|
|
444
|
-
const [path, rawQuery = ""] = id.split("?", 2);
|
|
445
|
-
const params = new URLSearchParams(rawQuery);
|
|
446
|
-
const filename = params.get("vize-file") ?? path;
|
|
447
|
-
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
448
|
-
const indexValue = params.get("index");
|
|
449
|
-
return {
|
|
450
|
-
filename,
|
|
451
|
-
path,
|
|
452
|
-
query: {
|
|
453
|
-
vue: params.has("vue"),
|
|
454
|
-
type: params.get("type"),
|
|
455
|
-
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
456
|
-
lang: params.get("lang"),
|
|
457
|
-
module: moduleValue,
|
|
458
|
-
scoped: params.get("scoped"),
|
|
459
|
-
vizeFile: params.get("vize-file")
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
function createVirtualStyleId(id) {
|
|
464
|
-
const { filename, query } = parseVueRequest(id);
|
|
465
|
-
const index = query.index ?? 0;
|
|
466
|
-
const lang = query.lang ?? "css";
|
|
467
|
-
const fileLang = query.scoped && isPreprocessorLang(lang) ? "css" : lang;
|
|
468
|
-
const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
|
|
469
|
-
const params = new URLSearchParams();
|
|
470
|
-
params.set("vue", "");
|
|
471
|
-
params.set("type", "style");
|
|
472
|
-
params.set("index", String(index));
|
|
473
|
-
params.set("lang", lang);
|
|
474
|
-
params.set("vize-file", filename);
|
|
475
|
-
if (query.scoped) params.set("scoped", query.scoped);
|
|
476
|
-
if (query.module !== false) params.set("module", typeof query.module === "string" ? query.module : "");
|
|
477
|
-
return `${filename}${STYLE_MARKER}${index}${suffix}?${params.toString()}`;
|
|
478
|
-
}
|
|
479
|
-
//#endregion
|
|
480
506
|
//#region src/strip-types.ts
|
|
481
507
|
function formatErrorMessage(error) {
|
|
482
508
|
const parts = [error.message];
|
|
@@ -572,22 +598,57 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
572
598
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
573
599
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
574
600
|
}
|
|
575
|
-
async function loadStyleBlock(id, options, cache) {
|
|
601
|
+
async function loadStyleBlock(context, id, options, cache) {
|
|
576
602
|
const request = parseVueRequest(id);
|
|
577
603
|
const index = request.query.index ?? -1;
|
|
578
604
|
if (index < 0) return "";
|
|
579
605
|
let compiled = cache.get(request.filename)?.compiled;
|
|
580
606
|
if (!compiled && fs.existsSync(request.filename)) {
|
|
581
607
|
const source = fs.readFileSync(request.filename, "utf8");
|
|
582
|
-
|
|
608
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
609
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
583
610
|
}
|
|
584
611
|
const block = compiled?.styles[index];
|
|
585
612
|
if (!compiled || !block) return "";
|
|
586
|
-
const source = transformStyleVars(block.content, compiled.scopeId);
|
|
613
|
+
const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
587
614
|
const scoped = request.query.scoped;
|
|
588
615
|
if (!scoped) return source;
|
|
589
616
|
return scopeCss(block.lang && isPreprocessorLang(block.lang) ? await preprocessStyle(source, block.lang, request.filename, options.root) : source, scoped);
|
|
590
617
|
}
|
|
618
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
619
|
+
function hostResolver(context) {
|
|
620
|
+
const ctx = context;
|
|
621
|
+
if (typeof ctx.resolve === "function") {
|
|
622
|
+
const resolve = ctx.resolve;
|
|
623
|
+
return async (request, importer) => {
|
|
624
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
625
|
+
return result && !result.external ? result.id : null;
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
const native = ctx.getNativeBuildContext?.();
|
|
629
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
630
|
+
const resolve = native.loaderContext.getResolve();
|
|
631
|
+
return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
|
|
632
|
+
}
|
|
633
|
+
if (native && "build" in native) {
|
|
634
|
+
const { build } = native;
|
|
635
|
+
return async (request, importer) => {
|
|
636
|
+
const result = await build.resolve(request, {
|
|
637
|
+
kind: "import-statement",
|
|
638
|
+
resolveDir: path.dirname(importer),
|
|
639
|
+
importer
|
|
640
|
+
});
|
|
641
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
647
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
648
|
+
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
649
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
650
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
651
|
+
}
|
|
591
652
|
const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
592
653
|
const options = normalizeOptions(rawOptions);
|
|
593
654
|
const filter = createFilter(options.include, options.exclude);
|
|
@@ -598,18 +659,17 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
598
659
|
name: "unplugin-vize",
|
|
599
660
|
resolveId(id) {
|
|
600
661
|
if (options.hostCompiler) return null;
|
|
601
|
-
|
|
602
|
-
return null;
|
|
662
|
+
return isVueStyleRequest(id) ? id : null;
|
|
603
663
|
},
|
|
604
664
|
loadInclude(id) {
|
|
605
665
|
if (options.hostCompiler) return false;
|
|
606
|
-
return !webpackStyleFiles &&
|
|
666
|
+
return !webpackStyleFiles && isVueStyleRequest(id);
|
|
607
667
|
},
|
|
608
668
|
async load(id) {
|
|
609
669
|
if (options.hostCompiler) return null;
|
|
610
|
-
if (!
|
|
670
|
+
if (!isVueStyleRequest(id)) return null;
|
|
611
671
|
return {
|
|
612
|
-
code: await loadStyleBlock(id, options, cache),
|
|
672
|
+
code: await loadStyleBlock(this, id, options, cache),
|
|
613
673
|
map: null
|
|
614
674
|
};
|
|
615
675
|
},
|
|
@@ -632,7 +692,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
632
692
|
};
|
|
633
693
|
}
|
|
634
694
|
if (!isVueFile(id) || !filter(id)) return null;
|
|
635
|
-
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
|
|
695
|
+
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache, await resolveSrcRequests(this, id, code));
|
|
636
696
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
637
697
|
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
638
698
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
@@ -642,7 +702,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
642
702
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
643
703
|
const stylePath = webpackStylePath(id, block, scoped);
|
|
644
704
|
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
645
|
-
virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId));
|
|
705
|
+
virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
646
706
|
return webpackStyleRequest(stylePath, block);
|
|
647
707
|
} : void 0
|
|
648
708
|
}), options.sourceMap);
|
|
@@ -663,7 +723,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
663
723
|
},
|
|
664
724
|
esbuild: {
|
|
665
725
|
onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
|
|
666
|
-
onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)
|
|
726
|
+
onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
|
|
667
727
|
loader(_code, id) {
|
|
668
728
|
const request = parseVueRequest(id);
|
|
669
729
|
if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
1
|
+
const require_webpack_styles = require("./webpack-styles-IFEnxDay.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
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
5
7
|
let unplugin = require("unplugin");
|
|
6
8
|
let node_crypto = require("node:crypto");
|
|
7
9
|
let _vizejs_native = require("@vizejs/native");
|
|
8
10
|
_vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
|
|
9
|
-
let node_path = require("node:path");
|
|
10
|
-
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
11
11
|
let oxc_transform = require("oxc-transform");
|
|
12
12
|
//#region src/filter.ts
|
|
13
13
|
function createFilter(include, exclude) {
|
|
@@ -95,6 +95,53 @@ function prependMappedJsxCode(code, mapJson, prefix) {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
//#endregion
|
|
98
|
+
//#region src/request.ts
|
|
99
|
+
function isVueFile(id) {
|
|
100
|
+
return id.endsWith(".vue");
|
|
101
|
+
}
|
|
102
|
+
function isJsxFile(id) {
|
|
103
|
+
return id.endsWith(".jsx") || id.endsWith(".tsx");
|
|
104
|
+
}
|
|
105
|
+
function isVueStyleRequest(id) {
|
|
106
|
+
if (!id.includes("?vue")) return false;
|
|
107
|
+
const { query } = parseVueRequest(id);
|
|
108
|
+
return query.vue && query.type === "style";
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The module id of a delegated style block, in Vue's request shape:
|
|
112
|
+
* `App.vue?vue&type=style&index=0[&scoped=…][&module[=name]]&lang.<ext>`.
|
|
113
|
+
*
|
|
114
|
+
* CSS pipelines classify a module by the extension that ends the id, and treat
|
|
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: a scoped
|
|
117
|
+
* preprocessor block is compiled before scoping, so it is CSS.
|
|
118
|
+
*/
|
|
119
|
+
function styleRequestId(filePath, block, scoped) {
|
|
120
|
+
const lang = block.lang ?? "css";
|
|
121
|
+
const delivered = scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
|
|
122
|
+
let query = `vue&type=style&index=${block.index}`;
|
|
123
|
+
if (scoped) query += `&scoped=${encodeURIComponent(scoped)}`;
|
|
124
|
+
if (block.module !== false) query += typeof block.module === "string" ? `&module=${encodeURIComponent(block.module)}` : "&module";
|
|
125
|
+
const ext = block.module === false ? delivered : `module.${delivered}`;
|
|
126
|
+
return `${filePath}?${query}&lang.${ext}`;
|
|
127
|
+
}
|
|
128
|
+
function parseVueRequest(id) {
|
|
129
|
+
const [filename, rawQuery = ""] = id.split("?", 2);
|
|
130
|
+
const params = new URLSearchParams(rawQuery);
|
|
131
|
+
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
132
|
+
const indexValue = params.get("index");
|
|
133
|
+
return {
|
|
134
|
+
filename,
|
|
135
|
+
query: {
|
|
136
|
+
vue: params.has("vue"),
|
|
137
|
+
type: params.get("type"),
|
|
138
|
+
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
139
|
+
module: moduleValue,
|
|
140
|
+
scoped: params.get("scoped")
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
98
145
|
//#region src/style.ts
|
|
99
146
|
function needsPreprocessor(block) {
|
|
100
147
|
return require_webpack_styles.isPreprocessorLang(block.lang);
|
|
@@ -168,27 +215,16 @@ function generateOutput(compiled, options) {
|
|
|
168
215
|
const styleImports = [];
|
|
169
216
|
const cssModuleImports = [];
|
|
170
217
|
for (const block of compiled.styles) {
|
|
171
|
-
const lang = block.lang ?? "css";
|
|
172
|
-
const params = new URLSearchParams();
|
|
173
|
-
params.set("vue", "");
|
|
174
|
-
params.set("type", "style");
|
|
175
|
-
params.set("index", String(block.index));
|
|
176
|
-
params.set("lang", lang);
|
|
177
|
-
if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
|
|
178
218
|
const scoped = block.scoped ? `data-v-${compiled.scopeId}` : null;
|
|
179
219
|
const styleFile = styleRequest?.(block, scoped);
|
|
220
|
+
const styleId = styleFile ?? styleRequestId(filePath, block, scoped);
|
|
180
221
|
if (isCssModule(block)) {
|
|
181
222
|
const bindingName = typeof block.module === "string" ? block.module : "$style";
|
|
182
223
|
if (styleFile) {
|
|
183
224
|
const namespace = `__vize_css_module_${block.index}__`;
|
|
184
225
|
cssModuleImports.push(`import * as ${namespace} from ${JSON.stringify(styleFile)};`, `const ${bindingName} = ${CSS_MODULE_LOCALS}(${namespace});`);
|
|
185
|
-
} else {
|
|
186
|
-
|
|
187
|
-
moduleParams.set("module", typeof block.module === "string" ? block.module : "");
|
|
188
|
-
const moduleUrl = `${filePath}?${moduleParams.toString()}`;
|
|
189
|
-
cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(moduleUrl)};`);
|
|
190
|
-
}
|
|
191
|
-
} else styleImports.push(`import ${JSON.stringify(styleFile ?? `${filePath}?${params.toString()}`)};`);
|
|
226
|
+
} else cssModuleImports.push(`import ${bindingName} from ${JSON.stringify(styleId)};`);
|
|
227
|
+
} else styleImports.push(`import ${JSON.stringify(styleId)};`);
|
|
192
228
|
}
|
|
193
229
|
if (cssModuleImports.some((line) => line.includes(CSS_MODULE_LOCALS))) cssModuleImports.unshift(CSS_MODULE_LOCALS_HELPER);
|
|
194
230
|
const allImports = [...styleImports, ...cssModuleImports].join("\n");
|
|
@@ -229,6 +265,33 @@ function assertSupportedStyleDependencies(styles, filename) {
|
|
|
229
265
|
}
|
|
230
266
|
}
|
|
231
267
|
//#endregion
|
|
268
|
+
//#region ../shared/sfc-src.ts
|
|
269
|
+
/**
|
|
270
|
+
* Whether a block `src` is a path relative to the SFC. Any other `src`
|
|
271
|
+
* (package, alias, absolute) is a module request that the bundler resolves,
|
|
272
|
+
* as in Vue's SFC spec and `@vitejs/plugin-vue`.
|
|
273
|
+
*/
|
|
274
|
+
function isRelativeSfcSrc(src) {
|
|
275
|
+
return src.startsWith("./") || src.startsWith("../");
|
|
276
|
+
}
|
|
277
|
+
/** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
|
|
278
|
+
function sfcSrcFile(importer, tag, src, resolutions) {
|
|
279
|
+
if (isRelativeSfcSrc(src)) return node_path.default.resolve(node_path.default.dirname(importer), src);
|
|
280
|
+
const file = resolutions?.get(src);
|
|
281
|
+
if (file !== void 0) return file;
|
|
282
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
|
|
283
|
+
}
|
|
284
|
+
/** Resolve an SFC's `src` module requests with the bundler's own resolver. */
|
|
285
|
+
async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
286
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
287
|
+
for (const request of new Set(requests)) {
|
|
288
|
+
if (isRelativeSfcSrc(request)) continue;
|
|
289
|
+
const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
|
|
290
|
+
if (file && node_path.default.isAbsolute(file)) resolutions.set(request, file);
|
|
291
|
+
}
|
|
292
|
+
return resolutions;
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
232
295
|
//#region src/src-blocks.ts
|
|
233
296
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
234
297
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
@@ -252,8 +315,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
252
315
|
openTag: `${head}${rest}>`
|
|
253
316
|
};
|
|
254
317
|
}
|
|
255
|
-
function readSrcBlock(filePath, tag, src) {
|
|
256
|
-
const resolved =
|
|
318
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
319
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
257
320
|
try {
|
|
258
321
|
return {
|
|
259
322
|
path: resolved,
|
|
@@ -263,44 +326,58 @@ function readSrcBlock(filePath, tag, src) {
|
|
|
263
326
|
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
264
327
|
}
|
|
265
328
|
}
|
|
266
|
-
|
|
267
|
-
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
268
|
-
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
269
|
-
* parser, so `src` text inside scripts or comments is left alone.
|
|
270
|
-
*/
|
|
271
|
-
function inlineSfcSrcBlocks(filePath, source) {
|
|
272
|
-
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
273
|
-
source,
|
|
274
|
-
dependencies: []
|
|
275
|
-
};
|
|
329
|
+
function collectSrcBlocks(filePath, bytes, source) {
|
|
276
330
|
let parsed;
|
|
277
331
|
try {
|
|
278
332
|
parsed = (0, _vizejs_native.parseSfc)(source, { filename: filePath });
|
|
279
333
|
} catch {
|
|
280
|
-
return
|
|
281
|
-
source,
|
|
282
|
-
dependencies: []
|
|
283
|
-
};
|
|
334
|
+
return [];
|
|
284
335
|
}
|
|
285
336
|
const blocks = [
|
|
286
337
|
["template", parsed.template],
|
|
287
338
|
["script", parsed.script],
|
|
288
339
|
...parsed.styles.map((style) => ["style", style])
|
|
289
340
|
];
|
|
290
|
-
const
|
|
291
|
-
const edits = [];
|
|
292
|
-
const dependencies = [];
|
|
341
|
+
const found = [];
|
|
293
342
|
for (const [tag, block] of blocks) {
|
|
294
343
|
if (!block) continue;
|
|
295
344
|
const { start, tagStart, tagEnd } = block.loc;
|
|
296
345
|
const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
|
|
297
|
-
if (
|
|
298
|
-
|
|
346
|
+
if (split) found.push({
|
|
347
|
+
tag,
|
|
348
|
+
...split,
|
|
349
|
+
tagStart,
|
|
350
|
+
tagEnd
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return found;
|
|
354
|
+
}
|
|
355
|
+
/** The `src` values of an SFC's blocks, in source order. */
|
|
356
|
+
function listSfcSrcBlocks(filePath, source) {
|
|
357
|
+
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
358
|
+
return collectSrcBlocks(filePath, Buffer.from(source), source).map((block) => block.src);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
362
|
+
* source, as `@vizejs/vite-plugin` does. Blocks are located by the native
|
|
363
|
+
* parser, so `src` text inside scripts or comments is left alone. Module
|
|
364
|
+
* requests come from the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
365
|
+
*/
|
|
366
|
+
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
367
|
+
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
368
|
+
source,
|
|
369
|
+
dependencies: []
|
|
370
|
+
};
|
|
371
|
+
const bytes = Buffer.from(source);
|
|
372
|
+
const edits = [];
|
|
373
|
+
const dependencies = [];
|
|
374
|
+
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
375
|
+
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
299
376
|
dependencies.push(file.path);
|
|
300
377
|
edits.push({
|
|
301
|
-
start: tagStart,
|
|
302
|
-
end: tagEnd,
|
|
303
|
-
text: `${
|
|
378
|
+
start: block.tagStart,
|
|
379
|
+
end: block.tagEnd,
|
|
380
|
+
text: `${block.openTag}\n${file.content}\n</${block.tag}>`
|
|
304
381
|
});
|
|
305
382
|
}
|
|
306
383
|
if (edits.length === 0) return {
|
|
@@ -348,8 +425,8 @@ function buildSignature(options) {
|
|
|
348
425
|
function buildSourceHash(source) {
|
|
349
426
|
return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
|
|
350
427
|
}
|
|
351
|
-
function compileVueModule(filePath, source, options, cache) {
|
|
352
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
|
|
428
|
+
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
429
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
353
430
|
const sourceHash = buildSourceHash(inlined);
|
|
354
431
|
const signature = buildSignature(options);
|
|
355
432
|
const cached = cache.get(filePath);
|
|
@@ -376,7 +453,9 @@ function compileVueModule(filePath, source, options, cache) {
|
|
|
376
453
|
runtimeModuleName: options.runtimeModuleName,
|
|
377
454
|
runtimeGlobalName: options.runtimeGlobalName,
|
|
378
455
|
vueVersion: String(options.vueVersion),
|
|
379
|
-
scopeId: `data-v-${scopeId}
|
|
456
|
+
scopeId: `data-v-${scopeId}`,
|
|
457
|
+
isProd: options.isProduction,
|
|
458
|
+
inlineTemplate: options.isProduction && !options.ssr && options.mode !== "function"
|
|
380
459
|
});
|
|
381
460
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
382
461
|
assertSupportedStyleDependencies(result.styles, filePath);
|
|
@@ -426,59 +505,6 @@ function compileJsxModule(filePath, source, options) {
|
|
|
426
505
|
};
|
|
427
506
|
}
|
|
428
507
|
//#endregion
|
|
429
|
-
//#region src/request.ts
|
|
430
|
-
const STYLE_MARKER = ".__vize_style_";
|
|
431
|
-
function isVueFile(id) {
|
|
432
|
-
return id.endsWith(".vue");
|
|
433
|
-
}
|
|
434
|
-
function isJsxFile(id) {
|
|
435
|
-
return id.endsWith(".jsx") || id.endsWith(".tsx");
|
|
436
|
-
}
|
|
437
|
-
function isVueStyleRequest(id) {
|
|
438
|
-
if (!id.includes("?vue")) return false;
|
|
439
|
-
const { query } = parseVueRequest(id);
|
|
440
|
-
return query.vue && query.type === "style";
|
|
441
|
-
}
|
|
442
|
-
function isVirtualStyleId(id) {
|
|
443
|
-
return id.includes(STYLE_MARKER);
|
|
444
|
-
}
|
|
445
|
-
function parseVueRequest(id) {
|
|
446
|
-
const [path, rawQuery = ""] = id.split("?", 2);
|
|
447
|
-
const params = new URLSearchParams(rawQuery);
|
|
448
|
-
const filename = params.get("vize-file") ?? path;
|
|
449
|
-
const moduleValue = params.has("module") ? params.get("module") || true : false;
|
|
450
|
-
const indexValue = params.get("index");
|
|
451
|
-
return {
|
|
452
|
-
filename,
|
|
453
|
-
path,
|
|
454
|
-
query: {
|
|
455
|
-
vue: params.has("vue"),
|
|
456
|
-
type: params.get("type"),
|
|
457
|
-
index: indexValue === null ? null : Number.parseInt(indexValue, 10),
|
|
458
|
-
lang: params.get("lang"),
|
|
459
|
-
module: moduleValue,
|
|
460
|
-
scoped: params.get("scoped"),
|
|
461
|
-
vizeFile: params.get("vize-file")
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
function createVirtualStyleId(id) {
|
|
466
|
-
const { filename, query } = parseVueRequest(id);
|
|
467
|
-
const index = query.index ?? 0;
|
|
468
|
-
const lang = query.lang ?? "css";
|
|
469
|
-
const fileLang = query.scoped && require_webpack_styles.isPreprocessorLang(lang) ? "css" : lang;
|
|
470
|
-
const suffix = query.module !== false ? `.module.${fileLang}` : `.${fileLang}`;
|
|
471
|
-
const params = new URLSearchParams();
|
|
472
|
-
params.set("vue", "");
|
|
473
|
-
params.set("type", "style");
|
|
474
|
-
params.set("index", String(index));
|
|
475
|
-
params.set("lang", lang);
|
|
476
|
-
params.set("vize-file", filename);
|
|
477
|
-
if (query.scoped) params.set("scoped", query.scoped);
|
|
478
|
-
if (query.module !== false) params.set("module", typeof query.module === "string" ? query.module : "");
|
|
479
|
-
return `${filename}${STYLE_MARKER}${index}${suffix}?${params.toString()}`;
|
|
480
|
-
}
|
|
481
|
-
//#endregion
|
|
482
508
|
//#region src/strip-types.ts
|
|
483
509
|
function formatErrorMessage(error) {
|
|
484
510
|
const parts = [error.message];
|
|
@@ -574,22 +600,57 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
574
600
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
575
601
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
576
602
|
}
|
|
577
|
-
async function loadStyleBlock(id, options, cache) {
|
|
603
|
+
async function loadStyleBlock(context, id, options, cache) {
|
|
578
604
|
const request = parseVueRequest(id);
|
|
579
605
|
const index = request.query.index ?? -1;
|
|
580
606
|
if (index < 0) return "";
|
|
581
607
|
let compiled = cache.get(request.filename)?.compiled;
|
|
582
608
|
if (!compiled && node_fs.default.existsSync(request.filename)) {
|
|
583
609
|
const source = node_fs.default.readFileSync(request.filename, "utf8");
|
|
584
|
-
|
|
610
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
611
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
585
612
|
}
|
|
586
613
|
const block = compiled?.styles[index];
|
|
587
614
|
if (!compiled || !block) return "";
|
|
588
|
-
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId);
|
|
615
|
+
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
589
616
|
const scoped = request.query.scoped;
|
|
590
617
|
if (!scoped) return source;
|
|
591
618
|
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);
|
|
592
619
|
}
|
|
620
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
621
|
+
function hostResolver(context) {
|
|
622
|
+
const ctx = context;
|
|
623
|
+
if (typeof ctx.resolve === "function") {
|
|
624
|
+
const resolve = ctx.resolve;
|
|
625
|
+
return async (request, importer) => {
|
|
626
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
627
|
+
return result && !result.external ? result.id : null;
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
const native = ctx.getNativeBuildContext?.();
|
|
631
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
632
|
+
const resolve = native.loaderContext.getResolve();
|
|
633
|
+
return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
|
|
634
|
+
}
|
|
635
|
+
if (native && "build" in native) {
|
|
636
|
+
const { build } = native;
|
|
637
|
+
return async (request, importer) => {
|
|
638
|
+
const result = await build.resolve(request, {
|
|
639
|
+
kind: "import-statement",
|
|
640
|
+
resolveDir: node_path.default.dirname(importer),
|
|
641
|
+
importer
|
|
642
|
+
});
|
|
643
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
649
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
650
|
+
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
651
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
652
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
653
|
+
}
|
|
593
654
|
const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
594
655
|
const options = normalizeOptions(rawOptions);
|
|
595
656
|
const filter = createFilter(options.include, options.exclude);
|
|
@@ -600,18 +661,17 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
600
661
|
name: "unplugin-vize",
|
|
601
662
|
resolveId(id) {
|
|
602
663
|
if (options.hostCompiler) return null;
|
|
603
|
-
|
|
604
|
-
return null;
|
|
664
|
+
return isVueStyleRequest(id) ? id : null;
|
|
605
665
|
},
|
|
606
666
|
loadInclude(id) {
|
|
607
667
|
if (options.hostCompiler) return false;
|
|
608
|
-
return !webpackStyleFiles &&
|
|
668
|
+
return !webpackStyleFiles && isVueStyleRequest(id);
|
|
609
669
|
},
|
|
610
670
|
async load(id) {
|
|
611
671
|
if (options.hostCompiler) return null;
|
|
612
|
-
if (!
|
|
672
|
+
if (!isVueStyleRequest(id)) return null;
|
|
613
673
|
return {
|
|
614
|
-
code: await loadStyleBlock(id, options, cache),
|
|
674
|
+
code: await loadStyleBlock(this, id, options, cache),
|
|
615
675
|
map: null
|
|
616
676
|
};
|
|
617
677
|
},
|
|
@@ -634,7 +694,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
634
694
|
};
|
|
635
695
|
}
|
|
636
696
|
if (!isVueFile(id) || !filter(id)) return null;
|
|
637
|
-
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
|
|
697
|
+
const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache, await resolveSrcRequests(this, id, code));
|
|
638
698
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
639
699
|
for (const dependency of dependencies) this.addWatchFile(dependency);
|
|
640
700
|
const transformed = await stripTypeScript(id, generateOutput(compiled, {
|
|
@@ -644,7 +704,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
644
704
|
styleRequest: webpackStyleFiles ? (block, scoped) => {
|
|
645
705
|
const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
|
|
646
706
|
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
647
|
-
virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId));
|
|
707
|
+
virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
648
708
|
return require_webpack_styles.webpackStyleRequest(stylePath, block);
|
|
649
709
|
} : void 0
|
|
650
710
|
}), options.sourceMap);
|
|
@@ -665,7 +725,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
665
725
|
},
|
|
666
726
|
esbuild: {
|
|
667
727
|
onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
|
|
668
|
-
onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)
|
|
728
|
+
onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
|
|
669
729
|
loader(_code, id) {
|
|
670
730
|
const request = parseVueRequest(id);
|
|
671
731
|
if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
|
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
5
|
+
const require_webpack_styles = require("./webpack-styles-IFEnxDay.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-Ca7spvMb.mjs";
|
|
2
2
|
//#region src/webpack-style-loader.ts
|
|
3
3
|
const SCOPE_QUERY = "?scope";
|
|
4
4
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
//#region src/style-scope.ts
|
|
6
6
|
const PREPROCESSOR_LANGS = new Set([
|
|
@@ -20,8 +20,9 @@ function scopeCss(css, scoped) {
|
|
|
20
20
|
* `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
|
|
21
21
|
* The plugin compiles without `isProd`, so both sides use the dev names.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/** `productionFilename` selects the hashed production names `useCssVars` uses. */
|
|
24
|
+
function transformStyleVars(css, scopeId, productionFilename) {
|
|
25
|
+
return transformViteCssVarsForPipeline(css, scopeId, productionFilename);
|
|
25
26
|
}
|
|
26
27
|
function loadPreprocessor(root, names, lang) {
|
|
27
28
|
const requireFromRoot = createRequire(path.join(root, "package.json"));
|
|
@@ -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");
|
|
25
24
|
let node_path = require("node:path");
|
|
26
25
|
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([
|
|
@@ -43,8 +43,9 @@ function scopeCss(css, scoped) {
|
|
|
43
43
|
* `v-bind()` in a delegated block, named like the compiled `useCssVars` call.
|
|
44
44
|
* The plugin compiles without `isProd`, so both sides use the dev names.
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
/** `productionFilename` selects the hashed production names `useCssVars` uses. */
|
|
47
|
+
function transformStyleVars(css, scopeId, productionFilename) {
|
|
48
|
+
return (0, _vizejs_native.transformViteCssVarsForPipeline)(css, scopeId, productionFilename);
|
|
48
49
|
}
|
|
49
50
|
function loadPreprocessor(root, names, lang) {
|
|
50
51
|
const requireFromRoot = (0, node_module.createRequire)(node_path.default.join(root, "package.json"));
|
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.662.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.662.0",
|
|
72
72
|
"oxc-transform": "0.144.0",
|
|
73
73
|
"unplugin": "3.3.0"
|
|
74
74
|
},
|