@vizejs/unplugin 0.664.0 → 0.666.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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-COZmphjF.cjs → unplugin-BMJB8--1.cjs} +131 -109
- package/dist/{unplugin-BVGBB7oG.mjs → unplugin-C3FO9qAL.mjs} +128 -106
- package/dist/webpack-style-loader.cjs +1 -1
- package/dist/webpack-style-loader.mjs +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -2
- package/dist/{webpack-styles-DVh6lFXt.cjs → webpack-styles-B4946o00.cjs} +1 -1
- package/dist/{webpack-styles-CoRj2un6.mjs → webpack-styles-qKeVgHc7.mjs} +1 -1
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
|
|
|
115
115
|
## Caveats
|
|
116
116
|
|
|
117
117
|
- Vite is still the recommended integration if you need the most complete behavior today.
|
|
118
|
-
- Every `<style>` block is a stylesheet module for the bundler's CSS pipeline, which writes the CSS file, as with `unplugin-vue`. The module is named like Vue's style requests, `App.vue?vue&type=style&index=0&lang.css` (`lang.module.css`, `lang.scss`), so a pipeline that handles a `.css` or `.scss` file handles the block: tsdown with `@tsdown/css` writes `style.css`, esbuild writes `<entry>.css` (set `outdir` or `outfile`), Rollup needs a CSS plugin such as `rollup-plugin-postcss`, and webpack uses your `.css` rule. A build with no CSS pipeline fails on the first style block. Rolldown alone does not bundle CSS, so build through tsdown or Vite.
|
|
118
|
+
- Every `<style>` block, including a `<style scoped>` in a `.jsx` or `.tsx` component, is a stylesheet module for the bundler's CSS pipeline, which writes the CSS file, as with `unplugin-vue`. The module is named like Vue's style requests, `App.vue?vue&type=style&index=0&lang.css` (`lang.module.css`, `lang.scss`), so a pipeline that handles a `.css` or `.scss` file handles the block: tsdown with `@tsdown/css` writes `style.css`, esbuild writes `<entry>.css` (set `outdir` or `outfile`), Rollup needs a CSS plugin such as `rollup-plugin-postcss`, and webpack uses your `.css` rule. A build with no CSS pipeline fails on the first style block. Rolldown alone does not bundle CSS, so build through tsdown or Vite.
|
|
119
119
|
- `<style src>`, `<script src>` and `<template src>` follow Vue's SFC spec, as in `@vitejs/plugin-vue`: a `./` or `../` path is read next to the SFC, and any other `src` (a package such as `modern-normalize/modern-normalize.css`, an alias, an absolute path, or a bare `foo.css`) is a module request resolved by the bundler's own resolver. The file is inlined before compilation and watched. A request that resolves to no file, including an external module, is a build error.
|
|
120
120
|
- Babel and esbuild without `bundle` bundle no stylesheet, so there plain CSS is injected into JavaScript at run time, and an `@import` in it is a build error. Preprocessor and CSS Module blocks still need a CSS pipeline.
|
|
121
121
|
- CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
|
package/dist/babel.cjs
CHANGED
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-C3FO9qAL.mjs";
|
|
2
2
|
//#region src/babel.ts
|
|
3
3
|
function vizeBabelPlugin(_api, rawOptions = {}) {
|
|
4
4
|
const options = normalizeOptions(rawOptions);
|
package/dist/esbuild.cjs
CHANGED
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-BMJB8--1.cjs");
|
|
6
6
|
exports.default = require_unplugin.vizeUnplugin;
|
|
7
7
|
exports.vizeUnplugin = require_unplugin.vizeUnplugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as vizeUnplugin } from "./unplugin-
|
|
1
|
+
import { n as vizeUnplugin } from "./unplugin-C3FO9qAL.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,13 +1,13 @@
|
|
|
1
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
2
|
-
let node_fs = require("node:fs");
|
|
3
|
-
node_fs = require_webpack_styles.__toESM(node_fs, 1);
|
|
1
|
+
const require_webpack_styles = require("./webpack-styles-B4946o00.cjs");
|
|
4
2
|
let node_module = require("node:module");
|
|
5
|
-
let node_path = require("node:path");
|
|
6
|
-
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
7
3
|
let unplugin = require("unplugin");
|
|
8
4
|
let node_crypto = require("node:crypto");
|
|
9
5
|
let _vizejs_native = require("@vizejs/native");
|
|
10
6
|
_vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
node_path = require_webpack_styles.__toESM(node_path, 1);
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
node_fs = require_webpack_styles.__toESM(node_fs, 1);
|
|
11
11
|
let oxc_transform = require("oxc-transform");
|
|
12
12
|
//#region src/filter.ts
|
|
13
13
|
function createFilter(include, exclude) {
|
|
@@ -301,8 +301,6 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
|
301
301
|
}
|
|
302
302
|
return resolutions;
|
|
303
303
|
}
|
|
304
|
-
//#endregion
|
|
305
|
-
//#region src/src-blocks.ts
|
|
306
304
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
307
305
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
308
306
|
/** Split an opening tag into its `src` value and the tag without it. */
|
|
@@ -325,27 +323,18 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
325
323
|
openTag: `${head}${rest}>`
|
|
326
324
|
};
|
|
327
325
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
try {
|
|
331
|
-
return {
|
|
332
|
-
path: resolved,
|
|
333
|
-
content: node_fs.default.readFileSync(resolved, "utf8")
|
|
334
|
-
};
|
|
335
|
-
} catch {
|
|
336
|
-
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
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) {
|
|
340
328
|
let parsed;
|
|
341
329
|
try {
|
|
342
|
-
parsed =
|
|
330
|
+
parsed = parseSfc(source, { filename: filePath });
|
|
343
331
|
} catch {
|
|
344
332
|
return [];
|
|
345
333
|
}
|
|
346
334
|
const blocks = [
|
|
347
335
|
["template", parsed.template],
|
|
348
336
|
["script", parsed.script],
|
|
337
|
+
["script", parsed.scriptSetup],
|
|
349
338
|
...parsed.styles.map((style) => ["style", style])
|
|
350
339
|
];
|
|
351
340
|
const found = [];
|
|
@@ -362,18 +351,28 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
362
351
|
}
|
|
363
352
|
return found;
|
|
364
353
|
}
|
|
365
|
-
/** The `src`
|
|
366
|
-
function
|
|
354
|
+
/** The `src` module requests (not relative paths) of an SFC's blocks, in source order. */
|
|
355
|
+
function listSfcSrcRequests(parseSfc, filePath, source) {
|
|
367
356
|
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
368
|
-
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
|
+
}
|
|
369
369
|
}
|
|
370
370
|
/**
|
|
371
371
|
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
372
|
-
* source
|
|
373
|
-
*
|
|
374
|
-
* 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}).
|
|
375
374
|
*/
|
|
376
|
-
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
375
|
+
function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
|
|
377
376
|
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
378
377
|
source,
|
|
379
378
|
dependencies: []
|
|
@@ -381,7 +380,7 @@ function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
|
381
380
|
const bytes = Buffer.from(source);
|
|
382
381
|
const edits = [];
|
|
383
382
|
const dependencies = [];
|
|
384
|
-
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
383
|
+
for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
|
|
385
384
|
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
386
385
|
dependencies.push(file.path);
|
|
387
386
|
edits.push({
|
|
@@ -436,7 +435,7 @@ function buildSourceHash(source) {
|
|
|
436
435
|
return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
|
|
437
436
|
}
|
|
438
437
|
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
439
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
438
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(_vizejs_native.parseSfc, filePath, source, srcResolutions);
|
|
440
439
|
const sourceHash = buildSourceHash(inlined);
|
|
441
440
|
const signature = buildSignature(options);
|
|
442
441
|
const cached = cache.get(filePath);
|
|
@@ -491,7 +490,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
|
491
490
|
dependencies
|
|
492
491
|
};
|
|
493
492
|
}
|
|
494
|
-
function compileJsxModule(filePath, source, options) {
|
|
493
|
+
function compileJsxModule(filePath, source, options, output) {
|
|
495
494
|
const result = compileJsx(source, {
|
|
496
495
|
filename: filePath,
|
|
497
496
|
lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
|
|
@@ -501,20 +500,99 @@ function compileJsxModule(filePath, source, options) {
|
|
|
501
500
|
sourceMap: options.sourceMap
|
|
502
501
|
});
|
|
503
502
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
503
|
+
const scoped = result.scopedStyles ?? [];
|
|
504
|
+
const styles = scoped.map((style, index) => ({
|
|
505
|
+
content: style.css,
|
|
506
|
+
src: null,
|
|
507
|
+
lang: "css",
|
|
508
|
+
scoped: false,
|
|
509
|
+
module: false,
|
|
510
|
+
index
|
|
511
|
+
}));
|
|
512
|
+
let prefix = "";
|
|
513
|
+
if (styles.length > 0 && output.hostCss === "none") prefix = prependInlineStyleInjection("", styles.map((style) => style.content).join("\n"), scoped[0].scopeId.replace(/^data-v-/, ""));
|
|
514
|
+
else for (const block of styles) {
|
|
515
|
+
const id = output.styleRequest?.(block, null) ?? styleRequestId(filePath, block, null, output.hostCss);
|
|
516
|
+
prefix += `import ${JSON.stringify(id)};\n`;
|
|
510
517
|
}
|
|
518
|
+
const { code, map } = prependMappedJsxCode(result.code, result.map ?? null, prefix);
|
|
511
519
|
return {
|
|
512
520
|
code,
|
|
513
521
|
map,
|
|
514
|
-
warnings: result.warnings
|
|
522
|
+
warnings: result.warnings,
|
|
523
|
+
styles
|
|
515
524
|
};
|
|
516
525
|
}
|
|
517
526
|
//#endregion
|
|
527
|
+
//#region src/host.ts
|
|
528
|
+
/**
|
|
529
|
+
* What the host does with an imported stylesheet. esbuild without `bundle`
|
|
530
|
+
* never follows an import, and its CSS loaders compile no preprocessor.
|
|
531
|
+
*/
|
|
532
|
+
function hostCss(context, framework) {
|
|
533
|
+
if (framework !== "esbuild") return "preprocessors";
|
|
534
|
+
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
535
|
+
}
|
|
536
|
+
const CSS_PIPELINE_HINT = "[vize] <style> blocks are stylesheet modules for the bundler's CSS pipeline, and this build did not bundle one. tsdown needs @tsdown/css; Rollup needs a CSS plugin such as rollup-plugin-postcss; Rolldown alone does not bundle CSS, so build through tsdown or Vite.";
|
|
537
|
+
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
538
|
+
function isStylePipelineError(error) {
|
|
539
|
+
return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
|
|
540
|
+
}
|
|
541
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
542
|
+
function hostResolver(context) {
|
|
543
|
+
const ctx = context;
|
|
544
|
+
if (typeof ctx.resolve === "function") {
|
|
545
|
+
const resolve = ctx.resolve;
|
|
546
|
+
return async (request, importer) => {
|
|
547
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
548
|
+
return result && !result.external ? result.id : null;
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const native = ctx.getNativeBuildContext?.();
|
|
552
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
553
|
+
const resolve = native.loaderContext.getResolve();
|
|
554
|
+
return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
|
|
555
|
+
}
|
|
556
|
+
if (native && "build" in native) {
|
|
557
|
+
const { build } = native;
|
|
558
|
+
return async (request, importer) => {
|
|
559
|
+
const result = await build.resolve(request, {
|
|
560
|
+
kind: "import-statement",
|
|
561
|
+
resolveDir: node_path.default.dirname(importer),
|
|
562
|
+
importer
|
|
563
|
+
});
|
|
564
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
569
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
570
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
571
|
+
const requests = listSfcSrcRequests(_vizejs_native.parseSfc, importer, source);
|
|
572
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
573
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
574
|
+
}
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region src/style-module.ts
|
|
577
|
+
async function loadStyleBlock(context, id, options, cache, jsxStyles) {
|
|
578
|
+
const request = parseVueRequest(id);
|
|
579
|
+
const index = request.query.index ?? -1;
|
|
580
|
+
if (index < 0) return "";
|
|
581
|
+
if (isJsxFile(request.filename)) return (jsxStyles.get(request.filename) ?? (node_fs.default.existsSync(request.filename) ? compileJsxModule(request.filename, node_fs.default.readFileSync(request.filename, "utf8"), options, { hostCss: "preprocessors" }).styles : []))[index]?.content ?? "";
|
|
582
|
+
let compiled = cache.get(request.filename)?.compiled;
|
|
583
|
+
if (!compiled && node_fs.default.existsSync(request.filename)) {
|
|
584
|
+
const source = node_fs.default.readFileSync(request.filename, "utf8");
|
|
585
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
586
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
587
|
+
}
|
|
588
|
+
const block = compiled?.styles[index];
|
|
589
|
+
if (!compiled || !block) return "";
|
|
590
|
+
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
591
|
+
const css = block.lang && require_webpack_styles.isPreprocessorLang(block.lang) && request.query.lang === "css" ? await require_webpack_styles.preprocessStyle(source, block.lang, request.filename, options.root) : source;
|
|
592
|
+
const scoped = request.query.scoped;
|
|
593
|
+
return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
|
|
594
|
+
}
|
|
595
|
+
//#endregion
|
|
518
596
|
//#region src/strip-types.ts
|
|
519
597
|
function formatErrorMessage(error) {
|
|
520
598
|
const parts = [error.message];
|
|
@@ -610,76 +688,20 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
610
688
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
611
689
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
612
690
|
}
|
|
613
|
-
async function loadStyleBlock(context, id, options, cache) {
|
|
614
|
-
const request = parseVueRequest(id);
|
|
615
|
-
const index = request.query.index ?? -1;
|
|
616
|
-
if (index < 0) return "";
|
|
617
|
-
let compiled = cache.get(request.filename)?.compiled;
|
|
618
|
-
if (!compiled && node_fs.default.existsSync(request.filename)) {
|
|
619
|
-
const source = node_fs.default.readFileSync(request.filename, "utf8");
|
|
620
|
-
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
621
|
-
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
622
|
-
}
|
|
623
|
-
const block = compiled?.styles[index];
|
|
624
|
-
if (!compiled || !block) return "";
|
|
625
|
-
const source = require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
626
|
-
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;
|
|
627
|
-
const scoped = request.query.scoped;
|
|
628
|
-
return scoped ? require_webpack_styles.scopeCss(css, scoped) : css;
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* What the host does with an imported stylesheet. esbuild without `bundle`
|
|
632
|
-
* never follows an import, and its CSS loaders compile no preprocessor.
|
|
633
|
-
*/
|
|
634
|
-
function hostCss(context, framework) {
|
|
635
|
-
if (framework !== "esbuild") return "preprocessors";
|
|
636
|
-
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
637
|
-
}
|
|
638
|
-
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.";
|
|
639
|
-
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
640
|
-
function isStylePipelineError(error) {
|
|
641
|
-
return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
|
|
642
|
-
}
|
|
643
|
-
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
644
|
-
function hostResolver(context) {
|
|
645
|
-
const ctx = context;
|
|
646
|
-
if (typeof ctx.resolve === "function") {
|
|
647
|
-
const resolve = ctx.resolve;
|
|
648
|
-
return async (request, importer) => {
|
|
649
|
-
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
650
|
-
return result && !result.external ? result.id : null;
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
const native = ctx.getNativeBuildContext?.();
|
|
654
|
-
if (native && "loaderContext" in native && native.loaderContext) {
|
|
655
|
-
const resolve = native.loaderContext.getResolve();
|
|
656
|
-
return (request, importer) => resolve(node_path.default.dirname(importer), request).catch(() => null);
|
|
657
|
-
}
|
|
658
|
-
if (native && "build" in native) {
|
|
659
|
-
const { build } = native;
|
|
660
|
-
return async (request, importer) => {
|
|
661
|
-
const result = await build.resolve(request, {
|
|
662
|
-
kind: "import-statement",
|
|
663
|
-
resolveDir: node_path.default.dirname(importer),
|
|
664
|
-
importer
|
|
665
|
-
});
|
|
666
|
-
return result.errors.length > 0 || result.external ? null : result.path;
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
return null;
|
|
670
|
-
}
|
|
671
|
-
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
672
|
-
async function resolveSrcRequests(context, importer, source) {
|
|
673
|
-
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
674
|
-
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
675
|
-
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
676
|
-
}
|
|
677
691
|
const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
678
692
|
const options = normalizeOptions(rawOptions);
|
|
679
693
|
const filter = createFilter(options.include, options.exclude);
|
|
680
694
|
const cache = /* @__PURE__ */ new Map();
|
|
695
|
+
const jsxStyles = /* @__PURE__ */ new Map();
|
|
681
696
|
const webpackStyleFiles = meta.framework === "webpack";
|
|
682
697
|
let virtualModules;
|
|
698
|
+
/** A webpack style block is a virtual file the host's rules match (webpack-styles.ts). */
|
|
699
|
+
const writeWebpackStyle = (id, block, scoped, content) => {
|
|
700
|
+
const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
|
|
701
|
+
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
702
|
+
virtualModules.writeModule(stylePath, content);
|
|
703
|
+
return require_webpack_styles.webpackStyleRequest(stylePath, block);
|
|
704
|
+
};
|
|
683
705
|
let loadedStyles = false;
|
|
684
706
|
const rollupHooks = {
|
|
685
707
|
buildStart() {
|
|
@@ -704,7 +726,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
704
726
|
if (!isVueStyleRequest(id)) return null;
|
|
705
727
|
loadedStyles = true;
|
|
706
728
|
return {
|
|
707
|
-
code: await loadStyleBlock(this, id, options, cache),
|
|
729
|
+
code: await loadStyleBlock(this, id, options, cache, jsxStyles),
|
|
708
730
|
map: null
|
|
709
731
|
};
|
|
710
732
|
},
|
|
@@ -719,7 +741,11 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
719
741
|
if (options.hostCompiler) return null;
|
|
720
742
|
if (isJsxFile(id)) {
|
|
721
743
|
if (!filter(id)) return null;
|
|
722
|
-
const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options
|
|
744
|
+
const { code: jsxCode, map: jsxMap, warnings, styles } = compileJsxModule(id, code, options, {
|
|
745
|
+
hostCss: hostCss(this, meta.framework),
|
|
746
|
+
styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, block.content) : void 0
|
|
747
|
+
});
|
|
748
|
+
jsxStyles.set(id, styles);
|
|
723
749
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
724
750
|
return {
|
|
725
751
|
code: jsxCode,
|
|
@@ -735,12 +761,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
735
761
|
isDev: false,
|
|
736
762
|
hostCss: hostCss(this, meta.framework),
|
|
737
763
|
filePath: id,
|
|
738
|
-
styleRequest: webpackStyleFiles ? (block, scoped) =>
|
|
739
|
-
const stylePath = require_webpack_styles.webpackStylePath(id, block, scoped);
|
|
740
|
-
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
741
|
-
virtualModules.writeModule(stylePath, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
742
|
-
return require_webpack_styles.webpackStyleRequest(stylePath, block);
|
|
743
|
-
} : void 0
|
|
764
|
+
styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, require_webpack_styles.transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0)) : void 0
|
|
744
765
|
}), options.sourceMap);
|
|
745
766
|
return {
|
|
746
767
|
code: transformed.code,
|
|
@@ -749,6 +770,7 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
|
|
|
749
770
|
},
|
|
750
771
|
watchChange(id) {
|
|
751
772
|
if (isVueFile(id)) cache.delete(id);
|
|
773
|
+
jsxStyles.delete(id);
|
|
752
774
|
},
|
|
753
775
|
rollup: rollupHooks,
|
|
754
776
|
rolldown: rollupHooks,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-
|
|
1
|
+
import { c as scopeCss, i as webpackStyleRequest, l as transformStyleVars, n as registerWebpackStyleRule, o as isPreprocessorLang, r as webpackStylePath, s as preprocessStyle, t as findVirtualModules } from "./webpack-styles-qKeVgHc7.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
3
|
import { createUnplugin } from "unplugin";
|
|
6
4
|
import { createHash } from "node:crypto";
|
|
7
5
|
import * as native from "@vizejs/native";
|
|
8
6
|
import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import fs from "node:fs";
|
|
9
9
|
import { transform } from "oxc-transform";
|
|
10
10
|
//#region src/filter.ts
|
|
11
11
|
function createFilter(include, exclude) {
|
|
@@ -299,8 +299,6 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
|
299
299
|
}
|
|
300
300
|
return resolutions;
|
|
301
301
|
}
|
|
302
|
-
//#endregion
|
|
303
|
-
//#region src/src-blocks.ts
|
|
304
302
|
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
305
303
|
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
306
304
|
/** Split an opening tag into its `src` value and the tag without it. */
|
|
@@ -323,18 +321,8 @@ function splitSrcAttribute(tag, openTag) {
|
|
|
323
321
|
openTag: `${head}${rest}>`
|
|
324
322
|
};
|
|
325
323
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
return {
|
|
330
|
-
path: resolved,
|
|
331
|
-
content: fs.readFileSync(resolved, "utf8")
|
|
332
|
-
};
|
|
333
|
-
} catch {
|
|
334
|
-
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
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) {
|
|
338
326
|
let parsed;
|
|
339
327
|
try {
|
|
340
328
|
parsed = parseSfc(source, { filename: filePath });
|
|
@@ -344,6 +332,7 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
344
332
|
const blocks = [
|
|
345
333
|
["template", parsed.template],
|
|
346
334
|
["script", parsed.script],
|
|
335
|
+
["script", parsed.scriptSetup],
|
|
347
336
|
...parsed.styles.map((style) => ["style", style])
|
|
348
337
|
];
|
|
349
338
|
const found = [];
|
|
@@ -360,18 +349,28 @@ function collectSrcBlocks(filePath, bytes, source) {
|
|
|
360
349
|
}
|
|
361
350
|
return found;
|
|
362
351
|
}
|
|
363
|
-
/** The `src`
|
|
364
|
-
function
|
|
352
|
+
/** The `src` module requests (not relative paths) of an SFC's blocks, in source order. */
|
|
353
|
+
function listSfcSrcRequests(parseSfc, filePath, source) {
|
|
365
354
|
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
366
|
-
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
|
+
}
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
369
|
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
370
|
-
* source
|
|
371
|
-
*
|
|
372
|
-
* 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}).
|
|
373
372
|
*/
|
|
374
|
-
function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
373
|
+
function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
|
|
375
374
|
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
376
375
|
source,
|
|
377
376
|
dependencies: []
|
|
@@ -379,7 +378,7 @@ function inlineSfcSrcBlocks(filePath, source, resolutions) {
|
|
|
379
378
|
const bytes = Buffer.from(source);
|
|
380
379
|
const edits = [];
|
|
381
380
|
const dependencies = [];
|
|
382
|
-
for (const block of collectSrcBlocks(filePath, bytes, source)) {
|
|
381
|
+
for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
|
|
383
382
|
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
384
383
|
dependencies.push(file.path);
|
|
385
384
|
edits.push({
|
|
@@ -434,7 +433,7 @@ function buildSourceHash(source) {
|
|
|
434
433
|
return createHash("sha256").update(source).digest("hex");
|
|
435
434
|
}
|
|
436
435
|
function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
437
|
-
const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source, srcResolutions);
|
|
436
|
+
const { source: inlined, dependencies } = inlineSfcSrcBlocks(native.parseSfc, filePath, source, srcResolutions);
|
|
438
437
|
const sourceHash = buildSourceHash(inlined);
|
|
439
438
|
const signature = buildSignature(options);
|
|
440
439
|
const cached = cache.get(filePath);
|
|
@@ -489,7 +488,7 @@ function compileVueModule(filePath, source, options, cache, srcResolutions) {
|
|
|
489
488
|
dependencies
|
|
490
489
|
};
|
|
491
490
|
}
|
|
492
|
-
function compileJsxModule(filePath, source, options) {
|
|
491
|
+
function compileJsxModule(filePath, source, options, output) {
|
|
493
492
|
const result = compileJsx(source, {
|
|
494
493
|
filename: filePath,
|
|
495
494
|
lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
|
|
@@ -499,20 +498,99 @@ function compileJsxModule(filePath, source, options) {
|
|
|
499
498
|
sourceMap: options.sourceMap
|
|
500
499
|
});
|
|
501
500
|
if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
501
|
+
const scoped = result.scopedStyles ?? [];
|
|
502
|
+
const styles = scoped.map((style, index) => ({
|
|
503
|
+
content: style.css,
|
|
504
|
+
src: null,
|
|
505
|
+
lang: "css",
|
|
506
|
+
scoped: false,
|
|
507
|
+
module: false,
|
|
508
|
+
index
|
|
509
|
+
}));
|
|
510
|
+
let prefix = "";
|
|
511
|
+
if (styles.length > 0 && output.hostCss === "none") prefix = prependInlineStyleInjection("", styles.map((style) => style.content).join("\n"), scoped[0].scopeId.replace(/^data-v-/, ""));
|
|
512
|
+
else for (const block of styles) {
|
|
513
|
+
const id = output.styleRequest?.(block, null) ?? styleRequestId(filePath, block, null, output.hostCss);
|
|
514
|
+
prefix += `import ${JSON.stringify(id)};\n`;
|
|
508
515
|
}
|
|
516
|
+
const { code, map } = prependMappedJsxCode(result.code, result.map ?? null, prefix);
|
|
509
517
|
return {
|
|
510
518
|
code,
|
|
511
519
|
map,
|
|
512
|
-
warnings: result.warnings
|
|
520
|
+
warnings: result.warnings,
|
|
521
|
+
styles
|
|
513
522
|
};
|
|
514
523
|
}
|
|
515
524
|
//#endregion
|
|
525
|
+
//#region src/host.ts
|
|
526
|
+
/**
|
|
527
|
+
* What the host does with an imported stylesheet. esbuild without `bundle`
|
|
528
|
+
* never follows an import, and its CSS loaders compile no preprocessor.
|
|
529
|
+
*/
|
|
530
|
+
function hostCss(context, framework) {
|
|
531
|
+
if (framework !== "esbuild") return "preprocessors";
|
|
532
|
+
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
533
|
+
}
|
|
534
|
+
const CSS_PIPELINE_HINT = "[vize] <style> blocks are stylesheet modules for the bundler's CSS pipeline, and this build did not bundle one. tsdown needs @tsdown/css; Rollup needs a CSS plugin such as rollup-plugin-postcss; Rolldown alone does not bundle CSS, so build through tsdown or Vite.";
|
|
535
|
+
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
536
|
+
function isStylePipelineError(error) {
|
|
537
|
+
return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
|
|
538
|
+
}
|
|
539
|
+
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
540
|
+
function hostResolver(context) {
|
|
541
|
+
const ctx = context;
|
|
542
|
+
if (typeof ctx.resolve === "function") {
|
|
543
|
+
const resolve = ctx.resolve;
|
|
544
|
+
return async (request, importer) => {
|
|
545
|
+
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
546
|
+
return result && !result.external ? result.id : null;
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
const native = ctx.getNativeBuildContext?.();
|
|
550
|
+
if (native && "loaderContext" in native && native.loaderContext) {
|
|
551
|
+
const resolve = native.loaderContext.getResolve();
|
|
552
|
+
return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
|
|
553
|
+
}
|
|
554
|
+
if (native && "build" in native) {
|
|
555
|
+
const { build } = native;
|
|
556
|
+
return async (request, importer) => {
|
|
557
|
+
const result = await build.resolve(request, {
|
|
558
|
+
kind: "import-statement",
|
|
559
|
+
resolveDir: path.dirname(importer),
|
|
560
|
+
importer
|
|
561
|
+
});
|
|
562
|
+
return result.errors.length > 0 || result.external ? null : result.path;
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
568
|
+
async function resolveSrcRequests(context, importer, source) {
|
|
569
|
+
const requests = listSfcSrcRequests(parseSfc, importer, source);
|
|
570
|
+
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
571
|
+
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
572
|
+
}
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/style-module.ts
|
|
575
|
+
async function loadStyleBlock(context, id, options, cache, jsxStyles) {
|
|
576
|
+
const request = parseVueRequest(id);
|
|
577
|
+
const index = request.query.index ?? -1;
|
|
578
|
+
if (index < 0) return "";
|
|
579
|
+
if (isJsxFile(request.filename)) return (jsxStyles.get(request.filename) ?? (fs.existsSync(request.filename) ? compileJsxModule(request.filename, fs.readFileSync(request.filename, "utf8"), options, { hostCss: "preprocessors" }).styles : []))[index]?.content ?? "";
|
|
580
|
+
let compiled = cache.get(request.filename)?.compiled;
|
|
581
|
+
if (!compiled && fs.existsSync(request.filename)) {
|
|
582
|
+
const source = fs.readFileSync(request.filename, "utf8");
|
|
583
|
+
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
584
|
+
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
585
|
+
}
|
|
586
|
+
const block = compiled?.styles[index];
|
|
587
|
+
if (!compiled || !block) return "";
|
|
588
|
+
const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
589
|
+
const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
|
|
590
|
+
const scoped = request.query.scoped;
|
|
591
|
+
return scoped ? scopeCss(css, scoped) : css;
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
516
594
|
//#region src/strip-types.ts
|
|
517
595
|
function formatErrorMessage(error) {
|
|
518
596
|
const parts = [error.message];
|
|
@@ -608,76 +686,20 @@ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, defineP
|
|
|
608
686
|
for (const [key, value] of Object.entries(definitions)) if (!existingDefines.has(key)) missingDefinitions[key] = value;
|
|
609
687
|
if (Object.keys(missingDefinitions).length > 0) new DefinePlugin(missingDefinitions).apply(compiler);
|
|
610
688
|
}
|
|
611
|
-
async function loadStyleBlock(context, id, options, cache) {
|
|
612
|
-
const request = parseVueRequest(id);
|
|
613
|
-
const index = request.query.index ?? -1;
|
|
614
|
-
if (index < 0) return "";
|
|
615
|
-
let compiled = cache.get(request.filename)?.compiled;
|
|
616
|
-
if (!compiled && fs.existsSync(request.filename)) {
|
|
617
|
-
const source = fs.readFileSync(request.filename, "utf8");
|
|
618
|
-
const resolutions = await resolveSrcRequests(context, request.filename, source);
|
|
619
|
-
compiled = compileVueModule(request.filename, source, options, cache, resolutions).compiled;
|
|
620
|
-
}
|
|
621
|
-
const block = compiled?.styles[index];
|
|
622
|
-
if (!compiled || !block) return "";
|
|
623
|
-
const source = transformStyleVars(block.content, compiled.scopeId, options.isProduction ? request.filename : void 0);
|
|
624
|
-
const css = block.lang && isPreprocessorLang(block.lang) && request.query.lang === "css" ? await preprocessStyle(source, block.lang, request.filename, options.root) : source;
|
|
625
|
-
const scoped = request.query.scoped;
|
|
626
|
-
return scoped ? scopeCss(css, scoped) : css;
|
|
627
|
-
}
|
|
628
|
-
/**
|
|
629
|
-
* What the host does with an imported stylesheet. esbuild without `bundle`
|
|
630
|
-
* never follows an import, and its CSS loaders compile no preprocessor.
|
|
631
|
-
*/
|
|
632
|
-
function hostCss(context, framework) {
|
|
633
|
-
if (framework !== "esbuild") return "preprocessors";
|
|
634
|
-
return (context.getNativeBuildContext?.())?.build?.initialOptions?.bundle === true ? "css" : "none";
|
|
635
|
-
}
|
|
636
|
-
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.";
|
|
637
|
-
/** A Rollup or Rolldown build error raised on a style module with no CSS pipeline. */
|
|
638
|
-
function isStylePipelineError(error) {
|
|
639
|
-
return [error, ...error.errors ?? []].some((item) => typeof item.id === "string" && isVueStyleRequest(item.id) || item.code === "UNSUPPORTED_FEATURE");
|
|
640
|
-
}
|
|
641
|
-
/** The bundler's own module resolver, or null for a host that offers none. */
|
|
642
|
-
function hostResolver(context) {
|
|
643
|
-
const ctx = context;
|
|
644
|
-
if (typeof ctx.resolve === "function") {
|
|
645
|
-
const resolve = ctx.resolve;
|
|
646
|
-
return async (request, importer) => {
|
|
647
|
-
const result = await resolve.call(context, request, importer, { skipSelf: true });
|
|
648
|
-
return result && !result.external ? result.id : null;
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
const native = ctx.getNativeBuildContext?.();
|
|
652
|
-
if (native && "loaderContext" in native && native.loaderContext) {
|
|
653
|
-
const resolve = native.loaderContext.getResolve();
|
|
654
|
-
return (request, importer) => resolve(path.dirname(importer), request).catch(() => null);
|
|
655
|
-
}
|
|
656
|
-
if (native && "build" in native) {
|
|
657
|
-
const { build } = native;
|
|
658
|
-
return async (request, importer) => {
|
|
659
|
-
const result = await build.resolve(request, {
|
|
660
|
-
kind: "import-statement",
|
|
661
|
-
resolveDir: path.dirname(importer),
|
|
662
|
-
importer
|
|
663
|
-
});
|
|
664
|
-
return result.errors.length > 0 || result.external ? null : result.path;
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
return null;
|
|
668
|
-
}
|
|
669
|
-
/** Resolve the SFC's `src` module requests (packages, aliases) with the bundler. */
|
|
670
|
-
async function resolveSrcRequests(context, importer, source) {
|
|
671
|
-
const requests = listSfcSrcBlocks(importer, source).filter((src) => !isRelativeSfcSrc(src));
|
|
672
|
-
const resolve = requests.length > 0 ? hostResolver(context) : null;
|
|
673
|
-
return resolve ? resolveSfcSrcRequests(importer, requests, resolve) : void 0;
|
|
674
|
-
}
|
|
675
689
|
const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
676
690
|
const options = normalizeOptions(rawOptions);
|
|
677
691
|
const filter = createFilter(options.include, options.exclude);
|
|
678
692
|
const cache = /* @__PURE__ */ new Map();
|
|
693
|
+
const jsxStyles = /* @__PURE__ */ new Map();
|
|
679
694
|
const webpackStyleFiles = meta.framework === "webpack";
|
|
680
695
|
let virtualModules;
|
|
696
|
+
/** A webpack style block is a virtual file the host's rules match (webpack-styles.ts). */
|
|
697
|
+
const writeWebpackStyle = (id, block, scoped, content) => {
|
|
698
|
+
const stylePath = webpackStylePath(id, block, scoped);
|
|
699
|
+
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
700
|
+
virtualModules.writeModule(stylePath, content);
|
|
701
|
+
return webpackStyleRequest(stylePath, block);
|
|
702
|
+
};
|
|
681
703
|
let loadedStyles = false;
|
|
682
704
|
const rollupHooks = {
|
|
683
705
|
buildStart() {
|
|
@@ -702,7 +724,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
702
724
|
if (!isVueStyleRequest(id)) return null;
|
|
703
725
|
loadedStyles = true;
|
|
704
726
|
return {
|
|
705
|
-
code: await loadStyleBlock(this, id, options, cache),
|
|
727
|
+
code: await loadStyleBlock(this, id, options, cache, jsxStyles),
|
|
706
728
|
map: null
|
|
707
729
|
};
|
|
708
730
|
},
|
|
@@ -717,7 +739,11 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
717
739
|
if (options.hostCompiler) return null;
|
|
718
740
|
if (isJsxFile(id)) {
|
|
719
741
|
if (!filter(id)) return null;
|
|
720
|
-
const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options
|
|
742
|
+
const { code: jsxCode, map: jsxMap, warnings, styles } = compileJsxModule(id, code, options, {
|
|
743
|
+
hostCss: hostCss(this, meta.framework),
|
|
744
|
+
styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, block.content) : void 0
|
|
745
|
+
});
|
|
746
|
+
jsxStyles.set(id, styles);
|
|
721
747
|
for (const warning of warnings) this.warn(`[vize] ${warning}`);
|
|
722
748
|
return {
|
|
723
749
|
code: jsxCode,
|
|
@@ -733,12 +759,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
733
759
|
isDev: false,
|
|
734
760
|
hostCss: hostCss(this, meta.framework),
|
|
735
761
|
filePath: id,
|
|
736
|
-
styleRequest: webpackStyleFiles ? (block, scoped) =>
|
|
737
|
-
const stylePath = webpackStylePath(id, block, scoped);
|
|
738
|
-
if (!virtualModules) throw new Error("[vize] webpack style blocks need the plugin's virtual modules.");
|
|
739
|
-
virtualModules.writeModule(stylePath, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0));
|
|
740
|
-
return webpackStyleRequest(stylePath, block);
|
|
741
|
-
} : void 0
|
|
762
|
+
styleRequest: webpackStyleFiles ? (block, scoped) => writeWebpackStyle(id, block, scoped, transformStyleVars(block.content, compiled.scopeId, options.isProduction ? id : void 0)) : void 0
|
|
742
763
|
}), options.sourceMap);
|
|
743
764
|
return {
|
|
744
765
|
code: transformed.code,
|
|
@@ -747,6 +768,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
|
|
|
747
768
|
},
|
|
748
769
|
watchChange(id) {
|
|
749
770
|
if (isVueFile(id)) cache.delete(id);
|
|
771
|
+
jsxStyles.delete(id);
|
|
750
772
|
},
|
|
751
773
|
rollup: rollupHooks,
|
|
752
774
|
rolldown: rollupHooks,
|
|
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_webpack_styles = require("./webpack-styles-
|
|
5
|
+
const require_webpack_styles = require("./webpack-styles-B4946o00.cjs");
|
|
6
6
|
//#region src/webpack-style-loader.ts
|
|
7
7
|
const SCOPE_QUERY = "?scope";
|
|
8
8
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-
|
|
1
|
+
import { a as webpackStyleScope, c as scopeCss } from "./webpack-styles-qKeVgHc7.mjs";
|
|
2
2
|
//#region src/webpack-style-loader.ts
|
|
3
3
|
const SCOPE_QUERY = "?scope";
|
|
4
4
|
const CSS_LOADER = /(?:^|[/\\])css-loader(?:[/\\]|$)/;
|
package/dist/webpack.cjs
CHANGED
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.666.0",
|
|
4
4
|
"description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@vizejs/native": "0.
|
|
71
|
+
"@vizejs/native": "0.666.0",
|
|
72
72
|
"oxc-transform": "0.144.0",
|
|
73
73
|
"unplugin": "3.3.0"
|
|
74
74
|
},
|
|
@@ -21,9 +21,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
//#endregion
|
|
23
23
|
let node_module = require("node:module");
|
|
24
|
+
let _vizejs_native = require("@vizejs/native");
|
|
24
25
|
let node_path = require("node:path");
|
|
25
26
|
node_path = __toESM(node_path, 1);
|
|
26
|
-
let _vizejs_native = require("@vizejs/native");
|
|
27
27
|
let node_url = require("node:url");
|
|
28
28
|
//#region src/style-scope.ts
|
|
29
29
|
const PREPROCESSOR_LANGS = new Set([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import path from "node:path";
|
|
3
2
|
import { scopeViteCssForPipeline, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
//#region src/style-scope.ts
|
|
6
6
|
const PREPROCESSOR_LANGS = new Set([
|