@vizejs/rspack-plugin 0.33.0 → 0.34.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,74 @@
1
+ import { a as SfcCompileResultNapi, c as VizeLoaderOptions, i as SfcCompileOptionsNapi, l as VizeRspackPluginOptions, n as CustomBlockInfo, o as SfcSrcInfo, r as LoaderEntry, s as StyleBlockInfo, t as CompiledModule, u as VizeStyleLoaderOptions } from "./index-Bvwqw7T6.mjs";
2
+ import vizeLoader from "./loader/index.mjs";
3
+ import vizeStyleLoader from "./loader/style-loader.mjs";
4
+ import vizeScopeLoader from "./loader/scope-loader.mjs";
5
+ import { Compiler, RuleSetRule } from "@rspack/core";
6
+
7
+ //#region src/plugin/index.d.ts
8
+ declare class VizePlugin {
9
+ static readonly name = "VizePlugin";
10
+ private options;
11
+ constructor(options?: VizeRspackPluginOptions);
12
+ apply(compiler: Compiler): void;
13
+ private shouldHandleFile;
14
+ }
15
+ //#endregion
16
+ //#region src/plugin/ruleCloning.d.ts
17
+ interface RuleCloningResult {
18
+ /** Whether rule cloning was performed */
19
+ applied: boolean;
20
+ /** Number of CSS rules cloned */
21
+ clonedCount: number;
22
+ /** Warnings to emit through the infrastructure logger */
23
+ warnings: string[];
24
+ }
25
+ /**
26
+ * Mutates `rules` in-place: wraps .vue rule into `oneOf`, clones CSS rules for style sub-requests.
27
+ */
28
+ declare function applyRuleCloning(rules: (RuleSetRule | "...")[], nativeCss: boolean): RuleCloningResult;
29
+ //#endregion
30
+ //#region src/shared/utils.d.ts
31
+ /** Generate scope ID (8-char SHA256 prefix). Uses relative path for cross-env consistency. */
32
+ declare function generateScopeId(filename: string, rootContext?: string, isProduction?: boolean, source?: string): string;
33
+ /** Extract style block metadata from SFC source. */
34
+ declare function extractStyleBlocks(source: string): StyleBlockInfo[];
35
+ /** Fallback scoped CSS transformer using regex. Does not support @media nesting, :deep()/:global()/:slotted(). */
36
+ declare function addScopeToCssFallback(css: string, scopeId: string): string;
37
+ /** Extract custom block metadata from SFC source (non-script/template/style tags). */
38
+ declare function extractCustomBlocks(source: string): CustomBlockInfo[];
39
+ /** Extract <script src> and <template src> references from SFC source. */
40
+ declare function extractSrcInfo(source: string): SfcSrcInfo;
41
+ /** Replace <script src> or <template src> with inline content from external files. */
42
+ declare function inlineSrcBlocks(source: string, scriptContent: string | null, templateContent: string | null): string;
43
+ /** Match a file path against include/exclude patterns. Normalizes backslashes. */
44
+ declare function matchesPattern(file: string, pattern: string | RegExp | (string | RegExp)[] | undefined, defaultValue: boolean): boolean;
45
+ //#endregion
46
+ //#region src/shared/hotReload.d.ts
47
+ /** HMR code generation for Vue SFCs using `module.hot` (Rspack/webpack CJS API). */
48
+ /** Generate `module.hot` HMR boilerplate for a Vue SFC. */
49
+ declare function genHotReloadCode(id: string): string;
50
+ //#endregion
51
+ //#region src/shared/compiler.d.ts
52
+ /** Clear the compilation cache. Exposed for testing. */
53
+ declare function clearCompilationCache(): void;
54
+ /** Compile a .vue file with content-hash caching. */
55
+ declare function compileFile(filePath: string, source: string, options?: {
56
+ sourceMap?: boolean;
57
+ ssr?: boolean;
58
+ vapor?: boolean;
59
+ compilerOptions?: SfcCompileOptionsNapi;
60
+ isCustomElement?: boolean;
61
+ rootContext?: string;
62
+ isProduction?: boolean; /** @see VizeLoaderOptions.transformAssetUrls */
63
+ transformAssetUrls?: boolean | Record<string, string[]>;
64
+ }): CompiledModule;
65
+ /** Generate JS output with style/custom-block imports and optional HMR code. */
66
+ declare function generateOutput(compiled: CompiledModule, options: {
67
+ requestPath: string; /** Inject HMR boilerplate using `module.hot` (Rspack/webpack CJS API) */
68
+ hmr?: boolean; /** Original file path (for __file exposure in dev mode) */
69
+ filePath?: string; /** Whether this is a production build */
70
+ isProduction?: boolean; /** Project root context (for computing relative __file path) */
71
+ rootContext?: string;
72
+ }): string;
73
+ //#endregion
74
+ export { type CompiledModule, type CustomBlockInfo, type LoaderEntry, 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 };
package/dist/index.mjs ADDED
@@ -0,0 +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-B5WyWrfH.mjs";import{a as s,i as c,n as l,r as u,t as d}from"./loader-CTDGCafa.mjs";import f from"./loader/style-loader.mjs";import p from"./loader/scope-loader.mjs";const m=`@vizejs/rspack-plugin/style-loader`,h=`@vizejs/rspack-plugin/scope-loader`,g={"\\.css$":`css`,"\\.scss$":`scss`,"\\.sass$":`sass`,"\\.less$":`less`,"\\.styl(us)?$":`styl`};function _(e,t){let n=[],r=e.findIndex(e=>e!==`...`&&v(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=x(n);i&&a.push({index:t,rule:n,lang:i})}let o=[];for(let e of a){let n=S(e.rule,e.lang,t);n&&o.push(n)}o.some(e=>e.resourceQuery instanceof RegExp&&e.resourceQuery.test(`vue&type=style&index=0&lang=css`))||o.push(C(t));let s={use:E(i)},c=[...o,s];e[r]={test:i.test,oneOf:c};for(let e of a)w(e.rule);return{applied:!0,clonedCount:o.length,warnings:n}}function v(e){return b(e.test)?E(e).some(e=>{let t=typeof e==`string`?e:e.loader;return t?y(t):!1}):!1}function y(e){return e===`@vizejs/rspack-plugin/loader`||e.includes(`rspack-vize-plugin`)&&e.includes(`loader`)&&!e.includes(`style-loader`)&&!e.includes(`scope-loader`)}function b(e){return e?e instanceof RegExp?e.test(`App.vue`)||e.test(`foo.vue`):typeof e==`string`?e.includes(`.vue`):!1:!1}function x(e){let t=e.test;if(!t||!(t instanceof RegExp))return null;let n=t.source;for(let[e,t]of Object.entries(g))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 S(e,t,n){let r=E(e);if(r.length===0)return null;let i={resourceQuery:RegExp(`(?=.*type=style)(?=.*lang=${t})`),use:[{loader:h},...D(r),{loader:m}]};return e.type?i.type=e.type:n&&(i.type=`css/auto`),i}function C(e){let t=/(?=.*type=style)(?=.*lang=css)/;return e?{resourceQuery:t,type:`css/auto`,use:[{loader:h},{loader:m}]}:{resourceQuery:t,type:`javascript/auto`,use:[{loader:h},{loader:m}]}}function w(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 T(e){return e?Array.isArray(e)?e:[e]:[]}function E(e){let t=T(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 D(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 O=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=!!t.options.experiments?.css;if(this.options.css?.native&&!i&&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=_(e,i);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)}}let{DefinePlugin:a}=t.webpack,o=new Set;for(let e of t.options.plugins??[]){let t=e?.definitions;if(t)for(let e of Object.keys(t))o.add(e)}let s={};o.has(`__VUE_OPTIONS_API__`)||(s.__VUE_OPTIONS_API__=JSON.stringify(!0)),o.has(`__VUE_PROD_DEVTOOLS__`)||(s.__VUE_PROD_DEVTOOLS__=JSON.stringify(!r)),o.has(`__VUE_PROD_HYDRATION_MISMATCH_DETAILS__`)||(s.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__=JSON.stringify(!r)),Object.keys(s).length>0&&new a(s).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{O as VizePlugin,o as addScopeToCssFallback,_ as applyRuleCloning,l as clearCompilationCache,u as compileFile,i as extractCustomBlocks,n as extractSrcInfo,e as extractStyleBlocks,s as genHotReloadCode,c as generateOutput,r as generateScopeId,a as inlineSrcBlocks,t as matchesPattern,d as vizeLoader,p as vizeScopeLoader,f as vizeStyleLoader};
@@ -1,7 +1,7 @@
1
- import { VizeLoaderOptions } from "./index-Crp9t5G9.js";
1
+ import { c as VizeLoaderOptions } from "../index-Bvwqw7T6.mjs";
2
2
  import { LoaderContext } from "@rspack/core";
