@vizejs/rspack-plugin 0.670.0 → 0.671.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/dist/compiler-CpqkQjxr.mjs +91 -0
- package/dist/{index-Cg474czL.d.mts → index-DYsdFxqp.d.mts} +4 -0
- package/dist/index.d.mts +1 -1
- 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 +1 -1
- package/dist/loader/jsx-loader.mjs +1 -1
- package/dist/loader/style-loader.d.mts +1 -1
- package/dist/{loader-CG3Vu2l3.mjs → loader-NWh5yFoK.mjs} +1 -1
- package/package.json +3 -3
- package/dist/compiler-sFiJ3Glz.mjs +0 -91
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import{d as e,f as t,m as n,n as r,o as i,u as a}from"./utils-D_f3YvFb.mjs";import*as o from"@vizejs/native";import{rewriteSfcTemplateAssetReferences as s}from"@vizejs/native";import c from"node:path";import{createHash as l}from"node:crypto";import{parseSync as u}from"oxc-parser";import{transformSync as d}from"oxc-transform";function f(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===3&&Array.isArray(t.sources)&&Array.isArray(t.names)&&typeof t.mappings==`string`}function p(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}return f(t)?t:null}function m(e){let t=0;for(let n=e.indexOf(`
|
|
2
|
+
`);n!==-1;n=e.indexOf(`
|
|
3
|
+
`,n+1))t++;return t}function h(e,t,n){if(n<=0)return e;let r=e.mappings.split(`;`);if(t>=r.length)return e;let i=[...r.slice(0,t),...Array(n).fill(``),...r.slice(t)];return{...e,mappings:i.join(`;`)}}function g(e,t,n){let r=n+e;if(!n)return{code:r,map:t??null};let i=p(t);return!i||!n.endsWith(`
|
|
4
|
+
`)?{code:r,map:null}:{code:r,map:JSON.stringify(h(i,0,m(n)))}}function _(e,t){return`{
|
|
5
|
+
const current = ${e}
|
|
6
|
+
const next = ${t}
|
|
7
|
+
Object.keys(current).forEach(key => {
|
|
8
|
+
if (!Object.prototype.hasOwnProperty.call(next, key)) delete current[key]
|
|
9
|
+
})
|
|
10
|
+
Object.assign(current, next)
|
|
11
|
+
}`}function v(e,t,n=`null`,r=`module.hot`,i=`_sfc_main`){return`
|
|
12
|
+
/* hot reload */
|
|
13
|
+
if (${r}) {
|
|
14
|
+
${i}.__hmrId = "${e}"
|
|
15
|
+
const api = __VUE_HMR_RUNTIME__
|
|
16
|
+
const previous = ${r}.data && ${r}.data.vize
|
|
17
|
+
// Own writable mappings; CSS module namespace exports may be read-only.
|
|
18
|
+
if (${i}.__cssModules) {
|
|
19
|
+
Object.keys(${i}.__cssModules).forEach(name => {
|
|
20
|
+
${i}.__cssModules[name] = Object.assign(Object.create(null), ${i}.__cssModules[name])
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
const current = {
|
|
24
|
+
metadata: ${JSON.stringify(t??null)},
|
|
25
|
+
imports: (() => {
|
|
26
|
+
// A circular import may still be uninitialized. An unavailable snapshot
|
|
27
|
+
// disables state preservation without changing module loading semantics.
|
|
28
|
+
try { return ${n} } catch { return null }
|
|
29
|
+
})(),
|
|
30
|
+
component: ${i},
|
|
31
|
+
setup: ${i}.setup && ${i}.setup.toString()
|
|
32
|
+
}
|
|
33
|
+
${r}.dispose(data => { data.vize = current })
|
|
34
|
+
${r}.accept()
|
|
35
|
+
if (!api.createRecord('${e}', ${i})) {
|
|
36
|
+
const before = previous && previous.metadata
|
|
37
|
+
const after = current.metadata
|
|
38
|
+
const sameImports = previous && previous.imports && current.imports &&
|
|
39
|
+
previous.imports.length === current.imports.length &&
|
|
40
|
+
current.imports.every((entry, index) => entry[0] === previous.imports[index][0] && Object.is(entry[1], previous.imports[index][1]))
|
|
41
|
+
const canPreserve = before && after && before.canRerender && after.canRerender &&
|
|
42
|
+
before.source !== after.source &&
|
|
43
|
+
before.options === after.options && before.styles === after.styles && sameImports &&
|
|
44
|
+
previous.setup === current.setup
|
|
45
|
+
if (canPreserve && (before.module === after.module ||
|
|
46
|
+
(typeof before.script === 'string' && before.script === after.script &&
|
|
47
|
+
typeof before.template === 'string' && typeof after.template === 'string' &&
|
|
48
|
+
before.template !== after.template && typeof ${i}.render === 'function'))) {
|
|
49
|
+
// Retain both the module table and each mapping captured by setup.
|
|
50
|
+
if (previous.component.__cssModules && ${i}.__cssModules) {
|
|
51
|
+
Object.keys(${i}.__cssModules).forEach(name => ${_(`previous.component.__cssModules[name]`,`${i}.__cssModules[name]`)})
|
|
52
|
+
${i}.__cssModules = previous.component.__cssModules
|
|
53
|
+
}
|
|
54
|
+
if (before.module !== after.module || ${i}.__cssModules) {
|
|
55
|
+
api.rerender('${e}', ${i}.render)
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
api.reload('${e}', ${i})
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}`}function y(e,t,n,r,i=`module.hot`,a=`_sfc_main`){return`
|
|
62
|
+
if (${i}) {
|
|
63
|
+
${i}.accept(${t}, () => {
|
|
64
|
+
${_(`${a}.__cssModules[${JSON.stringify(r)}]`,n)}
|
|
65
|
+
__VUE_HMR_RUNTIME__.rerender("${e}", ${a}.render)
|
|
66
|
+
})
|
|
67
|
+
}`}function b(e,t){if(t==null||t<0||!Number.isInteger(t))throw Error(`[vize] Missing native component export geometry.`);if(t>e.length||t<e.length&&(e[t]&192)==128)throw Error(`[vize] Invalid native component export geometry.`);return e.subarray(0,t).toString(`utf8`).length}function x(e,t,n){let r=Buffer.from(e.code),i=b(r,t.defaultExportStart),a=b(r,t.defaultExportKeywordEnd);if(!/^export\s+default$/.test(e.code.slice(i,a)))throw Error(`[vize] Native component export geometry does not describe this module.`);e.replace(i,a,`const ${n} =`)}const S=`vize-rspack-output.tsx`;function C(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function w(e){return C(e)&&typeof e.name==`string`?e.name:null}function T(e){try{let t=u(S,e);if(typeof t==`object`&&t){let e=t.errors;if(Array.isArray(e)&&e.length>0)return null;let n=t.program;if(C(n))return n}return C(t)?t:null}catch{return null}}function E(e){return!e||!Array.isArray(e.body)?[]:e.body.filter(C)}function D(e){let t=d(S,e,{target:`esnext`,jsx:`preserve`});if(t.errors.length)return null;let n=T(t.code);if(!n)return null;let r=[];for(let e of E(n)){if(e.type!==`ImportDeclaration`)continue;let t=C(e.source)?e.source.value:null;if(typeof t!=`string`)return null;if(t===`vue`||t.includes(`?vue&type=style&`))continue;let n=Array.isArray(e.specifiers)?e.specifiers.filter(C):[];if(n.length===0)return null;for(let e of n){let n=C(e.local)?w(e.local):null;if(!n)return null;let i=JSON.stringify(`${t}:${n}`);r.push(e.type===`ImportNamespaceSpecifier`?`...Object.keys(${n}).sort().map(key => [${i} + ':' + key, ${n}[key]])`:`[${i}, ${n}]`)}}return`[${r.join(`, `)}]`}function O(e,t){return k(e,t).code}function k(e,r){let i=new t(e.code,n(e.map)),a=e.isCustomElement,o=e.moduleShape;if(!o)throw Error(`[vize] The native compiler's output does not parse, so it reported no module shape.`);let u=e.hasScoped&&e.scopeId?`data-v-${e.scopeId}`:null,d=!0;if(o.hasDefaultExport&&!o.hasSfcMainDefined)x(i,o,`_sfc_main`),u&&i.append(`\n_sfc_main.__scopeId = "${u}";`),i.append(`
|
|
68
|
+
export default _sfc_main;`);else if(o.hasDefaultExport)d=o.defaultExportIsSfcMain,d&&u&&i.append(`\n_sfc_main.__scopeId = "${u}";`);else if(!o.hasSfcMainDefined&&(o.hasNamedRenderExport||o.hasNamedSsrRenderExport)){let e=o.hasNamedRenderExport?`render`:`ssrRender`,t=u?`, __scopeId: "${u}"`:``;i.append(`\nconst _sfc_main = { ${e}${t} };\nexport default _sfc_main;`)}else d=!1;let f=e=>{d&&i.append(`\n${e}`)};if(e.templateAssetUrls.length>0&&i.edit(s(i.code,e.templateAssetUrls)),e.styles.length>0){if(a&&e.styles.some(e=>e.module))throw Error(`[vize] <style module> is not supported in custom elements mode.`);let t=e.styles.filter(e=>e.module===!0).length;if(t>1)throw Error(`[vize] Found ${t} unnamed <style module> blocks. Only one unnamed <style module> is allowed per SFC. Use named modules instead: <style module="name">`);let n=e.styles.filter(e=>e.src||/\S/.test(e.content)),o=[],s=n.map(t=>{let n=[`vue`,`type=style`,`index=${t.index}`,`lang=${t.lang||`css`}`,...t.scoped?[`scoped=${e.scopeId}`]:[],...t.module?[`module=${typeof t.module==`string`?t.module:`true`}`]:[],...a?[`inline`]:[],...t.src?[`src`]:[]],i=`${t.src??r.requestPath}?${n.join(`&`)}`;if(a)return`import _style_${t.index} from ${JSON.stringify(i)};`;if(t.module){let e=typeof t.module==`string`?t.module:`$style`,n=`_cssModule_${t.index}`;return o.push({request:i,varName:n,bindingName:e}),`import * as ${n} from ${JSON.stringify(i)};`}return`import ${JSON.stringify(i)};`}).join(`
|
|
69
|
+
`);i.prepend(`${s}\n`),a&&f(`_sfc_main.styles = [${n.map(e=>`_style_${e.index}`).join(`,`)}];`),!a&&o.length>0&&f(`${[r.nativeCss?``:`const __vize_resolve_css_module__ = (value) => value.default?.locals ?? (value.default && typeof value.default === "object" && !Array.isArray(value.default) ? value.default : value);`,...o.map(e=>`_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(e.bindingName)}] = ${r.nativeCss?e.varName:`__vize_resolve_css_module__(${e.varName})`};`)].filter(Boolean).join(`
|
|
70
|
+
`)}\n${r.hmr&&e.scopeId?o.map(t=>y(e.scopeId,JSON.stringify(t.request),r.nativeCss?t.varName:`__vize_resolve_css_module__(${t.varName})`,t.bindingName)).join(`
|
|
71
|
+
`):``}`)}if(r.filePath&&!r.isProduction){let e=r.rootContext?c.relative(r.rootContext,r.filePath).replace(/\\/g,`/`):c.basename(r.filePath);f(`_sfc_main.__file = ${JSON.stringify(e)};`)}if(e.customBlocks.length>0&&f(e.customBlocks.map((e,t)=>{let n=[`vue`,`type=${e.type}`,`index=${t}`,...e.src?[`src=true`]:[]];for(let[t,r]of Object.entries(e.attrs))t!==`src`&&(r===!0?n.push(t):n.push(`${t}=${r}`));let i=`${r.requestPath}?${n.join(`&`)}`;return`import block${t} from ${JSON.stringify(i)};\nif (typeof block${t} === 'function') block${t}(_sfc_main);`}).join(`
|
|
72
|
+
`)),e.templateAssetUrls.length>0){let t=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(`
|
|
73
|
+
`);i.prepend(`${t}\n`)}if(r.hmr&&e.scopeId&&d){let t=e.hmr&&{...e.hmr,module:l(`sha256`).update(i.code).digest(`hex`).slice(0,16),styles:JSON.stringify({scoped:e.hasScoped,blocks:e.styles.map(({content:e,...t})=>({...t,active:!!(t.src||/\S/.test(e))}))})};f(v(e.scopeId,t,D(i.code)??`null`))}return{code:i.code,map:i.map}}const{compileSfc:A}=o,{compileJsx:j}=o;function M(e){return e.endsWith(`.jsx`)||e.endsWith(`.tsx`)}function N(e,t,n){return`
|
|
74
|
+
export const __vize_css__ = ${JSON.stringify(t)};
|
|
75
|
+
const __vize_css_id__ = ${JSON.stringify(`vize-style-${n}`)};
|
|
76
|
+
(function() {
|
|
77
|
+
if (typeof document !== "undefined") {
|
|
78
|
+
let style = document.getElementById(__vize_css_id__);
|
|
79
|
+
if (!style) {
|
|
80
|
+
style = document.createElement("style");
|
|
81
|
+
style.id = __vize_css_id__;
|
|
82
|
+
style.textContent = __vize_css__;
|
|
83
|
+
document.head.appendChild(style);
|
|
84
|
+
} else {
|
|
85
|
+
style.textContent = __vize_css__;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
})();
|
|
89
|
+
${e}`}function P(e,t,n={}){let r=j(t,{filename:e,lang:e.endsWith(`.tsx`)?`tsx`:`jsx`,jsxMode:n.jsxMode,jsxCompat:n.jsxCompat,vapor:n.vapor??!1,sourceMap:n.sourceMap??!1});if(r.errors.length>0)throw Error(`[vize] Compilation failed for ${e}:\n${r.errors.join(`
|
|
90
|
+
`)}`);let i=(r.scopedStyles??[]).map(e=>e.css).join(`
|
|
91
|
+
`),a=r.code,o=r.map??null;if(i){let e=r.scopedStyles[0].scopeId.replace(/^data-v-/,``);({code:a,map:o}=g(a,o,N(``,i,e)))}return{code:a,map:o,warnings:r.warnings}}const F=new Map;function I(e){return l(`sha256`).update(e).digest(`hex`).slice(0,16)}function L(){F.clear()}function R(t,n,o={}){let s=o.compilerOptions?.isTs??/<script[^>]*\blang=["']ts["']/.test(n),c=o.ssr??o.compilerOptions?.ssr??!1,l=o.vapor??o.compilerOptions?.vapor??!1,u=o.sourceMap??o.compilerOptions?.sourceMap??!0,d=o.isCustomElement??!1,f=o.rootContext??``,p=o.isProduction??!1,m=o.transformAssetUrls??!0,h=`${t}:ssr=${c}:vapor=${l}:ts=${s}:map=${u}:ce=${d}:syntax=${o.compilerOptions?.templateSyntax??`standard`}:xic=${o.compilerOptions?.experimentalInTagComments??!1}:xpt=${o.compilerOptions?.experimentalPatternedTemplate??!1}:xsc=${o.compilerOptions?.experimentalSelfComponent??!1}:xslot=${o.compilerOptions?.experimentalStrictSlotChildren??!1}:xss=${o.compilerOptions?.experimentalServerScript??!1}:root=${f}:prod=${p}:${m===!1?`tau=false`:m===!0?`tau=true`:`tau=${JSON.stringify(m)}`}`,g=I(n),_=F.get(h);if(_&&_.contentHash===g)return _.result;let v=i(t,o.rootContext,o.isProduction,n),y={...o.compilerOptions,filename:t,sourceMap:o.sourceMap??o.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:s,scopeId:`data-v-${v}`},b=A(n,y),x=r(n,m),S={code:b.code,hmr:{source:g,script:b.scriptHash,template:b.templateHash,options:I(JSON.stringify(y)),canRerender:!l&&!c&&!d&&b.customBlocks.length===0},...b.map?{map:b.map}:{},css:b.css,errors:b.errors,warnings:b.warnings,scopeId:v,hasScoped:b.hasScoped,styles:b.styles.map(e),customBlocks:b.customBlocks.map(a),isCustomElement:d,templateAssetUrls:x,macroArtifacts:b.macroArtifacts??[],moduleShape:b.moduleShape};return S.errors.length===0&&F.set(h,{contentHash:g,result:S}),S}export{O as a,M as i,R as n,k as o,P as r,v as s,L as t};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ModuleShapeNapi } from "@vizejs/native";
|
|
2
|
+
|
|
1
3
|
//#region src/types/native.d.ts
|
|
2
4
|
/** Native compiler API types used by the Rspack adapter. */
|
|
3
5
|
interface SfcCompileOptionsNapi {
|
|
@@ -176,6 +178,8 @@ interface CompiledModule {
|
|
|
176
178
|
templateAssetUrls: TemplateAssetUrl[];
|
|
177
179
|
/** Compile-time macro artifacts extracted from the source SFC. */
|
|
178
180
|
macroArtifacts?: MacroArtifact[];
|
|
181
|
+
/** Shape of `code` reported by the native compiler; absent when compilation failed. */
|
|
182
|
+
moduleShape?: ModuleShapeNapi;
|
|
179
183
|
}
|
|
180
184
|
/** Native options with loader-level aliases retained for existing configurations. */
|
|
181
185
|
type VizeSfcCompilerOptions = Omit<SfcCompileOptionsNapi, "ssr" | "vapor" | "sourceMap"> & {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as StyleBlockInfo, c as VizeRspackPluginOptions, d as VizeStyleLoaderOptions, f as JsxCompileOptionsNapi, g as SfcCompileResultNapi, h as SfcCompileOptionsNapi, i as SfcSrcInfo, l as VizeSfcCompilerOptions, m as MacroArtifact, n as CustomBlockInfo, o as VizeJsxLoaderOptions, p as JsxCompileResultNapi, r as LoaderEntry, s as VizeLoaderOptions, t as CompiledModule, u as VizeSfcLoaderOptions } from "./index-
|
|
1
|
+
import { a as StyleBlockInfo, c as VizeRspackPluginOptions, d as VizeStyleLoaderOptions, f as JsxCompileOptionsNapi, g as SfcCompileResultNapi, h as SfcCompileOptionsNapi, i as SfcSrcInfo, l as VizeSfcCompilerOptions, m as MacroArtifact, n as CustomBlockInfo, o as VizeJsxLoaderOptions, p as JsxCompileResultNapi, r as LoaderEntry, s as VizeLoaderOptions, t as CompiledModule, u as VizeSfcLoaderOptions } from "./index-DYsdFxqp.mjs";
|
|
2
2
|
import vizeLoader from "./loader/index.mjs";
|
|
3
3
|
import vizeJsxLoader from "./loader/jsx-loader.mjs";
|
|
4
4
|
import vizeStyleLoader from "./loader/style-loader.mjs";
|
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-D_f3YvFb.mjs";import{n as s,r as c,t as l}from"./loader-
|
|
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-D_f3YvFb.mjs";import{n as s,r as c,t as l}from"./loader-NWh5yFoK.mjs";import{a as u,i as d,n as f,r as p,s as m,t as h}from"./compiler-CpqkQjxr.mjs";import g from"./loader/jsx-loader.mjs";import _ from"./loader/style-loader.mjs";import v from"./loader/scope-loader.mjs";import{createRequire as y}from"node:module";import{parse as b}from"node:querystring";const x=`@vizejs/rspack-plugin/loader`;let S;try{S=y(import.meta.url).resolve(x).replaceAll(`\\`,`/`)}catch{}function C(e){let t=e.replaceAll(`\\`,`/`);return e===x||t===S||(t.includes(`@vizejs/rspack-plugin/`)||t.includes(`rspack-vize-plugin/`))&&/\/dist\/loader\/index\.[cm]?js$/.test(t)}function w(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function T(e){return typeof e==`string`?e.startsWith(`{`)&&e.endsWith(`}`)?JSON.parse(e):b(e):w(e)?e:{}}function E(e,t,n=!0){function r(e){if(typeof e.loader!=`string`||!C(e.loader))return;let r=T(e.options),i=w(r.css)?r.css:{};if(i.native!==void 0){if(!n)return;if(i.native!==t)throw Error(`[vize] Loader css.native conflicts with VizePlugin's automatic CSS mode. Configure a matching mode on VizePlugin, or set autoRules: false and provide matching style sub-request rules. See MIGRATION.md.`)}e.options={...r,css:{...i,native:t}}}function i(e){if(typeof e==`string`&&C(e)){let t={loader:e};return r(t),t}return w(e)&&r(e),e}function a(e){for(let t of e)w(t)&&(r(t),Array.isArray(t.use)?t.use=t.use.map(i):t.use!==void 0&&typeof t.use!=`function`&&(t.use=i(t.use)),Array.isArray(t.oneOf)&&a(t.oneOf),Array.isArray(t.rules)&&a(t.rules))}a(e)}const D=`@vizejs/rspack-plugin/style-loader`,O=`@vizejs/rspack-plugin/scope-loader`,k={"\\.css$":`css`,"\\.scss$":`scss`,"\\.sass$":`sass`,"\\.less$":`less`,"\\.styl(us)?$":`styl`};function A(e,t){let n=[],r=e.findIndex(e=>e!==`...`&&j(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=N(n);i&&a.push({index:t,rule:n,lang:i})}let o=[];for(let e of a)o.push(...P(e.rule,e.lang,t));o.some(e=>e.resourceQuery instanceof RegExp&&e.resourceQuery.test(`vue&type=style&index=0&lang=css`))||o.push(...F(t));let{test:s,include:c,exclude:l,resource:u,descriptionData:d,...f}=i,p={...f,loader:void 0,options:void 0,use:z(R(i))};E([p],t);for(let e of o)e.sideEffects=!0;e[r]={test:s,include:c,exclude:l,resource:u,descriptionData:d,oneOf:[...o,p]},e.splice(r+1,0,{resourceQuery:/(?=.*\bvue\b)(?=.*type=style)(?=.*&src(?:&|$))/,oneOf:o.map(e=>({...e,use:z(L(e.use))}))});for(let e of a)I(e.rule);return{applied:!0,clonedCount:o.length,warnings:n}}function j(e){return M(e.test)?R(e).some(e=>{let t=typeof e==`string`?e:e.loader;return t?C(t):!1}):!1}function M(e){return e?e instanceof RegExp?e.test(`App.vue`)||e.test(`foo.vue`):typeof e==`string`?e.includes(`.vue`):!1:!1}function N(e){let t=e.test;if(!t||!(t instanceof RegExp))return null;let n=t.source;for(let[e,t]of Object.entries(k))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 P(e,t,n){let r=R(e);if(r.length===0)return[];let i=z(r),a=n?-1:i.findIndex(e=>{let t=typeof e==`string`?e:e.loader;return/(?:^|[/\\])css-loader(?:[/\\?]|$)/.test(t??``)});i.splice(a+1,0,{loader:O}),i.push({loader:D});let o=(t,n)=>{let r={resourceQuery:t,use:z(i)};return n===`css/module`&&(!e.type||e.type===`css/auto`)?r.type=n:e.type?r.type=e.type:n&&(r.type=n),r};return n?[o(RegExp(`(?=.*type=style)(?=.*lang=${t})(?=.*module=)`),`css/module`),o(RegExp(`(?=.*type=style)(?=.*lang=${t})`),`css/auto`)]:[o(RegExp(`(?=.*type=style)(?=.*lang=${t})`))]}function F(e){return e?[{resourceQuery:/(?=.*type=style)(?=.*lang=css)(?=.*module=)/,type:`css/module`,use:[{loader:O},{loader:D}]},{resourceQuery:/(?=.*type=style)(?=.*lang=css)/,type:`css/auto`,use:[{loader:O},{loader:D}]}]:[{resourceQuery:/(?=.*type=style)(?=.*lang=css)/,type:`javascript/auto`,use:[{loader:O},{loader:D}]}]}function I(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 L(e){return e?Array.isArray(e)?e:[e]:[]}function R(e){let t=L(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 z(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 B=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`,i=[`include`,`exclude`,`isProduction`,`ssr`,`sourceMap`,`vapor`,`jsxMode`,`jsxCompat`,`root`,`compilerOptions`].filter(e=>this.options[e]!==void 0);i.length>0&&n.warn(`Deprecated VizePlugin options: ${i.join(`, `)}. Compilation options belong in loader options; file filters belong in module.rules. Legacy plugin behavior is unchanged: compilation options are not forwarded. See MIGRATION.md.`),this.options.debug&&this.options.vapor&&!r&&n.debug(`Legacy plugin vapor is set; configure vapor on the loader to select compilation mode.`);let a=s(t.options),o=t.webpack?.rspackVersion,l=c(this.options.css?.native,t.options,o);this.options.css?.native&&a===`disabled`&&n.warn("`css.native: true` is set but `experiments.css` is not enabled in rspack config.");let u=t.options.module?.rules,d=this.options.autoRules??!0;if(u&&E(u,l,d),d){let e=t.options.module?.rules;if(e){let t=A(e,l);t.applied&&this.options.debug&&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`}),this.options.debug&&n.debug(`Auto-injected TypeScript post-processing rule for .vue files.`)))}let{DefinePlugin:f}=t.webpack,p=new Set;for(let e of t.options.plugins??[]){let t=e?.definitions;if(t)for(let e of Object.keys(t))p.add(e)}let m={};p.has(`__VUE_OPTIONS_API__`)||(m.__VUE_OPTIONS_API__=JSON.stringify(!0)),p.has(`__VUE_PROD_DEVTOOLS__`)||(m.__VUE_PROD_DEVTOOLS__=JSON.stringify(!r)),p.has(`__VUE_PROD_HYDRATION_MISMATCH_DETAILS__`)||(m.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__=JSON.stringify(!r)),Object.keys(m).length>0&&new f(m).apply(t),this.options.debug&&!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{B as VizePlugin,o as addScopeToCssFallback,A as applyRuleCloning,h as clearCompilationCache,f as compileFile,p as compileJsxModule,i as extractCustomBlocks,n as extractSrcInfo,e as extractStyleBlocks,m 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-NWh5yFoK.mjs";export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,m as t}from"../utils-D_f3YvFb.mjs";import{r as n}from"../compiler-
|
|
1
|
+
import{c as e,m as t}from"../utils-D_f3YvFb.mjs";import{r as n}from"../compiler-CpqkQjxr.mjs";function r(e){let r=this.async(),a=this.getOptions(),o=this.resourcePath;if(this.addDependency(o),!i(o,a)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${o}. Passing through source unchanged.`)),r(null,e);return}try{let i=this.mode===`production`||process.env.NODE_ENV===`production`,s=a.sourceMap??this.sourceMap??!i,{code:c,map:l,warnings:u}=n(o,e,{jsxMode:a.jsxMode,jsxCompat:a.jsxCompat,vapor:a.vapor??!1,sourceMap:s});for(let e of u)this.emitWarning(Error(`[vize] ${e}`));r(null,c,t(l)?l:void 0)}catch(e){r(e)}}function i(t,n){return!(!e(t,n.include,!0)||e(t,n.exclude,!1))}export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,f as t,i as n,p as r,r as i}from"./utils-D_f3YvFb.mjs";import{n as a,o}from"./compiler-
|
|
1
|
+
import{c as e,f as t,i as n,p as r,r as i}from"./utils-D_f3YvFb.mjs";import{n as a,o}from"./compiler-CpqkQjxr.mjs";import{sources as s}from"@rspack/core";import c from"node:fs";import l from"node:path";function u(e){let t=e?.experiments;return!t||typeof t!=`object`||!Object.prototype.hasOwnProperty.call(t,`css`)?`unavailable`:t.css?`enabled`:`disabled`}function d(e){if(typeof e!=`string`)return null;let t=Number.parseInt(e,10);return Number.isNaN(t)?null:t}function f(e,t,n){if(e!=null)return e;let r=u(t);if(r!==`unavailable`)return r===`enabled`;let i=d(n);return i!=null&&i>=2}const p=/\.ce\.vue$/;function m(e){let u=this.async(),d=this.getOptions(),f=this.resourcePath,p=this.resourceQuery,m=v(this,f),y=d.isProduction??(this.mode===`production`||process.env.NODE_ENV===`production`),b=d.ssr??d.compilerOptions?.ssr??!1,x=!b&&!y&&d.hotReload!==!1,S=g(this,d),C=d.sourceMap??d.compilerOptions?.sourceMap??this.sourceMap??!y;if(this.addDependency(f),p?.includes(`type=style`)){u(Error(`[vize] Main loader received style sub-request: ${f}${p}. Use module.rules[].oneOf with resourceQuery branches so style requests are handled by @vizejs/rspack-plugin/style-loader.`));return}if(p&&p.includes(`vue`)&&p.includes(`type=`)&&!p.includes(`type=style`)){let t=new URLSearchParams(p.slice(1)),n=t.get(`type`);if(n&&n!==`style`){let r=parseInt(t.get(`index`)||`0`,10),a=i(e)[r];if(a){if(a.src){let e=l.resolve(l.dirname(f),a.src);this.addDependency(e);try{u(null,c.readFileSync(e,`utf-8`))}catch{u(Error(`[vize] Custom block <${n} src="${a.src}"> not found (resolved: ${e}) in ${f}`))}return}u(null,a.content)}else u(null,``);return}}if(!h(f,d)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${f}. Passing through source unchanged.`)),u(null,e);return}try{let i=_(f,d.customElement),p=n(e),h=new t(e,C&&(p.scriptSrc||p.templateSrc)?new s.OriginalSource(e,f).map({columns:!0}):null);if(p.scriptSrc){let e=l.resolve(l.dirname(f),p.scriptSrc);this.addDependency(e);try{r(h,`script`,c.readFileSync(e,`utf-8`),e)}catch{u(Error(`[vize] <script src="${p.scriptSrc}"> not found (resolved: ${e}) in ${f}`));return}}if(p.templateSrc){let e=l.resolve(l.dirname(f),p.templateSrc);this.addDependency(e);try{r(h,`template`,c.readFileSync(e,`utf-8`),e)}catch{u(Error(`[vize] <template src="${p.templateSrc}"> not found (resolved: ${e}) in ${f}`));return}}let g=d.root?l.resolve(this.rootContext,d.root):this.rootContext,v=a(f,h.code,{sourceMap:C,ssr:b,vapor:d.vapor??d.compilerOptions?.vapor??!1,compilerOptions:d.compilerOptions,isCustomElement:i,rootContext:g,isProduction:y,transformAssetUrls:d.transformAssetUrls});for(let e of v.warnings)this.emitWarning(Error(`[vize] ${e}`));if(v.errors.length>0){for(let e of v.errors)this.emitError(Error(`[vize] ${e}`));let e=v.errors.join(`\\n`);u(Error(`[vize] Compilation failed for ${f}:\n${e}`));return}let w=o(v,{requestPath:m,hmr:x,filePath:f,isProduction:y,rootContext:g,nativeCss:S}),T=w.map&&h.map?new s.SourceMapSource(w.code,f,JSON.stringify(w.map),h.code,JSON.stringify(h.map),!0).map({columns:!0}):w.map;u(null,w.code,T?JSON.stringify(T):void 0)}catch(e){u(e)}}function h(t,n){return!(!e(t,n.include,!0)||e(t,n.exclude,!1))}function g(e,t){let n=e._compiler;return f(t.css?.native,n?.options,n?.webpack?.rspackVersion)}function _(e,t){return t===!0?!0:t===!1||t===void 0?p.test(e):t.test(e)}function v(e,t){return`./${l.basename(t)}`}export{u as n,f as r,m as t};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/rspack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.671.0",
|
|
4
4
|
"description": "High-performance Rspack plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@vizejs/native": "0.
|
|
62
|
+
"@vizejs/native": "0.671.0",
|
|
63
63
|
"diff": "8.0.4",
|
|
64
64
|
"oxc-parser": "0.144.0",
|
|
65
65
|
"oxc-transform": "0.144.0",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"check": "vp check src vite.config.ts",
|
|
97
97
|
"check:fix": "vp check --fix src vite.config.ts",
|
|
98
98
|
"fmt": "vp fmt --write src vite.config.ts",
|
|
99
|
-
"test": "pnpm build && node --test src/*.test.ts src/**/*.test.ts",
|
|
99
|
+
"test": "pnpm build && node --test src/*.test.ts src/**/*.test.ts ../shared/*.test.ts",
|
|
100
100
|
"test:hmr": "pnpm build && node --test test/hmr.test.mjs",
|
|
101
101
|
"test:update": "pnpm build && node --test --test-update-snapshots src/*.test.ts src/**/*.test.ts"
|
|
102
102
|
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import{d as e,f as t,m as n,n as r,o as i,u as a}from"./utils-D_f3YvFb.mjs";import*as o from"@vizejs/native";import{rewriteSfcTemplateAssetReferences as s}from"@vizejs/native";import c from"node:path";import{createHash as l}from"node:crypto";import{parseSync as u}from"oxc-parser";import{transformSync as d}from"oxc-transform";function f(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.version===3&&Array.isArray(t.sources)&&Array.isArray(t.names)&&typeof t.mappings==`string`}function p(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}return f(t)?t:null}function m(e){let t=0;for(let n=e.indexOf(`
|
|
2
|
-
`);n!==-1;n=e.indexOf(`
|
|
3
|
-
`,n+1))t++;return t}function h(e,t,n){if(n<=0)return e;let r=e.mappings.split(`;`);if(t>=r.length)return e;let i=[...r.slice(0,t),...Array(n).fill(``),...r.slice(t)];return{...e,mappings:i.join(`;`)}}function g(e,t,n){let r=n+e;if(!n)return{code:r,map:t??null};let i=p(t);return!i||!n.endsWith(`
|
|
4
|
-
`)?{code:r,map:null}:{code:r,map:JSON.stringify(h(i,0,m(n)))}}function _(e,t){return`{
|
|
5
|
-
const current = ${e}
|
|
6
|
-
const next = ${t}
|
|
7
|
-
Object.keys(current).forEach(key => {
|
|
8
|
-
if (!Object.prototype.hasOwnProperty.call(next, key)) delete current[key]
|
|
9
|
-
})
|
|
10
|
-
Object.assign(current, next)
|
|
11
|
-
}`}function v(e,t,n=`null`,r=`module.hot`,i=`_sfc_main`){return`
|
|
12
|
-
/* hot reload */
|
|
13
|
-
if (${r}) {
|
|
14
|
-
${i}.__hmrId = "${e}"
|
|
15
|
-
const api = __VUE_HMR_RUNTIME__
|
|
16
|
-
const previous = ${r}.data && ${r}.data.vize
|
|
17
|
-
// Own writable mappings; CSS module namespace exports may be read-only.
|
|
18
|
-
if (${i}.__cssModules) {
|
|
19
|
-
Object.keys(${i}.__cssModules).forEach(name => {
|
|
20
|
-
${i}.__cssModules[name] = Object.assign(Object.create(null), ${i}.__cssModules[name])
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
const current = {
|
|
24
|
-
metadata: ${JSON.stringify(t??null)},
|
|
25
|
-
imports: (() => {
|
|
26
|
-
// A circular import may still be uninitialized. An unavailable snapshot
|
|
27
|
-
// disables state preservation without changing module loading semantics.
|
|
28
|
-
try { return ${n} } catch { return null }
|
|
29
|
-
})(),
|
|
30
|
-
component: ${i},
|
|
31
|
-
setup: ${i}.setup && ${i}.setup.toString()
|
|
32
|
-
}
|
|
33
|
-
${r}.dispose(data => { data.vize = current })
|
|
34
|
-
${r}.accept()
|
|
35
|
-
if (!api.createRecord('${e}', ${i})) {
|
|
36
|
-
const before = previous && previous.metadata
|
|
37
|
-
const after = current.metadata
|
|
38
|
-
const sameImports = previous && previous.imports && current.imports &&
|
|
39
|
-
previous.imports.length === current.imports.length &&
|
|
40
|
-
current.imports.every((entry, index) => entry[0] === previous.imports[index][0] && Object.is(entry[1], previous.imports[index][1]))
|
|
41
|
-
const canPreserve = before && after && before.canRerender && after.canRerender &&
|
|
42
|
-
before.source !== after.source &&
|
|
43
|
-
before.options === after.options && before.styles === after.styles && sameImports &&
|
|
44
|
-
previous.setup === current.setup
|
|
45
|
-
if (canPreserve && (before.module === after.module ||
|
|
46
|
-
(typeof before.script === 'string' && before.script === after.script &&
|
|
47
|
-
typeof before.template === 'string' && typeof after.template === 'string' &&
|
|
48
|
-
before.template !== after.template && typeof ${i}.render === 'function'))) {
|
|
49
|
-
// Retain both the module table and each mapping captured by setup.
|
|
50
|
-
if (previous.component.__cssModules && ${i}.__cssModules) {
|
|
51
|
-
Object.keys(${i}.__cssModules).forEach(name => ${_(`previous.component.__cssModules[name]`,`${i}.__cssModules[name]`)})
|
|
52
|
-
${i}.__cssModules = previous.component.__cssModules
|
|
53
|
-
}
|
|
54
|
-
if (before.module !== after.module || ${i}.__cssModules) {
|
|
55
|
-
api.rerender('${e}', ${i}.render)
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
api.reload('${e}', ${i})
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}`}function y(e,t,n,r,i=`module.hot`,a=`_sfc_main`){return`
|
|
62
|
-
if (${i}) {
|
|
63
|
-
${i}.accept(${t}, () => {
|
|
64
|
-
${_(`${a}.__cssModules[${JSON.stringify(r)}]`,n)}
|
|
65
|
-
__VUE_HMR_RUNTIME__.rerender("${e}", ${a}.render)
|
|
66
|
-
})
|
|
67
|
-
}`}const b=`vize-rspack-output.tsx`,x=`_sfc_main`;function S(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function C(e){return typeof e?.start==`number`?e.start:null}function w(e){return S(e)&&typeof e.name==`string`?e.name:null}function T(e){try{let t=u(b,e);if(typeof t==`object`&&t){let e=t.errors;if(Array.isArray(e)&&e.length>0)return null;let n=t.program;if(S(n))return n}return S(t)?t:null}catch{return null}}function E(e){return!e||!Array.isArray(e.body)?[]:e.body.filter(S)}function D(e,t){return w(e)===t}function O(e){return(Array.isArray(e.declarations)?e.declarations:[]).filter(S).map(e=>S(e.id)?w(e.id):null).filter(e=>e!=null)}function k(e){return E(e).find(e=>e.type===`ExportDefaultDeclaration`)??null}function A(e,t){let n=C(t);if(n==null)return null;let r=/^export\s+default\b/.exec(e.slice(n));return r?n+r[0].length:null}function j(e){let t=S(e.declaration)?e.declaration:null,n=[];if(t?.type===`FunctionDeclaration`||t?.type===`ClassDeclaration`){let e=S(t.id)?w(t.id):null;e&&n.push(e)}t?.type===`VariableDeclaration`&&n.push(...O(t));let r=Array.isArray(e.specifiers)?e.specifiers:[];for(let e of r.filter(S)){let t=w(S(e.exported)?e.exported:null)??w(S(e.local)?e.local:null);t&&n.push(t)}return n}function M(e){let t=T(e),n=E(t),r=k(t),i=n.filter(e=>e.type===`ExportNamedDeclaration`).flatMap(j);return{hasDefaultExport:r!=null,hasSfcMainDefined:n.some(e=>e.type===`VariableDeclaration`&&O(e).includes(x)),hasNamedRenderExport:i.includes(`render`),hasNamedSsrRenderExport:i.includes(`ssrRender`)}}function N(e){let t=d(b,e,{target:`esnext`,jsx:`preserve`});if(t.errors.length)return null;let n=T(t.code);if(!n)return null;let r=[];for(let e of E(n)){if(e.type!==`ImportDeclaration`)continue;let t=S(e.source)?e.source.value:null;if(typeof t!=`string`)return null;if(t===`vue`||t.includes(`?vue&type=style&`))continue;let n=Array.isArray(e.specifiers)?e.specifiers.filter(S):[];if(n.length===0)return null;for(let e of n){let n=S(e.local)?w(e.local):null;if(!n)return null;let i=JSON.stringify(`${t}:${n}`);r.push(e.type===`ImportNamespaceSpecifier`?`...Object.keys(${n}).sort().map(key => [${i} + ':' + key, ${n}[key]])`:`[${i}, ${n}]`)}}return`[${r.join(`, `)}]`}function P(e){let t=e.code,n=k(T(t)),r=C(n),i=n?A(t,n):null;r==null||i==null||e.replace(r,i,`const ${x} =`)}function F(e,t,n={}){let r=e.code,i=k(T(r)),a=S(i?.declaration)?i.declaration:null,o=C(i),s=typeof i?.end==`number`?i.end:null;!D(a,x)||o==null||(n.normalizeSemicolon&&s!=null&&r[s-1]!==`;`&&r[s]!==`;`&&e.replace(s,s,`;`),e.replace(o,o,`${t}\n`))}function I(e,t){return L(e,t).code}function L(e,r){let i=new t(e.code,n(e.map)),a=e.isCustomElement;e.templateAssetUrls.length>0&&i.edit(s(i.code,e.templateAssetUrls));let o=M(i.code),u=o.hasDefaultExport,d=o.hasSfcMainDefined;if(u&&!d)P(i),e.hasScoped&&e.scopeId&&i.append(`\n_sfc_main.__scopeId = "data-v-${e.scopeId}";`),i.append(`
|
|
68
|
-
export default _sfc_main;`);else if(u&&d&&e.hasScoped&&e.scopeId)F(i,`_sfc_main.__scopeId = "data-v-${e.scopeId}";`);else if(!u&&!d){let t=o.hasNamedRenderExport?`render`:o.hasNamedSsrRenderExport?`ssrRender`:null;if(t){let n=e.hasScoped&&e.scopeId?`, __scopeId: "data-v-${e.scopeId}"`:``;i.append(`\nconst _sfc_main = { ${t}${n} };\nexport default _sfc_main;`)}}if(e.styles.length>0){if(a&&e.styles.some(e=>e.module))throw Error(`[vize] <style module> is not supported in custom elements mode.`);let t=e.styles.filter(e=>e.module===!0).length;if(t>1)throw Error(`[vize] Found ${t} unnamed <style module> blocks. Only one unnamed <style module> is allowed per SFC. Use named modules instead: <style module="name">`);let n=e.styles.filter(e=>e.src||/\S/.test(e.content)),o=[],s=n.map(t=>{let n=[`vue`,`type=style`,`index=${t.index}`,`lang=${t.lang||`css`}`,...t.scoped?[`scoped=${e.scopeId}`]:[],...t.module?[`module=${typeof t.module==`string`?t.module:`true`}`]:[],...a?[`inline`]:[],...t.src?[`src`]:[]],i=`${t.src??r.requestPath}?${n.join(`&`)}`;if(a)return`import _style_${t.index} from ${JSON.stringify(i)};`;if(t.module){let e=typeof t.module==`string`?t.module:`$style`,n=`_cssModule_${t.index}`;return o.push({request:i,varName:n,bindingName:e}),`import * as ${n} from ${JSON.stringify(i)};`}return`import ${JSON.stringify(i)};`}).join(`
|
|
69
|
-
`);i.prepend(`${s}\n`),a&&F(i,`_sfc_main.styles = [${n.map(e=>`_style_${e.index}`).join(`,`)}];`,{normalizeSemicolon:!0}),!a&&o.length>0&&F(i,`${[r.nativeCss?``:`const __vize_resolve_css_module__ = (value) => value.default?.locals ?? (value.default && typeof value.default === "object" && !Array.isArray(value.default) ? value.default : value);`,...o.map(e=>`_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(e.bindingName)}] = ${r.nativeCss?e.varName:`__vize_resolve_css_module__(${e.varName})`};`)].filter(Boolean).join(`
|
|
70
|
-
`)}\n${r.hmr&&e.scopeId?o.map(t=>y(e.scopeId,JSON.stringify(t.request),r.nativeCss?t.varName:`__vize_resolve_css_module__(${t.varName})`,t.bindingName)).join(`
|
|
71
|
-
`):``}`,{normalizeSemicolon:!0})}if(r.filePath&&!r.isProduction){let e=r.rootContext?c.relative(r.rootContext,r.filePath).replace(/\\/g,`/`):c.basename(r.filePath);F(i,`_sfc_main.__file = ${JSON.stringify(e)};`,{normalizeSemicolon:!0})}if(e.customBlocks.length>0&&F(i,e.customBlocks.map((e,t)=>{let n=[`vue`,`type=${e.type}`,`index=${t}`,...e.src?[`src=true`]:[]];for(let[t,r]of Object.entries(e.attrs))t!==`src`&&(r===!0?n.push(t):n.push(`${t}=${r}`));let i=`${r.requestPath}?${n.join(`&`)}`;return`import block${t} from ${JSON.stringify(i)};\nif (typeof block${t} === 'function') block${t}(_sfc_main);`}).join(`
|
|
72
|
-
`),{normalizeSemicolon:!0}),e.templateAssetUrls.length>0){let t=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(`
|
|
73
|
-
`);i.prepend(`${t}\n`)}if(r.hmr&&e.scopeId){let t=e.hmr&&{...e.hmr,module:l(`sha256`).update(i.code).digest(`hex`).slice(0,16),styles:JSON.stringify({scoped:e.hasScoped,blocks:e.styles.map(({content:e,...t})=>({...t,active:!!(t.src||/\S/.test(e))}))})};F(i,v(e.scopeId,t,N(i.code)??`null`),{normalizeSemicolon:!0})}return{code:i.code,map:i.map}}const{compileSfc:R}=o,{compileJsx:z}=o;function B(e){return e.endsWith(`.jsx`)||e.endsWith(`.tsx`)}function V(e,t,n){return`
|
|
74
|
-
export const __vize_css__ = ${JSON.stringify(t)};
|
|
75
|
-
const __vize_css_id__ = ${JSON.stringify(`vize-style-${n}`)};
|
|
76
|
-
(function() {
|
|
77
|
-
if (typeof document !== "undefined") {
|
|
78
|
-
let style = document.getElementById(__vize_css_id__);
|
|
79
|
-
if (!style) {
|
|
80
|
-
style = document.createElement("style");
|
|
81
|
-
style.id = __vize_css_id__;
|
|
82
|
-
style.textContent = __vize_css__;
|
|
83
|
-
document.head.appendChild(style);
|
|
84
|
-
} else {
|
|
85
|
-
style.textContent = __vize_css__;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})();
|
|
89
|
-
${e}`}function H(e,t,n={}){let r=z(t,{filename:e,lang:e.endsWith(`.tsx`)?`tsx`:`jsx`,jsxMode:n.jsxMode,jsxCompat:n.jsxCompat,vapor:n.vapor??!1,sourceMap:n.sourceMap??!1});if(r.errors.length>0)throw Error(`[vize] Compilation failed for ${e}:\n${r.errors.join(`
|
|
90
|
-
`)}`);let i=(r.scopedStyles??[]).map(e=>e.css).join(`
|
|
91
|
-
`),a=r.code,o=r.map??null;if(i){let e=r.scopedStyles[0].scopeId.replace(/^data-v-/,``);({code:a,map:o}=g(a,o,V(``,i,e)))}return{code:a,map:o,warnings:r.warnings}}const U=new Map;function W(e){return l(`sha256`).update(e).digest(`hex`).slice(0,16)}function G(){U.clear()}function K(t,n,o={}){let s=o.compilerOptions?.isTs??/<script[^>]*\blang=["']ts["']/.test(n),c=o.ssr??o.compilerOptions?.ssr??!1,l=o.vapor??o.compilerOptions?.vapor??!1,u=o.sourceMap??o.compilerOptions?.sourceMap??!0,d=o.isCustomElement??!1,f=o.rootContext??``,p=o.isProduction??!1,m=o.transformAssetUrls??!0,h=`${t}:ssr=${c}:vapor=${l}:ts=${s}:map=${u}:ce=${d}:syntax=${o.compilerOptions?.templateSyntax??`standard`}:xic=${o.compilerOptions?.experimentalInTagComments??!1}:xpt=${o.compilerOptions?.experimentalPatternedTemplate??!1}:xsc=${o.compilerOptions?.experimentalSelfComponent??!1}:xslot=${o.compilerOptions?.experimentalStrictSlotChildren??!1}:xss=${o.compilerOptions?.experimentalServerScript??!1}:root=${f}:prod=${p}:${m===!1?`tau=false`:m===!0?`tau=true`:`tau=${JSON.stringify(m)}`}`,g=W(n),_=U.get(h);if(_&&_.contentHash===g)return _.result;let v=i(t,o.rootContext,o.isProduction,n),y={...o.compilerOptions,filename:t,sourceMap:o.sourceMap??o.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:s,scopeId:`data-v-${v}`},b=R(n,y),x=r(n,m),S={code:b.code,hmr:{source:g,script:b.scriptHash,template:b.templateHash,options:W(JSON.stringify(y)),canRerender:!l&&!c&&!d&&b.customBlocks.length===0},...b.map?{map:b.map}:{},css:b.css,errors:b.errors,warnings:b.warnings,scopeId:v,hasScoped:b.hasScoped,styles:b.styles.map(e),customBlocks:b.customBlocks.map(a),isCustomElement:d,templateAssetUrls:x,macroArtifacts:b.macroArtifacts??[]};return S.errors.length===0&&U.set(h,{contentHash:g,result:S}),S}export{I as a,B as i,K as n,L as o,H as r,v as s,G as t};
|