@vizejs/rspack-plugin 0.206.0 → 0.210.1
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/dist/compiler-Ci6TNveg.mjs +42 -0
- package/dist/{index-UcNdg-h0.d.mts → index-D-xYzHWQ.d.mts} +53 -1
- package/dist/index.d.mts +21 -2
- package/dist/index.mjs +1 -1
- package/dist/loader/index.d.mts +1 -1
- package/dist/loader/index.mjs +1 -1
- package/dist/loader/jsx-loader.d.mts +7 -0
- package/dist/loader/jsx-loader.mjs +1 -0
- package/dist/loader/style-loader.d.mts +1 -1
- package/dist/loader-hFzurQxg.mjs +1 -0
- package/package.json +7 -2
- package/dist/loader-BslWL-th.mjs +0 -24
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import{d as e,n as t,o as n,u as r}from"./utils-CFK8mca_.mjs";import*as i from"@vizejs/native";import a from"node:path";import{createHash as o}from"node:crypto";function s(e){return`
|
|
2
|
+
/* hot reload */
|
|
3
|
+
if (module.hot) {
|
|
4
|
+
_sfc_main.__hmrId = "${e}"
|
|
5
|
+
const api = __VUE_HMR_RUNTIME__
|
|
6
|
+
module.hot.accept()
|
|
7
|
+
if (!api.createRecord('${e}', _sfc_main)) {
|
|
8
|
+
api.reload('${e}', _sfc_main)
|
|
9
|
+
}
|
|
10
|
+
}`}function c(e,t,n,r){return`
|
|
11
|
+
if (module.hot) {
|
|
12
|
+
module.hot.accept(${t}, () => {
|
|
13
|
+
_sfc_main.__cssModules[${JSON.stringify(r)}] = ${n}
|
|
14
|
+
__VUE_HMR_RUNTIME__.rerender("${e}")
|
|
15
|
+
})
|
|
16
|
+
}`}function l(e,t){let n=e.code,r=e.isCustomElement;if(e.templateAssetUrls.length>0)for(let{url:t,varName:r}of e.templateAssetUrls){let e=t.indexOf(`#`),i=e>=0?t.slice(e):``,a=i?`${r} + ${JSON.stringify(i)}`:r,o=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`"${o}"`,`g`),a),n=n.replace(RegExp(`'${o}'`,`g`),a)}let i=/^export default /m,o=i.test(n),l=/\bconst\s+_sfc_main\s*=/.test(n);if(o&&!l?(n=n.replace(i,`const _sfc_main = `),e.hasScoped&&e.scopeId&&(n+=`\n_sfc_main.__scopeId = "data-v-${e.scopeId}";`),n+=`
|
|
17
|
+
export default _sfc_main;`):o&&l&&e.hasScoped&&e.scopeId&&(n=n.replace(/^export default _sfc_main/m,`_sfc_main.__scopeId = "data-v-${e.scopeId}";\nexport default _sfc_main`)),e.styles.length>0){if(r&&e.styles.some(e=>e.module))throw Error(`[vize] <style module> is not supported in custom elements mode.`);let i=e.styles.filter(e=>e.module===!0).length;if(i>1)throw Error(`[vize] Found ${i} unnamed <style module> blocks. Only one unnamed <style module> is allowed per SFC. Use named modules instead: <style module="name">`);let a=e.styles.filter(e=>e.src||/\S/.test(e.content)),o=[];if(n=a.map(n=>{let i=[`vue`,`type=style`,`index=${n.index}`,`lang=${n.lang||`css`}`,...n.scoped?[`scoped=${e.scopeId}`]:[],...n.module?[`module=${typeof n.module==`string`?n.module:`true`}`]:[],...r?[`inline`]:[]],a=`${t.requestPath}?${i.join(`&`)}`;if(r)return`import _style_${n.index} from ${JSON.stringify(a)};`;if(n.module){let e=typeof n.module==`string`?n.module:`$style`,r=`_cssModule_${n.index}`;return o.push({request:a,varName:r,bindingName:e}),t.nativeCss?`import * as ${r} from ${JSON.stringify(a)};`:`import ${r} from ${JSON.stringify(a)};`}return`import ${JSON.stringify(a)};`}).join(`
|
|
18
|
+
`)+`
|
|
19
|
+
`+n,r){let e=a.map(e=>`_style_${e.index}`).join(`,`);n=n.replace(/^export default _sfc_main;/m,`_sfc_main.styles = [${e}];\nexport default _sfc_main;`)}if(!r&&o.length>0){let r=o.map(e=>`_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(e.bindingName)}] = ${e.varName};`).join(`
|
|
20
|
+
`),i=t.hmr&&e.scopeId?o.map(t=>c(e.scopeId,JSON.stringify(t.request),t.varName,t.bindingName)).join(`
|
|
21
|
+
`):``;n=n.replace(/^export default _sfc_main;/m,`${r}\n${i}\nexport default _sfc_main;`)}}if(t.filePath&&!t.isProduction){let e=t.rootContext?a.relative(t.rootContext,t.filePath).replace(/\\/g,`/`):a.basename(t.filePath);n=n.replace(/^export default _sfc_main;/m,`_sfc_main.__file = ${JSON.stringify(e)};\nexport default _sfc_main;`)}if(t.hmr&&e.scopeId&&(n=n.replace(/^export default _sfc_main;/m,`${s(e.scopeId)}\nexport default _sfc_main;`)),e.customBlocks.length>0){let r=e.customBlocks.map((e,n)=>{let r=[`vue`,`type=${e.type}`,`index=${n}`,...e.src?[`src=true`]:[]];for(let[t,n]of Object.entries(e.attrs))t!==`src`&&(n===!0?r.push(t):r.push(`${t}=${n}`));let i=`${t.requestPath}?${r.join(`&`)}`;return`import block${n} from ${JSON.stringify(i)};\nif (typeof block${n} === 'function') block${n}(_sfc_main);`}).join(`
|
|
22
|
+
`);n=n.replace(/^export default _sfc_main;/m,`${r}\nexport default _sfc_main;`)}return e.templateAssetUrls.length>0&&(n=e.templateAssetUrls.map(({url:e,varName:t})=>{let n=e.startsWith(`~`)?e.slice(1):e,r=n.indexOf(`#`);return r>=0&&(n=n.slice(0,r)),`import ${t} from ${JSON.stringify(n)};`}).join(`
|
|
23
|
+
`)+`
|
|
24
|
+
`+n),n}const{compileSfc:u}=i,{compileJsx:d}=i;function f(e){return e.endsWith(`.jsx`)||e.endsWith(`.tsx`)}function p(e,t,n){return`
|
|
25
|
+
export const __vize_css__ = ${JSON.stringify(t)};
|
|
26
|
+
const __vize_css_id__ = ${JSON.stringify(`vize-style-${n}`)};
|
|
27
|
+
(function() {
|
|
28
|
+
if (typeof document !== "undefined") {
|
|
29
|
+
let style = document.getElementById(__vize_css_id__);
|
|
30
|
+
if (!style) {
|
|
31
|
+
style = document.createElement("style");
|
|
32
|
+
style.id = __vize_css_id__;
|
|
33
|
+
style.textContent = __vize_css__;
|
|
34
|
+
document.head.appendChild(style);
|
|
35
|
+
} else {
|
|
36
|
+
style.textContent = __vize_css__;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})();
|
|
40
|
+
${e}`}function m(e,t,n={}){let r=d(t,{filename:e,lang:e.endsWith(`.tsx`)?`tsx`:`jsx`,jsxMode:n.jsxMode,vapor:n.vapor??!1,sourceMap:n.sourceMap??!1});if(r.errors.length>0)throw Error(`[vize] Compilation failed for ${e}:\n${r.errors.join(`
|
|
41
|
+
`)}`);let i=(r.scopedStyles??[]).map(e=>e.css).join(`
|
|
42
|
+
`),a=r.code,o=r.map??null;if(i){let e=r.scopedStyles[0].scopeId.replace(/^data-v-/,``);a=p(a,i,e),o=null}return{code:a,map:o,warnings:r.warnings}}const h=new Map;function g(e){return o(`sha256`).update(e).digest(`hex`).slice(0,16)}function _(){h.clear()}function v(i,a,o={}){let s=o.compilerOptions?.isTs??/<script[^>]*\blang=["']ts["']/.test(a),c=o.ssr??o.compilerOptions?.ssr??!1,l=o.vapor??o.compilerOptions?.vapor??!1,d=o.sourceMap??o.compilerOptions?.sourceMap??!0,f=o.isCustomElement??!1,p=o.rootContext??``,m=o.isProduction??!1,_=o.transformAssetUrls??!0,v=`${i}:ssr=${c}:vapor=${l}:ts=${s}:map=${d}:ce=${f}:syntax=${o.compilerOptions?.templateSyntax??`standard`}:root=${p}:prod=${m}:${_===!1?`tau=false`:_===!0?`tau=true`:`tau=${JSON.stringify(_)}`}`,y=g(a),b=h.get(v);if(b&&b.contentHash===y)return b.result;let x=n(i,o.rootContext,o.isProduction,a),S=u(a,{...o.compilerOptions,filename:i,sourceMap:o.sourceMap??o.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:s,scopeId:`data-v-${x}`}),C=t(a,_),w={code:S.code,css:S.css,errors:S.errors,warnings:S.warnings,scopeId:x,hasScoped:S.hasScoped,styles:S.styles.map(e),customBlocks:S.customBlocks.map(r),isCustomElement:f,templateAssetUrls:C,macroArtifacts:S.macroArtifacts??[]};return w.errors.length===0&&h.set(v,{contentHash:y,result:w}),w}export{l as a,f as i,v as n,s as o,m as r,_ as t};
|
|
@@ -54,6 +54,54 @@ interface SfcCompileResultNapi {
|
|
|
54
54
|
customBlocks: CustomBlockNapi[];
|
|
55
55
|
macroArtifacts?: MacroArtifact[];
|
|
56
56
|
}
|
|
57
|
+
/** Options for the native `compileJsx`. */
|
|
58
|
+
interface JsxCompileOptionsNapi {
|
|
59
|
+
/** Source filename, used to infer the language when `lang` is omitted. */
|
|
60
|
+
filename?: string;
|
|
61
|
+
/** Source language: "jsx" or "tsx". Inferred from a `.tsx` filename. */
|
|
62
|
+
lang?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Default output mode (`"vdom"` | `"vapor"`); mirrors `compiler.jsxMode` and
|
|
65
|
+
* wins over `vapor`. Per-component `"use vue:*"` directives still override it.
|
|
66
|
+
*/
|
|
67
|
+
jsxMode?: "vdom" | "vapor";
|
|
68
|
+
/** Legacy default-mode toggle: `true` → Vapor, `false` (default) → VDOM. */
|
|
69
|
+
vapor?: boolean;
|
|
70
|
+
/** Emit a v3 source map for the generated render code (#1533). */
|
|
71
|
+
sourceMap?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/** A JSX component's extracted `<style scoped>` block (#1495, #1533). */
|
|
74
|
+
interface JsxScopedStyleNapi {
|
|
75
|
+
/** Generated scope id, e.g. `data-v-1a2b3c4d`, already applied to the CSS. */
|
|
76
|
+
scopeId: string;
|
|
77
|
+
/** Scope-rewritten CSS, with the `data-v-<hash>` attribute applied. */
|
|
78
|
+
css: string;
|
|
79
|
+
}
|
|
80
|
+
/** Result of the native `compileJsx`. */
|
|
81
|
+
interface JsxCompileResultNapi {
|
|
82
|
+
/**
|
|
83
|
+
* Generated render code for the module: the deduplicated runtime-helper
|
|
84
|
+
* preamble followed by every component's render code (the helper imports are
|
|
85
|
+
* no longer dropped, #1533).
|
|
86
|
+
*/
|
|
87
|
+
code: string;
|
|
88
|
+
/**
|
|
89
|
+
* v3 source map (JSON) for `code`, present only when `sourceMap` was requested
|
|
90
|
+
* and the module is a single component. `null`/absent otherwise (#1533).
|
|
91
|
+
*/
|
|
92
|
+
map?: string;
|
|
93
|
+
/** Error-severity diagnostic messages. */
|
|
94
|
+
errors: string[];
|
|
95
|
+
/** Warning-severity diagnostic messages. */
|
|
96
|
+
warnings: string[];
|
|
97
|
+
/**
|
|
98
|
+
* Extracted `<style scoped>` blocks across the module's components, in source
|
|
99
|
+
* order (#1495). Empty when no component had a `<style scoped>`. Each entry's
|
|
100
|
+
* CSS is already scope-rewritten; the plugin emits it through the same style
|
|
101
|
+
* path SFC `<style>` blocks use (#1533).
|
|
102
|
+
*/
|
|
103
|
+
scopedStyles: JsxScopedStyleNapi[];
|
|
104
|
+
}
|
|
57
105
|
interface StyleBlockInfo {
|
|
58
106
|
/** Raw style content */
|
|
59
107
|
content: string;
|
|
@@ -128,6 +176,8 @@ interface VizeLoaderOptions {
|
|
|
128
176
|
customElement?: boolean | RegExp;
|
|
129
177
|
/** Vapor mode @default false */
|
|
130
178
|
vapor?: boolean;
|
|
179
|
+
/** Default JSX output mode for `.jsx`/`.tsx` without a `"use vue:*"` directive. @default "vdom" */
|
|
180
|
+
jsxMode?: "vdom" | "vapor";
|
|
131
181
|
/** HMR. false to disable in dev. @default true (dev), false (prod/SSR) */
|
|
132
182
|
hotReload?: boolean;
|
|
133
183
|
/** CSS handling config */
|
|
@@ -157,6 +207,8 @@ interface VizeRspackPluginOptions {
|
|
|
157
207
|
sourceMap?: boolean;
|
|
158
208
|
/** Vapor mode @default false */
|
|
159
209
|
vapor?: boolean;
|
|
210
|
+
/** Default JSX output mode for `.jsx`/`.tsx` without a `"use vue:*"` directive. @default "vdom" */
|
|
211
|
+
jsxMode?: "vdom" | "vapor";
|
|
160
212
|
/** Root directory @default Rspack's root */
|
|
161
213
|
root?: string;
|
|
162
214
|
/** CSS config */
|
|
@@ -183,4 +235,4 @@ type LoaderEntry = string | {
|
|
|
183
235
|
options?: Record<string, unknown>;
|
|
184
236
|
};
|
|
185
237
|
//#endregion
|
|
186
|
-
export {
|
|
238
|
+
export { LoaderEntry as a, SfcCompileResultNapi as c, VizeLoaderOptions as d, VizeRspackPluginOptions as f, JsxCompileResultNapi as i, SfcSrcInfo as l, CustomBlockInfo as n, MacroArtifact as o, VizeStyleLoaderOptions as p, JsxCompileOptionsNapi as r, SfcCompileOptionsNapi as s, CompiledModule as t, StyleBlockInfo as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as LoaderEntry, c as SfcCompileResultNapi, d as VizeLoaderOptions, f as VizeRspackPluginOptions, i as JsxCompileResultNapi, l as SfcSrcInfo, n as CustomBlockInfo, o as MacroArtifact, p as VizeStyleLoaderOptions, r as JsxCompileOptionsNapi, s as SfcCompileOptionsNapi, t as CompiledModule, u as StyleBlockInfo } from "./index-D-xYzHWQ.mjs";
|
|
2
2
|
import vizeLoader from "./loader/index.mjs";
|
|
3
|
+
import vizeJsxLoader from "./loader/jsx-loader.mjs";
|
|
3
4
|
import vizeStyleLoader from "./loader/style-loader.mjs";
|
|
4
5
|
import vizeScopeLoader from "./loader/scope-loader.mjs";
|
|
5
6
|
import { Compiler, RuleSetRule } from "@rspack/core";
|
|
@@ -60,6 +61,24 @@ declare function generateOutput(compiled: CompiledModule, options: {
|
|
|
60
61
|
}): string;
|
|
61
62
|
//#endregion
|
|
62
63
|
//#region src/shared/compiler.d.ts
|
|
64
|
+
/** `.jsx`/`.tsx` Vue components routed to the native JSX compiler. */
|
|
65
|
+
declare function isJsxFile(filePath: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Compile a `.jsx`/`.tsx` Vue module to render code via the native JSX
|
|
68
|
+
* compiler. Mirrors {@link compileFile} but for the JSX lowering path: no custom
|
|
69
|
+
* blocks or asset-url rewriting apply. A component's `<style scoped>` CSS is
|
|
70
|
+
* surfaced (already scope-rewritten) and emitted through the same inline-style
|
|
71
|
+
* injection path the integrations use for plain SFC CSS (#1495, #1533).
|
|
72
|
+
*/
|
|
73
|
+
declare function compileJsxModule(filePath: string, source: string, options?: {
|
|
74
|
+
jsxMode?: "vdom" | "vapor";
|
|
75
|
+
vapor?: boolean;
|
|
76
|
+
sourceMap?: boolean;
|
|
77
|
+
}): {
|
|
78
|
+
code: string;
|
|
79
|
+
map: string | null;
|
|
80
|
+
warnings: string[];
|
|
81
|
+
};
|
|
63
82
|
/** Clear the compilation cache. Exposed for testing. */
|
|
64
83
|
declare function clearCompilationCache(): void;
|
|
65
84
|
/** Compile a .vue file with content-hash caching. */
|
|
@@ -74,4 +93,4 @@ declare function compileFile(filePath: string, source: string, options?: {
|
|
|
74
93
|
transformAssetUrls?: boolean | Record<string, string[]>;
|
|
75
94
|
}): CompiledModule;
|
|
76
95
|
//#endregion
|
|
77
|
-
export { type CompiledModule, type CustomBlockInfo, type LoaderEntry, type MacroArtifact, type RuleCloningResult, type SfcCompileOptionsNapi, type SfcCompileResultNapi, type SfcSrcInfo, type StyleBlockInfo, type VizeLoaderOptions, VizePlugin, type VizeRspackPluginOptions, type VizeStyleLoaderOptions, addScopeToCssFallback, applyRuleCloning, clearCompilationCache, compileFile, extractCustomBlocks, extractSrcInfo, extractStyleBlocks, genHotReloadCode, generateOutput, generateScopeId, inlineSrcBlocks, matchesPattern, vizeLoader, vizeScopeLoader, vizeStyleLoader };
|
|
96
|
+
export { type CompiledModule, type CustomBlockInfo, type JsxCompileOptionsNapi, type JsxCompileResultNapi, type LoaderEntry, type MacroArtifact, type RuleCloningResult, type SfcCompileOptionsNapi, type SfcCompileResultNapi, type SfcSrcInfo, type StyleBlockInfo, type VizeLoaderOptions, VizePlugin, type VizeRspackPluginOptions, type VizeStyleLoaderOptions, addScopeToCssFallback, applyRuleCloning, clearCompilationCache, compileFile, compileJsxModule, extractCustomBlocks, extractSrcInfo, extractStyleBlocks, genHotReloadCode, generateOutput, generateScopeId, inlineSrcBlocks, isJsxFile, matchesPattern, vizeJsxLoader, vizeLoader, vizeScopeLoader, vizeStyleLoader };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,i as n,o as r,r as i,s as a,t as o}from"./utils-CFK8mca_.mjs";import{
|
|
1
|
+
import{a as e,c as t,i as n,o as r,r as i,s as a,t as o}from"./utils-CFK8mca_.mjs";import{n as s,r as c,t as l}from"./loader-hFzurQxg.mjs";import{a as u,i as d,n as f,o as p,r as m,t as h}from"./compiler-Ci6TNveg.mjs";import g from"./loader/jsx-loader.mjs";import _ from"./loader/style-loader.mjs";import v from"./loader/scope-loader.mjs";const y=`@vizejs/rspack-plugin/style-loader`,b=`@vizejs/rspack-plugin/scope-loader`,x={"\\.css$":`css`,"\\.scss$":`scss`,"\\.sass$":`sass`,"\\.less$":`less`,"\\.styl(us)?$":`styl`};function S(e,t){let n=[],r=e.findIndex(e=>e!==`...`&&C(e));if(r===-1)return{applied:!1,clonedCount:0,warnings:n};let i=e[r];if(i.oneOf)return{applied:!1,clonedCount:0,warnings:n};let a=[];for(let t=0;t<e.length;t++){if(t===r)continue;let n=e[t];if(n===`...`)continue;let i=E(n);i&&a.push({index:t,rule:n,lang:i})}let o=[];for(let e of a)o.push(...D(e.rule,e.lang,t));o.some(e=>e.resourceQuery instanceof RegExp&&e.resourceQuery.test(`vue&type=style&index=0&lang=css`))||o.push(...O(t));let s={use:k(M(i),t)},c=[...o,s];e[r]={test:i.test,oneOf:c};for(let e of a)A(e.rule);return{applied:!0,clonedCount:o.length,warnings:n}}function C(e){return T(e.test)?M(e).some(e=>{let t=typeof e==`string`?e:e.loader;return t?w(t):!1}):!1}function w(e){return e===`@vizejs/rspack-plugin/loader`||e.includes(`rspack-vize-plugin`)&&e.includes(`loader`)&&!e.includes(`style-loader`)&&!e.includes(`scope-loader`)}function T(e){return e?e instanceof RegExp?e.test(`App.vue`)||e.test(`foo.vue`):typeof e==`string`?e.includes(`.vue`):!1:!1}function E(e){let t=e.test;if(!t||!(t instanceof RegExp))return null;let n=t.source;for(let[e,t]of Object.entries(x))if(n.includes(e)||n===e)return t;return t.test(`foo.css`)&&!t.test(`foo.vue`)?`css`:t.test(`foo.scss`)&&!t.test(`foo.vue`)?`scss`:t.test(`foo.sass`)&&!t.test(`foo.vue`)?`sass`:t.test(`foo.less`)&&!t.test(`foo.vue`)?`less`:t.test(`foo.styl`)&&!t.test(`foo.vue`)?`styl`:null}function D(e,t,n){let r=M(e);if(r.length===0)return[];let i=[{loader:b},...N(r),{loader:y}],a=(t,n)=>{let r={resourceQuery:t,use:N(i)};return e.type?r.type=e.type:n&&(r.type=n),r};return n?[a(RegExp(`(?=.*type=style)(?=.*lang=${t})(?=.*module=)`),`css/module`),a(RegExp(`(?=.*type=style)(?=.*lang=${t})`),`css/auto`)]:[a(RegExp(`(?=.*type=style)(?=.*lang=${t})`))]}function O(e){return e?[{resourceQuery:/(?=.*type=style)(?=.*lang=css)(?=.*module=)/,type:`css/module`,use:[{loader:b},{loader:y}]},{resourceQuery:/(?=.*type=style)(?=.*lang=css)/,type:`css/auto`,use:[{loader:b},{loader:y}]}]:[{resourceQuery:/(?=.*type=style)(?=.*lang=css)/,type:`javascript/auto`,use:[{loader:b},{loader:y}]}]}function k(e,t){return N(e).map(e=>{if(typeof e==`string`)return w(e)?{loader:e,options:{css:{native:t}}}:e;if(typeof e!=`object`||!e)return e;let n=e.loader;if(!n||!w(n))return e;let r=e.options;if(!r||typeof r!=`object`||Array.isArray(r))return{...e,options:{css:{native:t}}};let i=r,a=i.css;return!a||typeof a!=`object`||Array.isArray(a)?{...e,options:{...i,css:{native:t}}}:{...e,options:{...i,css:{...a,native:t}}}})}function A(e){let t=e.resourceQuery;if(t)return typeof t==`object`&&!Array.isArray(t)&&!(t instanceof RegExp)&&`not`in t,void 0;e.resourceQuery={not:[/vue/]}}function j(e){return e?Array.isArray(e)?e:[e]:[]}function M(e){let t=j(e.use);if(t.length>0)return t;let n=e.loader;if(n){let t=e.options;return t?[{loader:n,options:t}]:[n]}return[]}function N(e){return e.map(e=>{if(typeof e==`string`)return e;if(typeof e==`object`&&e){let t={...e};return`options`in e&&e.options&&typeof e.options==`object`&&(t.options={...e.options}),t}return e})}var P=class e{static name=`VizePlugin`;options;constructor(e={}){this.options=e}apply(t){let n=t.getInfrastructureLogger(e.name),r=this.options.isProduction??t.options.mode===`production`;this.options.vapor&&!r&&n.debug(`Vapor mode is enabled.`);let i=s(t.options),a=t.webpack?.rspackVersion,o=c(this.options.css?.native,t.options,a);if(this.options.css?.native&&i===`disabled`&&n.warn("`css.native: true` is set but `experiments.css` is not enabled in rspack config."),this.options.autoRules??!0){let e=t.options.module?.rules;if(e){let t=S(e,o);t.applied&&n.debug(`Auto-injected ${t.clonedCount} style rule(s) for Vue SFC sub-requests.`);for(let e of t.warnings)n.warn(e)}}if(this.options.typescript??!0){let e=t.options.module?.rules;e&&(e.some(e=>{if(e===`...`||typeof e!=`object`||!e)return!1;let t=e;if(t.enforce!==`post`)return!1;let n=t.test;return n instanceof RegExp?n.test(`App.vue`):typeof n==`string`?n.includes(`.vue`):!1})||(e.push({test:/\.vue$/,resourceQuery:{not:[/type=/]},enforce:`post`,loader:`builtin:swc-loader`,options:{jsc:{parser:{syntax:`typescript`}}},type:`javascript/auto`}),n.debug(`Auto-injected TypeScript post-processing rule for .vue files.`)))}let{DefinePlugin:l}=t.webpack,u=new Set;for(let e of t.options.plugins??[]){let t=e?.definitions;if(t)for(let e of Object.keys(t))u.add(e)}let d={};u.has(`__VUE_OPTIONS_API__`)||(d.__VUE_OPTIONS_API__=JSON.stringify(!0)),u.has(`__VUE_PROD_DEVTOOLS__`)||(d.__VUE_PROD_DEVTOOLS__=JSON.stringify(!r)),u.has(`__VUE_PROD_HYDRATION_MISMATCH_DETAILS__`)||(d.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__=JSON.stringify(!r)),Object.keys(d).length>0&&new l(d).apply(t),r||t.hooks.watchRun.tap(e.name,e=>{let t=e.modifiedFiles,r=e.removedFiles;if(t)for(let e of t)e.endsWith(`.vue`)&&this.shouldHandleFile(e)&&n.debug(`Vue file changed: ${e}`);if(r)for(let e of r)e.endsWith(`.vue`)&&this.shouldHandleFile(e)&&n.debug(`Vue file removed: ${e}`)})}shouldHandleFile(e){return!(!t(e,this.options.include,!0)||t(e,this.options.exclude,!1))}};export{P as VizePlugin,o as addScopeToCssFallback,S as applyRuleCloning,h as clearCompilationCache,f as compileFile,m as compileJsxModule,i as extractCustomBlocks,n as extractSrcInfo,e as extractStyleBlocks,p as genHotReloadCode,u as generateOutput,r as generateScopeId,a as inlineSrcBlocks,d as isJsxFile,t as matchesPattern,g as vizeJsxLoader,l as vizeLoader,v as vizeScopeLoader,_ as vizeStyleLoader};
|
package/dist/loader/index.d.mts
CHANGED
package/dist/loader/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"../loader-
|
|
1
|
+
import{t as e}from"../loader-hFzurQxg.mjs";export{e as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { d as VizeLoaderOptions } from "../index-D-xYzHWQ.mjs";
|
|
2
|
+
import { LoaderContext } from "@rspack/core";
|
|
3
|
+
|
|
4
|
+
//#region src/loader/jsx-loader.d.ts
|
|
5
|
+
declare function vizeJsxLoader(this: LoaderContext<VizeLoaderOptions>, source: string): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { vizeJsxLoader as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e}from"../utils-CFK8mca_.mjs";import{r as t}from"../compiler-Ci6TNveg.mjs";function n(e){let n=this.async(),i=this.getOptions(),a=this.resourcePath;if(this.addDependency(a),!r(a,i)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${a}. Passing through source unchanged.`)),n(null,e);return}try{let r=i.sourceMap??this.sourceMap??!0,{code:o,map:s,warnings:c}=t(a,e,{jsxMode:i.jsxMode,vapor:i.vapor??!1,sourceMap:r});for(let e of c)this.emitWarning(Error(`[vize] ${e}`));n(null,o,s?JSON.parse(s):void 0)}catch(e){n(e)}}function r(t,n){return!(!e(t,n.include,!0)||e(t,n.exclude,!1))}export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,i as t,r as n,s as r}from"./utils-CFK8mca_.mjs";import{a as i,n as a}from"./compiler-Ci6TNveg.mjs";import o from"node:fs";import s from"node:path";function c(e){let t=e?.experiments;return!t||typeof t!=`object`||!Object.prototype.hasOwnProperty.call(t,`css`)?`unavailable`:t.css?`enabled`:`disabled`}function l(e){if(typeof e!=`string`)return null;let t=Number.parseInt(e,10);return Number.isNaN(t)?null:t}function u(e,t,n){if(e!=null)return e;let r=c(t);if(r!==`unavailable`)return r===`enabled`;let i=l(n);return i!=null&&i>=2}const d=/\.ce\.vue$/;function f(e){let c=this.async(),l=this.getOptions(),u=this.resourcePath,d=this.resourceQuery,f=g(this,u),_=this.mode===`production`||process.env.NODE_ENV===`production`,v=!(l.ssr??!1)&&!_&&l.hotReload!==!1,y=m(this,l);if(this.addDependency(u),d?.includes(`type=style`)){c(Error(`[vize] Main loader received style sub-request: ${u}${d}. Use module.rules[].oneOf with resourceQuery branches so style requests are handled by @vizejs/rspack-plugin/style-loader.`));return}if(d&&d.includes(`vue`)&&d.includes(`type=`)&&!d.includes(`type=style`)){let t=new URLSearchParams(d.slice(1)),r=t.get(`type`);if(r&&r!==`style`){let i=parseInt(t.get(`index`)||`0`,10),a=n(e)[i];if(a){if(a.src){let e=s.resolve(s.dirname(u),a.src);this.addDependency(e);try{c(null,o.readFileSync(e,`utf-8`))}catch{c(Error(`[vize] Custom block <${r} src="${a.src}"> not found (resolved: ${e}) in ${u}`))}return}c(null,a.content)}else c(null,``);return}}if(!p(u,l)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${u}. Passing through source unchanged.`)),c(null,e);return}try{let n=h(u,l.customElement),d=t(e),p=e;if(d.scriptSrc){let e=s.resolve(s.dirname(u),d.scriptSrc);this.addDependency(e);try{let t=o.readFileSync(e,`utf-8`);p=r(p,t,null)}catch{c(Error(`[vize] <script src="${d.scriptSrc}"> not found (resolved: ${e}) in ${u}`));return}}if(d.templateSrc){let e=s.resolve(s.dirname(u),d.templateSrc);this.addDependency(e);try{let t=o.readFileSync(e,`utf-8`);p=r(p,null,t)}catch{c(Error(`[vize] <template src="${d.templateSrc}"> not found (resolved: ${e}) in ${u}`));return}}let m=a(u,p,{sourceMap:l.sourceMap??this.sourceMap??!0,ssr:l.ssr??!1,vapor:l.vapor??!1,compilerOptions:l.compilerOptions,isCustomElement:n,rootContext:this.rootContext,isProduction:_,transformAssetUrls:l.transformAssetUrls});for(let e of m.warnings)this.emitWarning(Error(`[vize] ${e}`));if(m.errors.length>0){for(let e of m.errors)this.emitError(Error(`[vize] ${e}`));let e=m.errors.join(`\\n`);c(Error(`[vize] Compilation failed for ${u}:\n${e}`));return}c(null,i(m,{requestPath:f,hmr:v,filePath:u,isProduction:_,rootContext:this.rootContext,nativeCss:y}))}catch(e){c(e)}}function p(t,n){return!(!e(t,n.include,!0)||e(t,n.exclude,!1))}function m(e,t){let n=e._compiler;return u(t.css?.native,n?.options,n?.webpack?.rspackVersion)}function h(e,t){return t===!0?!0:t===!1||t===void 0?d.test(e):t.test(e)}function g(e,t){return`./${s.basename(t)}`}export{c as n,u as r,f as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/rspack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.210.1",
|
|
4
4
|
"description": "High-performance Rspack plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"import": "./dist/loader/index.mjs",
|
|
40
40
|
"default": "./dist/loader/index.mjs"
|
|
41
41
|
},
|
|
42
|
+
"./jsx-loader": {
|
|
43
|
+
"types": "./dist/loader/jsx-loader.d.mts",
|
|
44
|
+
"import": "./dist/loader/jsx-loader.mjs",
|
|
45
|
+
"default": "./dist/loader/jsx-loader.mjs"
|
|
46
|
+
},
|
|
42
47
|
"./style-loader": {
|
|
43
48
|
"types": "./dist/loader/style-loader.d.mts",
|
|
44
49
|
"import": "./dist/loader/style-loader.mjs",
|
|
@@ -54,7 +59,7 @@
|
|
|
54
59
|
"access": "public"
|
|
55
60
|
},
|
|
56
61
|
"dependencies": {
|
|
57
|
-
"@vizejs/native": "0.
|
|
62
|
+
"@vizejs/native": "0.210.1"
|
|
58
63
|
},
|
|
59
64
|
"devDependencies": {
|
|
60
65
|
"@rspack/core": "2.0.3",
|
package/dist/loader-BslWL-th.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import{c as e,d as t,i as n,n as r,o as i,r as a,s as o,u as s}from"./utils-CFK8mca_.mjs";import*as c from"@vizejs/native";import l from"node:fs";import u from"node:path";import{createHash as d}from"node:crypto";function f(e){let t=e?.experiments;return!t||typeof t!=`object`||!Object.prototype.hasOwnProperty.call(t,`css`)?`unavailable`:t.css?`enabled`:`disabled`}function p(e){if(typeof e!=`string`)return null;let t=Number.parseInt(e,10);return Number.isNaN(t)?null:t}function m(e,t,n){if(e!=null)return e;let r=f(t);if(r!==`unavailable`)return r===`enabled`;let i=p(n);return i!=null&&i>=2}function h(e){return`
|
|
2
|
-
/* hot reload */
|
|
3
|
-
if (module.hot) {
|
|
4
|
-
_sfc_main.__hmrId = "${e}"
|
|
5
|
-
const api = __VUE_HMR_RUNTIME__
|
|
6
|
-
module.hot.accept()
|
|
7
|
-
if (!api.createRecord('${e}', _sfc_main)) {
|
|
8
|
-
api.reload('${e}', _sfc_main)
|
|
9
|
-
}
|
|
10
|
-
}`}function g(e,t,n,r){return`
|
|
11
|
-
if (module.hot) {
|
|
12
|
-
module.hot.accept(${t}, () => {
|
|
13
|
-
_sfc_main.__cssModules[${JSON.stringify(r)}] = ${n}
|
|
14
|
-
__VUE_HMR_RUNTIME__.rerender("${e}")
|
|
15
|
-
})
|
|
16
|
-
}`}function _(e,t){let n=e.code,r=e.isCustomElement;if(e.templateAssetUrls.length>0)for(let{url:t,varName:r}of e.templateAssetUrls){let e=t.indexOf(`#`),i=e>=0?t.slice(e):``,a=i?`${r} + ${JSON.stringify(i)}`:r,o=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);n=n.replace(RegExp(`"${o}"`,`g`),a),n=n.replace(RegExp(`'${o}'`,`g`),a)}let i=/^export default /m,a=i.test(n),o=/\bconst\s+_sfc_main\s*=/.test(n);if(a&&!o?(n=n.replace(i,`const _sfc_main = `),e.hasScoped&&e.scopeId&&(n+=`\n_sfc_main.__scopeId = "data-v-${e.scopeId}";`),n+=`
|
|
17
|
-
export default _sfc_main;`):a&&o&&e.hasScoped&&e.scopeId&&(n=n.replace(/^export default _sfc_main/m,`_sfc_main.__scopeId = "data-v-${e.scopeId}";\nexport default _sfc_main`)),e.styles.length>0){if(r&&e.styles.some(e=>e.module))throw Error(`[vize] <style module> is not supported in custom elements mode.`);let i=e.styles.filter(e=>e.module===!0).length;if(i>1)throw Error(`[vize] Found ${i} unnamed <style module> blocks. Only one unnamed <style module> is allowed per SFC. Use named modules instead: <style module="name">`);let a=e.styles.filter(e=>e.src||/\S/.test(e.content)),o=[];if(n=a.map(n=>{let i=[`vue`,`type=style`,`index=${n.index}`,`lang=${n.lang||`css`}`,...n.scoped?[`scoped=${e.scopeId}`]:[],...n.module?[`module=${typeof n.module==`string`?n.module:`true`}`]:[],...r?[`inline`]:[]],a=`${t.requestPath}?${i.join(`&`)}`;if(r)return`import _style_${n.index} from ${JSON.stringify(a)};`;if(n.module){let e=typeof n.module==`string`?n.module:`$style`,r=`_cssModule_${n.index}`;return o.push({request:a,varName:r,bindingName:e}),t.nativeCss?`import * as ${r} from ${JSON.stringify(a)};`:`import ${r} from ${JSON.stringify(a)};`}return`import ${JSON.stringify(a)};`}).join(`
|
|
18
|
-
`)+`
|
|
19
|
-
`+n,r){let e=a.map(e=>`_style_${e.index}`).join(`,`);n=n.replace(/^export default _sfc_main;/m,`_sfc_main.styles = [${e}];\nexport default _sfc_main;`)}if(!r&&o.length>0){let r=o.map(e=>`_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(e.bindingName)}] = ${e.varName};`).join(`
|
|
20
|
-
`),i=t.hmr&&e.scopeId?o.map(t=>g(e.scopeId,JSON.stringify(t.request),t.varName,t.bindingName)).join(`
|
|
21
|
-
`):``;n=n.replace(/^export default _sfc_main;/m,`${r}\n${i}\nexport default _sfc_main;`)}}if(t.filePath&&!t.isProduction){let e=t.rootContext?u.relative(t.rootContext,t.filePath).replace(/\\/g,`/`):u.basename(t.filePath);n=n.replace(/^export default _sfc_main;/m,`_sfc_main.__file = ${JSON.stringify(e)};\nexport default _sfc_main;`)}if(t.hmr&&e.scopeId&&(n=n.replace(/^export default _sfc_main;/m,`${h(e.scopeId)}\nexport default _sfc_main;`)),e.customBlocks.length>0){let r=e.customBlocks.map((e,n)=>{let r=[`vue`,`type=${e.type}`,`index=${n}`,...e.src?[`src=true`]:[]];for(let[t,n]of Object.entries(e.attrs))t!==`src`&&(n===!0?r.push(t):r.push(`${t}=${n}`));let i=`${t.requestPath}?${r.join(`&`)}`;return`import block${n} from ${JSON.stringify(i)};\nif (typeof block${n} === 'function') block${n}(_sfc_main);`}).join(`
|
|
22
|
-
`);n=n.replace(/^export default _sfc_main;/m,`${r}\nexport default _sfc_main;`)}return e.templateAssetUrls.length>0&&(n=e.templateAssetUrls.map(({url:e,varName:t})=>{let n=e.startsWith(`~`)?e.slice(1):e,r=n.indexOf(`#`);return r>=0&&(n=n.slice(0,r)),`import ${t} from ${JSON.stringify(n)};`}).join(`
|
|
23
|
-
`)+`
|
|
24
|
-
`+n),n}const{compileSfc:v}=c,y=new Map;function b(e){return d(`sha256`).update(e).digest(`hex`).slice(0,16)}function x(){y.clear()}function S(e,n,a={}){let o=a.compilerOptions?.isTs??/<script[^>]*\blang=["']ts["']/.test(n),c=a.ssr??a.compilerOptions?.ssr??!1,l=a.vapor??a.compilerOptions?.vapor??!1,u=a.sourceMap??a.compilerOptions?.sourceMap??!0,d=a.isCustomElement??!1,f=a.rootContext??``,p=a.isProduction??!1,m=a.transformAssetUrls??!0,h=`${e}:ssr=${c}:vapor=${l}:ts=${o}:map=${u}:ce=${d}:syntax=${a.compilerOptions?.templateSyntax??`standard`}:root=${f}:prod=${p}:${m===!1?`tau=false`:m===!0?`tau=true`:`tau=${JSON.stringify(m)}`}`,g=b(n),_=y.get(h);if(_&&_.contentHash===g)return _.result;let x=i(e,a.rootContext,a.isProduction,n),S=v(n,{...a.compilerOptions,filename:e,sourceMap:a.sourceMap??a.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:o,scopeId:`data-v-${x}`}),C=r(n,m),w={code:S.code,css:S.css,errors:S.errors,warnings:S.warnings,scopeId:x,hasScoped:S.hasScoped,styles:S.styles.map(t),customBlocks:S.customBlocks.map(s),isCustomElement:d,templateAssetUrls:C,macroArtifacts:S.macroArtifacts??[]};return w.errors.length===0&&y.set(h,{contentHash:g,result:w}),w}const C=/\.ce\.vue$/;function w(e){let t=this.async(),r=this.getOptions(),i=this.resourcePath,s=this.resourceQuery,c=O(this,i),d=this.mode===`production`||process.env.NODE_ENV===`production`,f=!(r.ssr??!1)&&!d&&r.hotReload!==!1,p=E(this,r);if(this.addDependency(i),s?.includes(`type=style`)){t(Error(`[vize] Main loader received style sub-request: ${i}${s}. Use module.rules[].oneOf with resourceQuery branches so style requests are handled by @vizejs/rspack-plugin/style-loader.`));return}if(s&&s.includes(`vue`)&&s.includes(`type=`)&&!s.includes(`type=style`)){let n=new URLSearchParams(s.slice(1)),r=n.get(`type`);if(r&&r!==`style`){let o=parseInt(n.get(`index`)||`0`,10),s=a(e)[o];if(s){if(s.src){let e=u.resolve(u.dirname(i),s.src);this.addDependency(e);try{t(null,l.readFileSync(e,`utf-8`))}catch{t(Error(`[vize] Custom block <${r} src="${s.src}"> not found (resolved: ${e}) in ${i}`))}return}t(null,s.content)}else t(null,``);return}}if(!T(i,r)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${i}. Passing through source unchanged.`)),t(null,e);return}try{let a=D(i,r.customElement),s=n(e),m=e;if(s.scriptSrc){let e=u.resolve(u.dirname(i),s.scriptSrc);this.addDependency(e);try{let t=l.readFileSync(e,`utf-8`);m=o(m,t,null)}catch{t(Error(`[vize] <script src="${s.scriptSrc}"> not found (resolved: ${e}) in ${i}`));return}}if(s.templateSrc){let e=u.resolve(u.dirname(i),s.templateSrc);this.addDependency(e);try{let t=l.readFileSync(e,`utf-8`);m=o(m,null,t)}catch{t(Error(`[vize] <template src="${s.templateSrc}"> not found (resolved: ${e}) in ${i}`));return}}let h=S(i,m,{sourceMap:r.sourceMap??this.sourceMap??!0,ssr:r.ssr??!1,vapor:r.vapor??!1,compilerOptions:r.compilerOptions,isCustomElement:a,rootContext:this.rootContext,isProduction:d,transformAssetUrls:r.transformAssetUrls});for(let e of h.warnings)this.emitWarning(Error(`[vize] ${e}`));if(h.errors.length>0){for(let e of h.errors)this.emitError(Error(`[vize] ${e}`));let e=h.errors.join(`\\n`);t(Error(`[vize] Compilation failed for ${i}:\n${e}`));return}t(null,_(h,{requestPath:c,hmr:f,filePath:i,isProduction:d,rootContext:this.rootContext,nativeCss:p}))}catch(e){t(e)}}function T(t,n){return!(!e(t,n.include,!0)||e(t,n.exclude,!1))}function E(e,t){let n=e._compiler;return m(t.css?.native,n?.options,n?.webpack?.rspackVersion)}function D(e,t){return t===!0?!0:t===!1||t===void 0?C.test(e):t.test(e)}function O(e,t){return`./${u.basename(t)}`}export{h as a,_ as i,x as n,f as o,S as r,m as s,w as t};
|