3
3
 
4
4
  //#region src/loader/index.d.ts
5
-
6
- declare function vizeLoader(this: LoaderContext<VizeLoaderOptions>, source: string): void; //#endregion
7
- export { vizeLoader as vizeLoader$1 };
5
+ declare function vizeLoader(this: LoaderContext<VizeLoaderOptions>, source: string): void;
6
+ //#endregion
7
+ export { vizeLoader as default };
@@ -0,0 +1 @@
1
+ import"../utils-B5WyWrfH.mjs";import{t as e}from"../loader-CTDGCafa.mjs";export{e as default};
@@ -0,0 +1,7 @@
1
+ import { LoaderContext } from "@rspack/core";
2
+
3
+ //#region src/loader/scope-loader.d.ts
4
+ interface VizeScopeLoaderOptions {}
5
+ declare function vizeScopeLoader(this: LoaderContext<VizeScopeLoaderOptions>, source: string): void;
6
+ //#endregion
7
+ export { VizeScopeLoaderOptions, vizeScopeLoader as default };
@@ -0,0 +1 @@
1
+ import{l as e}from"../utils-B5WyWrfH.mjs";import*as t from"@vizejs/native";const{compileCss:n}=t;function r(t){let r=this.async(),{resourceQuery:i,resourcePath:a}=this;if(!i){r(null,t);return}let o=new URLSearchParams(i.slice(1)).get(`scoped`);if(!o){r(null,t);return}let s=`data-v-${o}`,c=n(e(t),{filename:a,scoped:!0,scopeId:s});for(let e of c.errors)this.emitError(Error(`[vize] ${e}`));for(let e of c.warnings)this.emitWarning(Error(`[vize] ${e}`));r(null,c.code)}export{r as default};
@@ -0,0 +1,7 @@
1
+ import { u as VizeStyleLoaderOptions } from "../index-Bvwqw7T6.mjs";
2
+ import { LoaderContext } from "@rspack/core";
3
+
4
+ //#region src/loader/style-loader.d.ts
5
+ declare function vizeStyleLoader(this: LoaderContext<VizeStyleLoaderOptions>, source: string): void;
6
+ //#endregion
7
+ export { vizeStyleLoader as default };
@@ -0,0 +1 @@
1
+ import{a as e}from"../utils-B5WyWrfH.mjs";import t from"node:path";import n from"node:fs/promises";function r(r){let i=this.async(),{resourceQuery:a,resourcePath:o}=this;if(!a){i(null,r);return}let s=new URLSearchParams(a.slice(1));if(s.get(`type`)!==`style`){i(null,r);return}let c=parseInt(s.get(`index`)||`0`,10);this.addDependency(o);let l=e(r)[c];if(!l){this.emitError(Error(`[vize] Style block at index ${c} not found in ${o}`)),i(null,``);return}if(l.src){let e=t.resolve(t.dirname(o),l.src);this.addDependency(e),n.readFile(e,`utf-8`).then(e=>{i(null,e)}).catch(()=>{this.emitWarning(Error(`[vize] <style src> target not found: ${l.src} (resolved: ${e}) in ${o}`)),i(null,``)});return}i(null,l.content)}export{r as default};
@@ -0,0 +1,24 @@
1
+ import{a as e,c as t,i as n,n as r,o as i,r as a,s as o}from"./utils-B5WyWrfH.mjs";import{createHash as s}from"node:crypto";import c from"node:path";import l from"node:fs";import*as u from"@vizejs/native";function d(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 f(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{compileSfc:p}=u,m=new Map;function h(e){return s(`sha256`).update(e).digest(`hex`).slice(0,16)}function g(){m.clear()}function _(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??``,g=o.isProduction??!1,_=o.transformAssetUrls??!0,v=`${t}:ssr=${c}:vapor=${l}:ts=${s}:map=${u}:ce=${d}:root=${f}:prod=${g}:${_===!1?`tau=false`:_===!0?`tau=true`:`tau=${JSON.stringify(_)}`}`,y=h(n),b=m.get(v);if(b&&b.contentHash===y)return b.result;let x=i(t,o.rootContext,o.isProduction,n),S=/<style[^>]*\bscoped\b/.test(n),C=p(n,{...o.compilerOptions,filename:t,sourceMap:o.sourceMap??o.compilerOptions?.sourceMap??!0,ssr:c,vapor:l,isTs:s,scopeId:S?`data-v-${x}`:void 0}),w=e(n),T=a(n),E=r(n,_),D={code:C.code,css:C.css,errors:C.errors,warnings:C.warnings,scopeId:x,hasScoped:S,styles:w,customBlocks:T,isCustomElement:d,templateAssetUrls:E};return D.errors.length===0&&m.set(v,{contentHash:y,result:D}),D}function v(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`]:[]].join(`&`),a=`${t.requestPath}?${i}`;if(r)return`import _style_${n.index} from ${JSON.stringify(a)};`;if(n.module){let e=typeof n.module==`string`?n.module:`$style`,t=`_cssModule_${n.index}`;return o.push({request:a,varName:t,bindingName:e}),`import ${t} 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=>f(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?c.relative(t.rootContext,t.filePath).replace(/\\/g,`/`):c.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,`${d(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=r.join(`&`),a=t.requestPath;return`import block${n} from ${JSON.stringify(`${a}?${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 y=/\.ce\.vue$/;function b(e){let t=this.async(),r=this.getOptions(),i=this.resourcePath,s=this.resourceQuery,u=C(this,i),d=this.mode===`production`||process.env.NODE_ENV===`production`,f=!(r.ssr??!1)&&!d&&r.hotReload!==!1;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=c.resolve(c.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(!x(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=S(i,r.customElement),s=n(e),p=e;if(s.scriptSrc){let e=c.resolve(c.dirname(i),s.scriptSrc);this.addDependency(e);try{let t=l.readFileSync(e,`utf-8`);p=o(p,t,null)}catch{t(Error(`[vize] <script src="${s.scriptSrc}"> not found (resolved: ${e}) in ${i}`));return}}if(s.templateSrc){let e=c.resolve(c.dirname(i),s.templateSrc);this.addDependency(e);try{let t=l.readFileSync(e,`utf-8`);p=o(p,null,t)}catch{t(Error(`[vize] <template src="${s.templateSrc}"> not found (resolved: ${e}) in ${i}`));return}}let m=_(i,p,{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 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`);t(Error(`[vize] Compilation failed for ${i}:\n${e}`));return}t(null,v(m,{requestPath:u,hmr:f,filePath:i,isProduction:d,rootContext:this.rootContext}))}catch(e){t(e)}}function x(e,n){return!(!t(e,n.include,!0)||t(e,n.exclude,!1))}function S(e,t){return t===!0?!0:t===!1||t===void 0?y.test(e):t.test(e)}function C(e,t){return`./${c.basename(t)}`}export{d as a,v as i,g as n,_ as r,b as t};
@@ -0,0 +1,4 @@
1
+ import{createHash as e}from"node:crypto";import t from"node:path";function n(n,r,i,a){let o;if(r){let e=t.relative(r,n).replace(/^(\.\.[/\\])+/,``).replace(/\\/g,`/`);o=i&&a?e+`
2
+ `+a.replace(/\r\n/g,`
3
+ `):e}else o=n;return e(`sha256`).update(o).digest(`hex`).slice(0,8)}function r(e){let t=[],n=/<style([^>]*)>([\s\S]*?)<\/style>/gi,r,i=0;for(;(r=n.exec(e))!==null;){let e=r[1],n=r[2],a=e.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,o=e.match(/\blang=["']([^"']+)["']/)?.[1]??null,s=/\bscoped\b/.test(e),c=e.match(/\bmodule(?:=["']([^"']+)["'])?\b/),l=c?c[1]||!0:!1;t.push({content:n,src:a,lang:o,scoped:s,module:l,index:i}),i++}return t}function i(e,t){let n=`[data-v-${t}]`,r=``,i=0,a=0,s=0;for(;a<e.length;){let t=e[a];if(t===`{`){if(i===0){let t=e.slice(s,a);r+=o(t,n),r+=`{`}else r+=t;i++,a++,s=a}else t===`}`?(i--,r+=t,a++,s=a):(i>0&&(r+=t),a++)}return s<e.length&&i===0&&(r+=e.slice(s)),r}function a(e){if(!e.includes(`/*`))return e;let t=e.length,n=[],r=0,i=0;for(;i<t;){let a=e.charCodeAt(i);if(a===34||a===39){let n=a;for(i++;i<t;){let t=e.charCodeAt(i);if(t===92){i+=2;continue}if(i++,t===n)break}continue}if(a===47&&i+1<t&&e.charCodeAt(i+1)===42){i>r&&n.push(e.slice(r,i)),i+=2;let a=` `;for(;i<t;){if(e.charCodeAt(i)===42&&i+1<t&&e.charCodeAt(i+1)===47){a+=` `,i+=2;break}a+=e.charCodeAt(i)===10?`
4
+ `:` `,i++}n.push(a),r=i;continue}i++}return r===0?e:(r<t&&n.push(e.slice(r)),n.join(``))}function o(e,t){return e.trim().startsWith(`@`)?e:e.split(`,`).map(e=>{let n=e.trim();return!n||n.startsWith(`@`)?e:`${e.match(/^(\s*)/)?.[1]??``}${n}${t}`}).join(`,`)}function s(e){let t=[],n=new Set([`script`,`template`,`style`]),r=0,i=0;for(;i<e.length;){let a=e.indexOf(`<`,i);if(a===-1)break;if(e.startsWith(`<!--`,a)){let t=e.indexOf(`-->`,a+4);i=t===-1?e.length:t+3;continue}if(e[a+1]===`/`){let t=e.indexOf(`>`,a+2);i=t===-1?e.length:t+1;continue}let o=/^<([a-zA-Z][a-zA-Z0-9-]*)(\s[^>]*)?\s*\/?>/.exec(e.slice(a));if(!o){i=a+1;continue}let s=o[1],l=(o[2]||``).trim(),u=o[0].trimEnd().endsWith(`/>`),d=a+o[0].length;if(u){n.has(s.toLowerCase())||t.push({type:s,content:``,src:l.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,attrs:c(l),index:r++}),i=d;continue}let f=s.toLowerCase(),p=1,m=d;for(;m<e.length&&p>0;){let i=e.indexOf(`<`,m);if(i===-1){m=e.length;break}let a=RegExp(`^</${s}\\s*>`,`i`).exec(e.slice(i));if(a){if(p--,p===0){let o=e.slice(d,i);n.has(f)||t.push({type:s,content:o,src:l.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,attrs:c(l),index:r++}),m=i+a[0].length;break}m=i+a[0].length;continue}let o=RegExp(`^<${s}\\b[^>]*>`,`i`).exec(e.slice(i));if(o&&!o[0].trimEnd().endsWith(`/>`)){p++,m=i+o[0].length;continue}m=i+1}i=m}return t}function c(e){let t={},n=/\b([a-z][a-z0-9-]*)(?:=["']([^"']*)["'])?/gi,r;for(;(r=n.exec(e))!==null;)t[r[1]]=r[2]??!0;return t}function l(e){let t=e.match(/<script([^>]*)>/i),n=e.match(/<template([^>]*)>/i);return{scriptSrc:t?.[1]?.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,templateSrc:n?.[1]?.match(/\bsrc=["']([^"']+)["']/)?.[1]??null}}function u(e,t,n){let r=e;return t!==null&&(r=r.replace(/(<script)([^>]*)\bsrc=["'][^"']+["']([^>]*>)[\s\S]*?(<\/script>)/i,(e,n,r,i,a)=>`${n}${(r+i).replace(/\bsrc=["'][^"']+["']\s*/g,``)}\n${t}\n${a}`)),n!==null&&(r=r.replace(/(<template)([^>]*)\bsrc=["'][^"']+["']([^>]*>)[\s\S]*?(<\/template>)/i,(e,t,r,i,a)=>`${t}${(r+i).replace(/\bsrc=["'][^"']+["']\s*/g,``)}\n${n}\n${a}`)),r}function d(e,t,n){if(!t)return n;let r=e.replace(/\\/g,`/`);return(Array.isArray(t)?t:[t]).some(t=>typeof t==`string`?r.includes(t)||e.includes(t):t.test(r))}const f=Object.freeze({img:[`src`],video:[`src`,`poster`],source:[`src`],image:[`xlink:href`,`href`],use:[`xlink:href`,`href`]});function p(e){return!e||/^(https?:)?\/\//.test(e)||e.startsWith(`data:`)?!1:!!(e.startsWith(`./`)||e.startsWith(`../`)||e.startsWith(`@/`)||e.startsWith(`~`))}function m(e){let t=0;for(;t<e.length;){let n=e.indexOf(`<`,t);if(n===-1)break;if(e.startsWith(`<!--`,n)){let r=e.indexOf(`-->`,n+4);t=r===-1?e.length:r+3;continue}if(e[n+1]===`/`){let r=e.indexOf(`>`,n+2);t=r===-1?e.length:r+1;continue}let r=/^<template(\s[^>]*)?>/.exec(e.slice(n));if(!r){t=n+1;continue}let i=n+r[0].length,a=1,o=i;for(;o<e.length&&a>0;){let t=e.indexOf(`<`,o);if(t===-1)break;let n=/^<\/template\s*>/i.exec(e.slice(t));if(n){if(a--,a===0)return e.slice(i,t);o=t+n[0].length;continue}let r=/^<template\b[^>]*>/i.exec(e.slice(t));if(r&&!r[0].trimEnd().endsWith(`/>`)){a++,o=t+r[0].length;continue}o=t+1}return null}return null}function h(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function g(e,t){if(t===!1)return[];let n=t==null||t===!0?f:t,r=m(e);if(!r)return[];let i=new Map,a=0;for(let[e,t]of Object.entries(n)){let n=RegExp(`<${h(e)}((?:\\s+[^>]*)?)(?:/>|>)`,`gi`),o;for(;(o=n.exec(r))!==null;){let e=o[1]??``;for(let n of t){let t=RegExp(`(?:^|\\s)${h(n)}="([^"]+)"`,`i`),r=RegExp(`(?:^|\\s)${h(n)}='([^']+)'`,`i`),o=t.exec(e)??r.exec(e);if(o){let e=o[1];p(e)&&!i.has(e)&&i.set(e,`_imports_${a++}`)}}}}return Array.from(i.entries()).map(([e,t])=>({url:e,varName:t}))}export{r as a,d as c,l as i,a as l,g as n,n as o,s as r,u as s,i as t};
package/package.json CHANGED
@@ -1,69 +1,73 @@
1
1
  {
2
2
  "name": "@vizejs/rspack-plugin",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "High-performance Rspack plugin for Vue SFC compilation powered by Vize",
5
- "publishConfig": {
6
- "access": "public"
5
+ "keywords": [
6
+ "compiler",
7
+ "fast",
8
+ "loader",
9
+ "native",
10
+ "plugin",
11
+ "rspack",
12
+ "sfc",
13
+ "vue"
14
+ ],
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/ubugeeei/vize",
19
+ "directory": "npm/rspack-vize-plugin"
7
20
  },
21
+ "files": [
22
+ "dist"
23
+ ],
8
24
  "type": "module",
9
- "main": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
25
+ "main": "./dist/index.mjs",
26
+ "types": "./dist/index.d.mts",
11
27
  "exports": {
12
28
  ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "default": "./dist/index.js"
29
+ "types": "./dist/index.d.mts",
30
+ "import": "./dist/index.mjs",
31
+ "default": "./dist/index.mjs"
16
32
  },
17
33
  "./loader": {
18
- "types": "./dist/loader/index.d.ts",
19
- "import": "./dist/loader/index.js",
20
- "default": "./dist/loader/index.js"
34
+ "types": "./dist/loader/index.d.mts",
35
+ "import": "./dist/loader/index.mjs",
36
+ "default": "./dist/loader/index.mjs"
21
37
  },
22
38
  "./style-loader": {
23
- "types": "./dist/loader/style-loader.d.ts",
24
- "import": "./dist/loader/style-loader.js",
25
- "default": "./dist/loader/style-loader.js"
39
+ "types": "./dist/loader/style-loader.d.mts",
40
+ "import": "./dist/loader/style-loader.mjs",
41
+ "default": "./dist/loader/style-loader.mjs"
42
+ },
43
+ "./scope-loader": {
44
+ "types": "./dist/loader/scope-loader.d.mts",
45
+ "import": "./dist/loader/scope-loader.mjs",
46
+ "default": "./dist/loader/scope-loader.mjs"
26
47
  }
27
48
  },
28
- "files": [
29
- "dist"
30
- ],
31
- "keywords": [
32
- "rspack",
33
- "vue",
34
- "plugin",
35
- "loader",
36
- "sfc",
37
- "compiler",
38
- "native",
39
- "fast"
40
- ],
41
- "repository": {
42
- "type": "git",
43
- "url": "https://github.com/ubugeeei/vize",
44
- "directory": "npm/rspack-vize-plugin"
49
+ "publishConfig": {
50
+ "access": "public"
45
51
  },
46
- "license": "MIT",
47
52
  "dependencies": {
48
- "@vizejs/native": "0.33.0"
49
- },
50
- "peerDependencies": {
51
- "@rspack/core": ">=1.0.0"
53
+ "@vizejs/native": "0.34.0"
52
54
  },
53
55
  "devDependencies": {
54
56
  "@rspack/core": "^1.7.7",
55
57
  "@types/node": "^22.0.0",
56
- "tsdown": "^0.9.0",
57
58
  "tsx": "^4.21.0",
58
- "typescript": "~5.6.0"
59
+ "typescript": "~5.6.0",
60
+ "vite-plus": "latest"
61
+ },
62
+ "peerDependencies": {
63
+ "@rspack/core": ">=1.0.0"
59
64
  },
60
65
  "scripts": {
61
- "build": "tsdown",
62
- "dev": "tsdown --watch",
63
- "lint": "oxlint --deny-warnings --type-aware --tsconfig tsconfig.json",
64
- "lint:fix": "oxlint --type-aware --tsconfig tsconfig.json --fix",
65
- "fmt": "oxfmt --write src tsdown.config.ts",
66
- "fmt:check": "oxfmt src tsdown.config.ts",
66
+ "build": "vp pack",
67
+ "dev": "vp pack --watch",
68
+ "check": "vp check src vite.config.ts",
69
+ "check:fix": "vp check --fix src vite.config.ts",
70
+ "fmt": "vp fmt --write src vite.config.ts",
67
71
  "test": "pnpm build && node --import tsx --test src/*.test.ts src/**/*.test.ts",
68
72
  "test:update": "pnpm build && node --import tsx --test --test-update-snapshots src/*.test.ts src/**/*.test.ts"
69
73
  }
@@ -1,249 +0,0 @@
1
- //#region src/types/index.d.ts
2
- /**
3
- * Type definitions for @vizejs/rspack-plugin
4
- * Copied and adapted from vite-plugin-vize
5
- */
6
- interface SfcCompileOptionsNapi {
7
- filename?: string;
8
- sourceMap?: boolean;
9
- ssr?: boolean;
10
- /** Preserve TypeScript in output when true */
11
- isTs?: boolean;
12
- /** Scope ID for scoped CSS (e.g., "data-v-abc123") */
13
- scopeId?: string;
14
- }
15
- interface SfcCompileResultNapi {
16
- code: string;
17
- css?: string;
18
- /** Source map JSON string (when implemented in @vizejs/native) */
19
- map?: string;
20
- errors: string[];
21
- warnings: string[];
22
- }
23
- interface StyleBlockInfo {
24
- /** Raw style content (uncompiled for preprocessor langs) */
25
- content: string;
26
- /** External style source path from `<style src="...">` */
27
- src?: string | null;
28
- /** Language of the style block (e.g., "css", "scss", "less", "sass", "stylus") */
29
- lang: string | null;
30
- /** Whether the style block has the scoped attribute */
31
- scoped: boolean;
32
- /** CSS Modules: true for unnamed `module`, or the binding name for `module="name"` */
33
- module: boolean | string;
34
- /** Index of this style block in the SFC */
35
- index: number;
36
- }
37
- interface CustomBlockInfo {
38
- /** Tag name of the custom block (e.g., "i18n", "docs") */
39
- type: string;
40
- /** Raw content of the custom block */
41
- content: string;
42
- /** External source path from `<block src="...">` */
43
- src?: string | null;
44
- /** All attributes on the custom block tag */
45
- attrs: Record<string, string | true>;
46
- /** Index of this custom block in the SFC */
47
- index: number;
48
- }
49
- interface SfcSrcInfo {
50
- /** Whether <script> has a src attribute */
51
- scriptSrc?: string | null;
52
- /** Whether <template> has a src attribute */
53
- templateSrc?: string | null;
54
- }
55
- interface CompiledModule {
56
- code: string;
57
- css?: string;
58
- errors: string[];
59
- warnings: string[];
60
- scopeId: string;
61
- hasScoped: boolean;
62
- /** Per-block style metadata extracted from the source SFC */
63
- styles: StyleBlockInfo[];
64
- /** Custom blocks extracted from the source SFC */
65
- customBlocks: CustomBlockInfo[];
66
- /** Whether this is a custom element SFC (e.g., .ce.vue) */
67
- isCustomElement: boolean;
68
- }
69
- interface VizeLoaderOptions {
70
- /**
71
- * Enable source map generation
72
- * @default true
73
- */
74
- sourceMap?: boolean;
75
- /**
76
- * Enable SSR mode
77
- * @default false
78
- */
79
- ssr?: boolean;
80
- /**
81
- * Project root directory
82
- */
83
- root?: string;
84
- /**
85
- * Files to include in compilation (safe filter)
86
- */
87
- include?: string | RegExp | (string | RegExp)[];
88
- /**
89
- * Files to exclude from compilation (safe filter)
90
- */
91
- exclude?: string | RegExp | (string | RegExp)[];
92
- /**
93
- * Additional low-level compiler options passed to @vizejs/native compileSfc
94
- */
95
- compilerOptions?: SfcCompileOptionsNapi;
96
- /**
97
- * Transform Vue SFCs into custom elements.
98
- * - `true`: all `*.vue` imports are converted into custom elements
99
- * - `RegExp`: matched files are converted into custom elements
100
- *
101
- * @default /\.ce\.vue$/
102
- */
103
- customElement?: boolean | RegExp;
104
- /**
105
- * Enable HMR (Hot Module Replacement) for Vue SFCs.
106
- * Set to `false` to explicitly disable HMR even in development mode.
107
- *
108
- * @default true (enabled in development, disabled in production/SSR)
109
- */
110
- hotReload?: boolean;
111
- }
112
- interface VizeStyleLoaderOptions {
113
- /**
114
- * Whether to use native CSS mode (experiments.css)
115
- * In both modes, the loader outputs pure CSS
116
- * @default false
117
- */
118
- native?: boolean;
119
- }
120
- type VizeStyleLanguage = "css" | "scss" | "sass" | "less" | "styl" | "stylus";
121
- interface CreateVizeVueRulesOptions {
122
- /**
123
- * Production mode flag
124
- * @default false
125
- */
126
- isProduction?: boolean;
127
- /**
128
- * Use Rspack native CSS pipeline (`experiments.css`)
129
- * @default true
130
- */
131
- nativeCss?: boolean;
132
- /**
133
- * Extra languages to handle automatically in addition to `css`
134
- * @default ["scss", "sass", "less", "stylus", "styl"]
135
- */
136
- styleLanguages?: VizeStyleLanguage[];
137
- /**
138
- * Loader entry for the main `.vue` compiler loader
139
- * @default "@vizejs/rspack-plugin/loader"
140
- */
141
- vizeLoader?: string;
142
- /**
143
- * Loader entry for the `.vue` style extractor loader
144
- * @default "@vizejs/rspack-plugin/style-loader"
145
- */
146
- vizeStyleLoader?: string;
147
- /**
148
- * Dev style injector / prod extractor loader entry used in non-native CSS mode
149
- * @default "style-loader"
150
- */
151
- styleInjectLoader?: LoaderEntry;
152
- /**
153
- * Production CSS extractor loader entry used in non-native CSS mode
154
- * (e.g. `rspack.CssExtractRspackPlugin.loader`)
155
- */
156
- styleExtractLoader?: LoaderEntry;
157
- /**
158
- * css-loader entry used in non-native CSS mode
159
- * @default "css-loader"
160
- */
161
- cssLoader?: LoaderEntry;
162
- /**
163
- * Main vize loader options
164
- */
165
- loaderOptions?: VizeLoaderOptions;
166
- /**
167
- * Vize style loader options
168
- */
169
- styleLoaderOptions?: VizeStyleLoaderOptions;
170
- /**
171
- * Add a post-processing rule to strip TypeScript type annotations from
172
- * the compiled `.vue` output.
173
- *
174
- * This is needed because `@vizejs/native compileSfc` preserves TypeScript
175
- * syntax in its output (same as `@vue/compiler-sfc`), and a downstream
176
- * transpiler must strip the types before the browser/runtime can execute it.
177
- *
178
- * - `true`: use Rspack built-in SWC loader (`builtin:swc-loader`)
179
- * - `LoaderEntry`: use a custom loader (e.g. `esbuild-loader`)
180
- * - `false` / omitted: no post-processing (user handles it separately)
181
- *
182
- * @default false
183
- */
184
- typescript?: boolean | LoaderEntry;
185
- }
186
- interface VizeRspackPluginOptions {
187
- /**
188
- * Files to include in compilation
189
- * @default /\.vue$/
190
- */
191
- include?: string | RegExp | (string | RegExp)[];
192
- /**
193
- * Files to exclude from compilation
194
- * @default /node_modules/
195
- */
196
- exclude?: string | RegExp | (string | RegExp)[];
197
- /**
198
- * Force production mode
199
- * @default auto-detected from Rspack config
200
- */
201
- isProduction?: boolean;
202
- /**
203
- * Enable SSR mode
204
- * @default false
205
- */
206
- ssr?: boolean;
207
- /**
208
- * Enable source map generation
209
- * @default true in development, false in production
210
- */
211
- sourceMap?: boolean;
212
- /**
213
- * Enable Vapor mode compilation
214
- * @default false
215
- */
216
- vapor?: boolean;
217
- /**
218
- * Root directory to scan for .vue files
219
- * @default Rspack's root
220
- */
221
- root?: string;
222
- /**
223
- * CSS configuration
224
- */
225
- css?: {
226
- /**
227
- * Use Rspack native CSS processing (experiments.css)
228
- * When enabled, no need for css-loader/style-loader/CssExtractRspackPlugin
229
- * Handled by Rust-side LightningCSS, better performance
230
- * @default false
231
- */
232
- native?: boolean;
233
- };
234
- /**
235
- * Custom compiler options
236
- */
237
- compilerOptions?: SfcCompileOptionsNapi;
238
- /**
239
- * Enable debug logging
240
- * @default false
241
- */
242
- debug?: boolean;
243
- }
244
- /** Loader entry: either a string (loader name/path) or an object with loader + options */
245
- type LoaderEntry = string | {
246
- loader: string;
247
- options?: Record<string, unknown>;
248
- }; //#endregion
249
- export { CompiledModule, CreateVizeVueRulesOptions, CustomBlockInfo, LoaderEntry, SfcCompileOptionsNapi, SfcCompileResultNapi, SfcSrcInfo, StyleBlockInfo, VizeLoaderOptions, VizeRspackPluginOptions, VizeStyleLanguage, VizeStyleLoaderOptions };