@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.
- package/README.md +229 -149
- package/dist/index-Bvwqw7T6.d.mts +138 -0
- package/dist/index.d.mts +74 -0
- package/dist/index.mjs +1 -0
- package/dist/{index-C1nbpj8i.d.ts → loader/index.d.mts} +4 -4
- package/dist/loader/index.mjs +1 -0
- package/dist/loader/scope-loader.d.mts +7 -0
- package/dist/loader/scope-loader.mjs +1 -0
- package/dist/loader/style-loader.d.mts +7 -0
- package/dist/loader/style-loader.mjs +1 -0
- package/dist/loader-CTDGCafa.mjs +24 -0
- package/dist/utils-B5WyWrfH.mjs +4 -0
- package/package.json +48 -44
- package/dist/index-Crp9t5G9.d.ts +0 -249
- package/dist/index.d.ts +0 -159
- package/dist/index.js +0 -1
- package/dist/loader/index.d.ts +0 -3
- package/dist/loader/index.js +0 -1
- package/dist/loader/style-loader.d.ts +0 -3
- package/dist/loader/style-loader.js +0 -1
- package/dist/loader-DyzGJOBD.js +0 -22
- package/dist/style-loader-DPvk-BhE.js +0 -1
- package/dist/style-loader-zO0F0c6t.d.ts +0 -7
- package/dist/utils-Cw44tFia.js +0 -3
package/dist/index.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { CompiledModule, CreateVizeVueRulesOptions, CustomBlockInfo, LoaderEntry, SfcCompileOptionsNapi, SfcCompileResultNapi, SfcSrcInfo, StyleBlockInfo, VizeLoaderOptions, VizeRspackPluginOptions, VizeStyleLanguage, VizeStyleLoaderOptions } from "./index-Crp9t5G9.js";
|
|
2
|
-
import { vizeLoader$1 as vizeLoader } from "./index-C1nbpj8i.js";
|
|
3
|
-
import { vizeStyleLoader$1 as vizeStyleLoader } from "./style-loader-zO0F0c6t.js";
|
|
4
|
-
import { Compiler } from "@rspack/core";
|
|
5
|
-
|
|
6
|
-
//#region src/plugin/index.d.ts
|
|
7
|
-
|
|
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
|
-
} //#endregion
|
|
15
|
-
//#region src/shared/utils.d.ts
|
|
16
|
-
/**
|
|
17
|
-
* Generate a unique scope ID for scoped CSS based on file path.
|
|
18
|
-
* Uses SHA256 hash and takes the first 8 characters.
|
|
19
|
-
*
|
|
20
|
-
* Uses relative path (when rootContext is provided) for cross-environment
|
|
21
|
-
* consistency (e.g. SSR hydration). In production, mixes source content
|
|
22
|
-
* into the hash to avoid collisions across packages with identically-named files.
|
|
23
|
-
*/
|
|
24
|
-
declare function generateScopeId(filename: string, rootContext?: string, isProduction?: boolean, source?: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Extract style block metadata from a Vue SFC source string.
|
|
27
|
-
* Parses `<style>` tags to determine lang, scoped, and module attributes.
|
|
28
|
-
*
|
|
29
|
-
* Copied from vite-plugin-vize/src/compiler.ts
|
|
30
|
-
*/
|
|
31
|
-
declare function extractStyleBlocks(source: string): StyleBlockInfo[];
|
|
32
|
-
/**
|
|
33
|
-
* Fallback scoped CSS transformer using simple regex.
|
|
34
|
-
*
|
|
35
|
-
* ⚠️ Known limitations:
|
|
36
|
-
* - Does not support @media / @supports nested selectors
|
|
37
|
-
* - Does not support Vue's :deep() / :global() / :slotted() pseudo-classes
|
|
38
|
-
* - Does not handle CSS comments containing { or ,
|
|
39
|
-
* - Does not support :root and other pseudo-class selectors
|
|
40
|
-
*
|
|
41
|
-
* Recommendation: This regex implementation is for MVP stage only;
|
|
42
|
-
* production-grade scoped semantics should use native-side precise API.
|
|
43
|
-
*
|
|
44
|
-
* Copied from rspack-plugin-design.md
|
|
45
|
-
*/
|
|
46
|
-
declare function addScopeToCssFallback(css: string, scopeId: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Extract custom block metadata from a Vue SFC source string.
|
|
49
|
-
* Parses root-level tags that are not <script>, <template>, or <style>.
|
|
50
|
-
*/
|
|
51
|
-
declare function extractCustomBlocks(source: string): CustomBlockInfo[];
|
|
52
|
-
/**
|
|
53
|
-
* Extract <script src> and <template src> references from an SFC source.
|
|
54
|
-
* Returns null for each if no src attribute is present.
|
|
55
|
-
*/
|
|
56
|
-
declare function extractSrcInfo(source: string): SfcSrcInfo;
|
|
57
|
-
/**
|
|
58
|
-
* Replace <script src="..."> or <template src="..."> with inline content
|
|
59
|
-
* read from external files. This produces a self-contained SFC string
|
|
60
|
-
* that can be passed to compileSfc.
|
|
61
|
-
*/
|
|
62
|
-
declare function inlineSrcBlocks(source: string, scriptContent: string | null, templateContent: string | null): string;
|
|
63
|
-
/**
|
|
64
|
-
* Create a conditional logger.
|
|
65
|
-
*
|
|
66
|
-
* Copied from vite-plugin-vize/src/transform.ts
|
|
67
|
-
*/
|
|
68
|
-
declare function createLogger(debug: boolean): {
|
|
69
|
-
log: (...args: unknown[]) => false | void;
|
|
70
|
-
info: (...args: unknown[]) => void;
|
|
71
|
-
warn: (...args: unknown[]) => void;
|
|
72
|
-
error: (...args: unknown[]) => void;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Match a file path against include/exclude patterns.
|
|
76
|
-
* Used by both the main loader and the plugin for consistent filtering.
|
|
77
|
-
*
|
|
78
|
-
* Normalizes backslashes to forward slashes before matching,
|
|
79
|
-
* so patterns like /src\/.*\.vue$/ work on Windows.
|
|
80
|
-
*/
|
|
81
|
-
declare function matchesPattern(file: string, pattern: string | RegExp | (string | RegExp)[] | undefined, defaultValue: boolean): boolean;
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/shared/hotReload.d.ts
|
|
85
|
-
/**
|
|
86
|
-
* HMR (Hot Module Replacement) code generation for Vue SFC modules.
|
|
87
|
-
*
|
|
88
|
-
* Uses `module.hot` (Rspack/webpack CommonJS HMR API), NOT `import.meta.hot`.
|
|
89
|
-
* Reference: rspack-vue-loader's hotReload.ts
|
|
90
|
-
*
|
|
91
|
-
* __VUE_HMR_RUNTIME__ is injected into global scope by @vue/runtime-core.
|
|
92
|
-
*/
|
|
93
|
-
/**
|
|
94
|
-
* Generate HMR boilerplate code for a compiled Vue SFC module.
|
|
95
|
-
*
|
|
96
|
-
* The generated code:
|
|
97
|
-
* 1. Assigns `__hmrId` to the component for Vue devtools
|
|
98
|
-
* 2. Calls `module.hot.accept()` to make the module self-accepting
|
|
99
|
-
* 3. Registers or reloads the component via `__VUE_HMR_RUNTIME__`
|
|
100
|
-
*
|
|
101
|
-
* @param id - Unique HMR identifier for this component (typically the scopeId hash)
|
|
102
|
-
*/
|
|
103
|
-
declare function genHotReloadCode(id: string): string;
|
|
104
|
-
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/shared/compiler.d.ts
|
|
107
|
-
/**
|
|
108
|
-
* Generate HMR code for a CSS Module import.
|
|
109
|
-
*
|
|
110
|
-
* When the CSS Module file changes, this code:
|
|
111
|
-
* 1. Updates the __cssModules binding with the new values
|
|
112
|
-
* 2. Triggers a Vue component rerender (NOT a full reload)
|
|
113
|
-
*/
|
|
114
|
-
/**
|
|
115
|
-
* Clear the compilation cache. Exposed for testing and manual invalidation.
|
|
116
|
-
*/
|
|
117
|
-
declare function clearCompilationCache(): void;
|
|
118
|
-
/**
|
|
119
|
-
* Compile a single .vue file.
|
|
120
|
-
*
|
|
121
|
-
* Adapted from vite-plugin-vize for Rspack loader scenario:
|
|
122
|
-
* - Uses content-hash based cache to skip re-compilation of unchanged files
|
|
123
|
-
* - Does not read file (source is passed as parameter)
|
|
124
|
-
* - Returns styles metadata for loader chain processing
|
|
125
|
-
*/
|
|
126
|
-
declare function compileFile(filePath: string, source: string, options?: {
|
|
127
|
-
sourceMap?: boolean;
|
|
128
|
-
ssr?: boolean;
|
|
129
|
-
compilerOptions?: SfcCompileOptionsNapi;
|
|
130
|
-
isCustomElement?: boolean;
|
|
131
|
-
rootContext?: string;
|
|
132
|
-
isProduction?: boolean;
|
|
133
|
-
}): CompiledModule;
|
|
134
|
-
/**
|
|
135
|
-
* Generate output code with style imports and custom block imports injected.
|
|
136
|
-
*
|
|
137
|
-
* Key difference from Vite version:
|
|
138
|
-
* - Generates import statements with query parameters for style blocks
|
|
139
|
-
* - Rspack will route these to the appropriate style loader via resourceQuery matching
|
|
140
|
-
* - Injects `module.hot` based HMR code when `hmr` is enabled
|
|
141
|
-
*/
|
|
142
|
-
declare function generateOutput(compiled: CompiledModule, options: {
|
|
143
|
-
requestPath: string;
|
|
144
|
-
/** Inject HMR boilerplate using `module.hot` (Rspack/webpack CJS API) */
|
|
145
|
-
hmr?: boolean;
|
|
146
|
-
/** Original file path (for __file exposure in dev mode) */
|
|
147
|
-
filePath?: string;
|
|
148
|
-
/** Whether this is a production build */
|
|
149
|
-
isProduction?: boolean;
|
|
150
|
-
/** Project root context (for computing relative __file path) */
|
|
151
|
-
rootContext?: string;
|
|
152
|
-
}): string;
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/preset/rules.d.ts
|
|
156
|
-
declare function createVizeVueRules(options?: CreateVizeVueRulesOptions): Record<string, unknown>[];
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
export { CompiledModule, CreateVizeVueRulesOptions, CustomBlockInfo, LoaderEntry, SfcCompileOptionsNapi, SfcCompileResultNapi, SfcSrcInfo, StyleBlockInfo, VizeLoaderOptions, VizePlugin, VizeRspackPluginOptions, VizeStyleLanguage, VizeStyleLoaderOptions, addScopeToCssFallback, clearCompilationCache, compileFile, createLogger, createVizeVueRules, extractCustomBlocks, extractSrcInfo, extractStyleBlocks, genHotReloadCode, generateOutput, generateScopeId, inlineSrcBlocks, matchesPattern, vizeLoader, vizeStyleLoader };
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{addScopeToCssFallback as e,createLogger as t,extractCustomBlocks as n,extractSrcInfo as r,extractStyleBlocks as i,generateScopeId as a,inlineSrcBlocks as o,matchesPattern as s}from"./utils-Cw44tFia.js";import{clearCompilationCache as c,compileFile as l,genHotReloadCode as u,generateOutput as d,vizeLoader as f}from"./loader-DyzGJOBD.js";import{vizeStyleLoader as p}from"./style-loader-DPvk-BhE.js";var m=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&&n.warn("Vapor mode is enabled but SFC-level Vapor compilation is not yet supported by @vizejs/native. Only `__VUE_PROD_HYDRATION_MISMATCH_DETAILS__` will be set. Track https://github.com/nicepkg/vize for updates.");let i=!!t.options.experiments?.css;this.options.css?.native&&!i&&n.warn("`css.native: true` is set but `experiments.css` is not enabled in rspack config.");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!(!s(e,this.options.include,!0)||s(e,this.options.exclude,!1))}};const h=[`scss`,`sass`,`less`,`stylus`,`styl`],g={scss:`sass-loader`,sass:`sass-loader`,less:`less-loader`,styl:`stylus-loader`,stylus:`stylus-loader`};function _(e={}){let{isProduction:t=!1,nativeCss:n=!0,styleLanguages:r=h,vizeLoader:i=`@vizejs/rspack-plugin/loader`,vizeStyleLoader:a=`@vizejs/rspack-plugin/style-loader`,styleInjectLoader:o=`style-loader`,styleExtractLoader:s,cssLoader:c=`css-loader`,loaderOptions:l,styleLoaderOptions:u,typescript:d=!1}=e,f=Array.from(new Set(r.filter(e=>e!==`css`))),p={loader:a,...u?{options:u}:{}},m=[];for(let e of f){let r=g[e];if(!r)continue;m.push(v({lang:e,module:!0,nativeCss:n,styleLoaderEntry:p,preprocessorLoader:r,isProduction:t,styleInjectLoader:o,styleExtractLoader:s,cssLoader:c}))}m.push(v({module:!0,nativeCss:n,styleLoaderEntry:p,isProduction:t,styleInjectLoader:o,styleExtractLoader:s,cssLoader:c}));for(let e of f){let r=g[e];if(!r)continue;m.push(v({lang:e,module:!1,nativeCss:n,styleLoaderEntry:p,preprocessorLoader:r,isProduction:t,styleInjectLoader:o,styleExtractLoader:s,cssLoader:c}))}return m.push(v({module:!1,nativeCss:n,styleLoaderEntry:p,isProduction:t,styleInjectLoader:o,styleExtractLoader:s,cssLoader:c})),m.push({use:[{loader:i,options:l}]}),[{test:/\.vue$/,oneOf:m},...d?[{test:/\.vue$/,resourceQuery:{not:[/type=/]},enforce:`post`,...d===!0?{loader:`builtin:swc-loader`,options:{jsc:{parser:{syntax:`typescript`}}}}:typeof d==`string`?{loader:d}:d,type:`javascript/auto`}]:[]]}function v(e){let{lang:t,module:n,nativeCss:r,styleLoaderEntry:i,preprocessorLoader:a,isProduction:o,styleInjectLoader:s,styleExtractLoader:c,cssLoader:l}=e,u=[`type=style`];n&&u.push(`module`),t&&u.push(`lang=${t}`);let d=new RegExp(u.map(e=>`(?=.*${e})`).join(``));if(r)return{resourceQuery:d,type:n?`css/module`:`css/auto`,use:a?[a,i]:[i]};let f=typeof l==`string`?{loader:l,options:{modules:{auto:(e,t)=>typeof t==`string`&&t.includes(`module=`)}}}:l;return{resourceQuery:d,type:`javascript/auto`,use:[o&&c?c:s,f,...a?[a]:[],i]}}export{m as VizePlugin,e as addScopeToCssFallback,c as clearCompilationCache,l as compileFile,t as createLogger,_ as createVizeVueRules,n as extractCustomBlocks,r as extractSrcInfo,i as extractStyleBlocks,u as genHotReloadCode,d as generateOutput,a as generateScopeId,o as inlineSrcBlocks,s as matchesPattern,f as vizeLoader,p as vizeStyleLoader};
|
package/dist/loader/index.d.ts
DELETED
package/dist/loader/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../utils-Cw44tFia.js";import{vizeLoader as e}from"../loader-DyzGJOBD.js";export{e as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"../utils-Cw44tFia.js";import{vizeStyleLoader as e}from"../style-loader-DPvk-BhE.js";export{e as default};
|
package/dist/loader-DyzGJOBD.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import{extractCustomBlocks as e,extractSrcInfo as t,extractStyleBlocks as n,generateScopeId as r,inlineSrcBlocks as i,matchesPattern as a}from"./utils-Cw44tFia.js";import{createHash as o}from"node:crypto";import s from"node:path";import c from"node:fs";import*as l from"@vizejs/native";function u(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 d(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:f}=l,p=new Map;function m(e){return o(`sha256`).update(e).digest(`hex`).slice(0,16)}function h(){p.clear()}function g(t,i,a={}){let o=a.compilerOptions?.isTs??/<script[^>]*\blang=["']ts["']/.test(i),s=a.ssr??a.compilerOptions?.ssr??!1,c=a.sourceMap??a.compilerOptions?.sourceMap??!0,l=a.isCustomElement??!1,u=a.rootContext??``,d=a.isProduction??!1,h=`${t}:ssr=${s}:ts=${o}:map=${c}:ce=${l}:root=${u}:prod=${d}`,g=m(i),_=p.get(h);if(_&&_.contentHash===g)return _.result;let v=r(t,a.rootContext,a.isProduction,i),y=/<style[^>]*\bscoped\b/.test(i),b={...a.compilerOptions,filename:t,sourceMap:a.sourceMap??a.compilerOptions?.sourceMap??!0,ssr:s,isTs:o,scopeId:y?`data-v-${v}`:void 0},x=f(i,b),S=n(i),C=e(i),w={code:x.code,css:x.css,errors:x.errors,warnings:x.warnings,scopeId:v,hasScoped:y,styles:S,customBlocks:C,isCustomElement:l};return w.errors.length===0&&p.set(h,{contentHash:g,result:w}),w}function _(e,t){let n=e.code,r=e.isCustomElement,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){let t=e.styles.some(e=>e.module);if(t)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=[],s=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=i.join(`&`),s=`${t.requestPath}?${a}`;if(r)return`import _style_${n.index} from ${JSON.stringify(s)};`;if(n.module){let e=typeof n.module==`string`?n.module:`$style`,t=`_cssModule_${n.index}`;return o.push({request:s,varName:t,bindingName:e}),`import ${t} from ${JSON.stringify(s)};`}return`import ${JSON.stringify(s)};`}).join(`
|
|
18
|
-
`);if(n=s+`
|
|
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=>d(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?s.relative(t.rootContext,t.filePath).replace(/\\/g,`/`):s.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,`${u(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)){if(t===`src`)continue;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 n}const v=/\.ce\.vue$/;function y(n){let r=this.async(),a=this.getOptions(),o=this.resourcePath,l=this.resourceQuery,u=S(this,o),d=this.mode===`production`||process.env.NODE_ENV===`production`,f=a.ssr??!1,p=!f&&!d&&a.hotReload!==!1;if(this.addDependency(o),l?.includes(`type=style`)){r(Error(`[vize] Main loader received style sub-request: ${o}${l}. Use module.rules[].oneOf with resourceQuery branches so style requests are handled by @vizejs/rspack-plugin/style-loader.`));return}if(l&&l.includes(`vue`)&&l.includes(`type=`)&&!l.includes(`type=style`)){let t=new URLSearchParams(l.slice(1)),i=t.get(`type`);if(i&&i!==`style`){let a=parseInt(t.get(`index`)||`0`,10),l=e(n),u=l[a];if(u){if(u.src){let e=s.resolve(s.dirname(o),u.src);this.addDependency(e);try{let t=c.readFileSync(e,`utf-8`);r(null,t)}catch{r(Error(`[vize] Custom block <${i} src="${u.src}"> not found (resolved: ${e}) in ${o}`))}return}r(null,u.content)}else r(null,``);return}}if(!b(o,a)){this.emitWarning(Error(`[vize] File is filtered out by loader options include/exclude: ${o}. Passing through source unchanged.`)),r(null,n);return}try{let e=x(o,a.customElement),l=t(n),f=n;if(l.scriptSrc){let e=s.resolve(s.dirname(o),l.scriptSrc);this.addDependency(e);try{let t=c.readFileSync(e,`utf-8`);f=i(f,t,null)}catch{r(Error(`[vize] <script src="${l.scriptSrc}"> not found (resolved: ${e}) in ${o}`));return}}if(l.templateSrc){let e=s.resolve(s.dirname(o),l.templateSrc);this.addDependency(e);try{let t=c.readFileSync(e,`utf-8`);f=i(f,null,t)}catch{r(Error(`[vize] <template src="${l.templateSrc}"> not found (resolved: ${e}) in ${o}`));return}}let m=g(o,f,{sourceMap:a.sourceMap??this.sourceMap??!0,ssr:a.ssr??!1,compilerOptions:a.compilerOptions,isCustomElement:e,rootContext:this.rootContext,isProduction:d});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`);r(Error(`[vize] Compilation failed for ${o}:\n${e}`));return}let h=_(m,{requestPath:u,hmr:p,filePath:o,isProduction:d,rootContext:this.rootContext});r(null,h)}catch(e){r(e)}}function b(e,t){return!(!a(e,t.include,!0)||a(e,t.exclude,!1))}function x(e,t){return t===!0?!0:t===!1||t===void 0?v.test(e):t.test(e)}function S(e,t){let n=s.basename(t);return`./${n}`}export{h as clearCompilationCache,g as compileFile,u as genHotReloadCode,_ as generateOutput,y as vizeLoader};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{addScopeToCssFallback as e,extractStyleBlocks as t}from"./utils-Cw44tFia.js";import n from"node:path";import r from"node:fs/promises";const i=new Set;function a(e){let i=this.async(),{resourceQuery:a,resourcePath:s}=this;if(!a){i(null,e);return}let c=new URLSearchParams(a.slice(1)),l=c.get(`type`);if(l!==`style`){i(null,e);return}let u=parseInt(c.get(`index`)||`0`,10),d=c.get(`scoped`);this.addDependency(s);let f=t(e),p=f[u];if(!p){this.emitError(Error(`[vize] Style block at index ${u} not found in ${s}`)),i(null,``);return}if(p.src){let e=n.resolve(n.dirname(s),p.src);this.addDependency(e),r.readFile(e,`utf-8`).then(e=>{let t=o(this,e,p.scoped,d,s);i(null,t)}).catch(()=>{this.emitWarning(Error(`[vize] <style src> target not found: ${p.src} (resolved: ${e}) in ${s}`)),i(null,``)});return}let m=o(this,p.content,p.scoped,d,s);i(null,m)}function o(t,n,r,a,o){return r&&a?(i.has(o)||(i.add(o),t.emitWarning(Error(`[vize] scoped CSS uses fallback transformer with limitations: no :deep()/:global()/:slotted(), no nested @media. File: ${o}`))),e(n,a)):n}export{a as vizeStyleLoader};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { VizeStyleLoaderOptions } from "./index-Crp9t5G9.js";
|
|
2
|
-
import { LoaderContext } from "@rspack/core";
|
|
3
|
-
|
|
4
|
-
//#region src/loader/style-loader.d.ts
|
|
5
|
-
|
|
6
|
-
declare function vizeStyleLoader(this: LoaderContext<VizeStyleLoaderOptions>, source: string): void; //#endregion
|
|
7
|
-
export { vizeStyleLoader as vizeStyleLoader$1 };
|
package/dist/utils-Cw44tFia.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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;let s=e(`sha256`).update(o).digest(`hex`);return s.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,o=0,s=0;for(;o<e.length;){let t=e[o];if(t===`{`){if(i===0){let t=e.slice(s,o);r+=a(t,n),r+=`{`}else r+=t;i++,o++,s=o}else t===`}`?(i--,r+=t,o++,s=o):(i>0&&(r+=t),o++)}return s<e.length&&i===0&&(r+=e.slice(s)),r}function a(e,t){let n=e.trim();return n.startsWith(`@`)?e:e.split(`,`).map(e=>{let n=e.trim();if(!n||n.startsWith(`@`))return e;let r=e.match(/^(\s*)/)?.[1]??``;return`${r}${n}${t}`}).join(`,`)}function o(e){let t=e.replace(/<(script|template|style)\b[^>]*>[\s\S]*?<\/\1>/gi,``),n=[],r=/<([a-z][a-z0-9-]*)([^>]*)>([\s\S]*?)<\/\1>/gi,i,a=0;for(;(i=r.exec(t))!==null;){let e=i[1],t=i[2],r=i[3],o=t.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,c=s(t);n.push({type:e,content:r,src:o,attrs:c,index:a}),a++}return n}function s(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 c(e){let t=e.match(/<script([^>]*)>/i),n=e.match(/<template([^>]*)>/i),r=t?.[1]?.match(/\bsrc=["']([^"']+)["']/)?.[1]??null,i=n?.[1]?.match(/\bsrc=["']([^"']+)["']/)?.[1]??null;return{scriptSrc:r,templateSrc:i}}function l(e,t,n){let r=e;return t!==null&&(r=r.replace(/(<script)([^>]*)\bsrc=["'][^"']+["']([^>]*>)[\s\S]*?(<\/script>)/i,(e,n,r,i,a)=>{let o=(r+i).replace(/\bsrc=["'][^"']+["']\s*/g,``);return`${n}${o}\n${t}\n${a}`})),n!==null&&(r=r.replace(/(<template)([^>]*)\bsrc=["'][^"']+["']([^>]*>)[\s\S]*?(<\/template>)/i,(e,t,r,i,a)=>{let o=(r+i).replace(/\bsrc=["'][^"']+["']\s*/g,``);return`${t}${o}\n${n}\n${a}`})),r}function u(e){return{log:(...t)=>e&&console.log(`[vize:rspack]`,...t),info:(...e)=>console.log(`[vize:rspack]`,...e),warn:(...e)=>console.warn(`[vize:rspack]`,...e),error:(...e)=>console.error(`[vize:rspack]`,...e)}}function d(e,t,n){if(!t)return n;let r=e.replace(/\\/g,`/`),i=Array.isArray(t)?t:[t];return i.some(t=>typeof t==`string`?r.includes(t)||e.includes(t):t.test(r))}export{i as addScopeToCssFallback,u as createLogger,o as extractCustomBlocks,c as extractSrcInfo,r as extractStyleBlocks,n as generateScopeId,l as inlineSrcBlocks,d as matchesPattern};
|