@vizejs/rspack-plugin 0.284.0 → 0.286.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.
@@ -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{rewriteSfcTemplateAssetReferences as a}from"@vizejs/native";import o from"node:path";import{createHash as s}from"node:crypto";import{parseSync as c}from"oxc-parser";function l(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 u(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
+ }`}const d=`_sfc_main`;function f(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function p(e){return typeof e?.start==`number`?e.start:null}function m(e){return f(e)&&typeof e.name==`string`?e.name:null}function h(e){try{let t=c(`vize-rspack-output.tsx`,e);if(typeof t==`object`&&t){let e=t.errors;if(Array.isArray(e)&&e.length>0)return null;let n=t.program;if(f(n))return n}return f(t)?t:null}catch{return null}}function g(e){return!e||!Array.isArray(e.body)?[]:e.body.filter(f)}function _(e,t){return m(e)===t}function v(e){return(Array.isArray(e.declarations)?e.declarations:[]).filter(f).map(e=>f(e.id)?m(e.id):null).filter(e=>e!=null)}function y(e){return g(e).find(e=>e.type===`ExportDefaultDeclaration`)??null}function b(e,t){let n=p(t);if(n==null)return null;let r=/^export\s+default\b/.exec(e.slice(n));return r?n+r[0].length:null}function x(e){let t=h(e),n=g(t);return{hasDefaultExport:y(t)!=null,hasSfcMainDefined:n.some(e=>e.type===`VariableDeclaration`&&v(e).includes(d))}}function S(e){let t=y(h(e)),n=p(t),r=t?b(e,t):null;return n==null||r==null?e:`${e.slice(0,n)}const ${d} =${e.slice(r)}`}function C(e,t,n={}){let r=y(h(e)),i=f(r?.declaration)?r.declaration:null,a=p(r),o=typeof r?.end==`number`?r.end:null;if(!_(i,d)||a==null)return e;if(n.normalizeSemicolon&&o!=null){let n=e[o]===`;`?o+1:o;return`${e.slice(0,a)}${t}\nexport default ${d};${e.slice(n)}`}return`${e.slice(0,a)}${t}\n${e.slice(a)}`}function w(e,t){let n=e.code,r=e.isCustomElement;e.templateAssetUrls.length>0&&(n=a(n,e.templateAssetUrls));let i=x(n),s=i.hasDefaultExport,c=i.hasSfcMainDefined;if(s&&!c?(n=S(n),e.hasScoped&&e.scopeId&&(n+=`\n_sfc_main.__scopeId = "data-v-${e.scopeId}";`),n+=`
17
+ export default _sfc_main;`):s&&c&&e.hasScoped&&e.scopeId&&(n=C(n,`_sfc_main.__scopeId = "data-v-${e.scopeId}";`)),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=C(n,`_sfc_main.styles = [${e}];`,{normalizeSemicolon:!0})}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=>u(e.scopeId,JSON.stringify(t.request),t.varName,t.bindingName)).join(`
21
+ `):``;n=C(n,`${r}\n${i}`,{normalizeSemicolon:!0})}}if(t.filePath&&!t.isProduction){let e=t.rootContext?o.relative(t.rootContext,t.filePath).replace(/\\/g,`/`):o.basename(t.filePath);n=C(n,`_sfc_main.__file = ${JSON.stringify(e)};`,{normalizeSemicolon:!0})}if(t.hmr&&e.scopeId&&(n=C(n,l(e.scopeId),{normalizeSemicolon:!0})),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=C(n,r,{normalizeSemicolon:!0})}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:T}=i,{compileJsx:E}=i;function D(e){return e.endsWith(`.jsx`)||e.endsWith(`.tsx`)}function O(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 k(e,t,n={}){let r=E(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=O(a,i,e),o=null}return{code:a,map:o,warnings:r.warnings}}const A=new Map;function j(e){return s(`sha256`).update(e).digest(`hex`).slice(0,16)}function M(){A.clear()}function N(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,u=o.sourceMap??o.compilerOptions?.sourceMap??!0,d=o.isCustomElement??!1,f=o.rootContext??``,p=o.isProduction??!1,m=o.transformAssetUrls??!0,h=`${i}:ssr=${c}:vapor=${l}:ts=${s}:map=${u}:ce=${d}:syntax=${o.compilerOptions?.templateSyntax??`standard`}:root=${f}:prod=${p}:${m===!1?`tau=false`:m===!0?`tau=true`:`tau=${JSON.stringify(m)}`}`,g=j(a),_=A.get(h);if(_&&_.contentHash===g)return _.result;let v=n(i,o.rootContext,o.isProduction,a),y=T(a,{...o.compilerOptions,filename:i,sourceMap:o.sourceMap??o.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:s,scopeId:`data-v-${v}`}),b=t(a,m),x={code:y.code,css:y.css,errors:y.errors,warnings:y.warnings,scopeId:v,hasScoped:y.hasScoped,styles:y.styles.map(e),customBlocks:y.customBlocks.map(r),isCustomElement:d,templateAssetUrls:b,macroArtifacts:y.macroArtifacts??[]};return x.errors.length===0&&A.set(h,{contentHash:g,result:x}),x}export{w as a,D as i,N as n,l as o,k as r,M as t};
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{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){let t=e.replaceAll(`\\`,`/`);return e===`@vizejs/rspack-plugin/loader`||(t.includes(`@vizejs/rspack-plugin`)||t.includes(`rspack-vize-plugin`))&&/\/dist\/loader\/index\.[cm]?js$/.test(t)}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};
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-Lgg-oaBX.mjs";import{a as u,i as d,n as f,o as p,r as m,t as h}from"./compiler-CC1Pk6sT.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){let t=e.replaceAll(`\\`,`/`);return e===`@vizejs/rspack-plugin/loader`||(t.includes(`@vizejs/rspack-plugin`)||t.includes(`rspack-vize-plugin`))&&/\/dist\/loader\/index\.[cm]?js$/.test(t)}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};
@@ -1 +1 @@
1
- import{t as e}from"../loader-hFzurQxg.mjs";export{e as default};
1
+ import{t as e}from"../loader-Lgg-oaBX.mjs";export{e as default};
@@ -1 +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};
1
+ import{c as e}from"../utils-CFK8mca_.mjs";import{r as t}from"../compiler-CC1Pk6sT.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};
@@ -1 +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};
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-CC1Pk6sT.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.284.0",
3
+ "version": "0.286.0",
4
4
  "description": "High-performance Rspack plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -59,7 +59,8 @@
59
59
  "access": "public"
60
60
  },
61
61
  "dependencies": {
62
- "@vizejs/native": "0.284.0"
62
+ "@vizejs/native": "0.286.0",
63
+ "oxc-parser": "0.133.0"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@rspack/core": "2.0.3",
@@ -1,42 +0,0 @@
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};