@vizejs/rspack-plugin 0.37.0 → 0.39.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 +104 -11
- package/dist/{index-Bvwqw7T6.d.mts → index-CrdHfSbU.d.mts} +7 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/loader/index.d.mts +1 -1
- package/dist/loader/index.mjs +1 -1
- package/dist/loader/scope-loader.mjs +1 -1
- package/dist/loader/style-loader.d.mts +1 -1
- package/dist/loader/style-loader.mjs +1 -1
- package/dist/{loader-CTDGCafa.mjs → loader-BGVyAZvr.mjs} +1 -1
- package/dist/{utils-B5WyWrfH.mjs → utils-DDd2p4Wp.mjs} +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ High-performance Rspack plugin for Vue SFC compilation powered by [Vize](https:/
|
|
|
16
16
|
- 🎨 **CSS Processing** - Support for both native CSS (`experiments.css`) and CssExtractRspackPlugin
|
|
17
17
|
- 📦 **CSS Modules** - First-class CSS Modules support with per-module HMR
|
|
18
18
|
- 🔗 **`<style src>` Support** - Resolves external style files with watch dependency tracking
|
|
19
|
-
- 🔧 **TypeScript** - Full TypeScript support with auto-detection and
|
|
19
|
+
- 🔧 **TypeScript** - Full TypeScript support with auto-detection and built-in SWC stripping by default
|
|
20
20
|
- 🗄️ **Compilation Cache** - Content-hash based caching to skip re-compilation of unchanged files
|
|
21
21
|
- 🛠️ **Vue DevTools** - Exposes `__file` for component file path in development mode
|
|
22
22
|
- 🧩 **Custom Elements** - Auto-detect `.ce.vue` or configure via `customElement` option
|
|
@@ -31,7 +31,7 @@ pnpm add -D @vizejs/rspack-plugin @rspack/core
|
|
|
31
31
|
|
|
32
32
|
### Simple Mode (Recommended)
|
|
33
33
|
|
|
34
|
-
Write a single `.vue` rule and your normal CSS rules. `VizePlugin` automatically clones your CSS rules for Vue style sub-requests.
|
|
34
|
+
Write a single `.vue` rule and your normal CSS rules. `VizePlugin` automatically clones your CSS rules for Vue style sub-requests and injects Rspack's built-in SWC post-processing for `.vue` TypeScript output.
|
|
35
35
|
|
|
36
36
|
```javascript
|
|
37
37
|
// rspack.config.mjs
|
|
@@ -131,7 +131,10 @@ export default {
|
|
|
131
131
|
{
|
|
132
132
|
test: /\.css$/,
|
|
133
133
|
type: "javascript/auto",
|
|
134
|
-
use: [
|
|
134
|
+
use: [
|
|
135
|
+
isProduction ? rspack.CssExtractRspackPlugin.loader : "style-loader",
|
|
136
|
+
"css-loader",
|
|
137
|
+
],
|
|
135
138
|
},
|
|
136
139
|
{
|
|
137
140
|
test: /\.scss$/,
|
|
@@ -318,7 +321,9 @@ export default {
|
|
|
318
321
|
resourceQuery: /vue&type=style.*lang=scss/,
|
|
319
322
|
type: "javascript/auto",
|
|
320
323
|
use: [
|
|
321
|
-
isProduction
|
|
324
|
+
isProduction
|
|
325
|
+
? rspack.CssExtractRspackPlugin.loader
|
|
326
|
+
: "style-loader",
|
|
322
327
|
"css-loader",
|
|
323
328
|
{ loader: "@vizejs/rspack-plugin/scope-loader" },
|
|
324
329
|
"sass-loader",
|
|
@@ -331,13 +336,16 @@ export default {
|
|
|
331
336
|
resourceQuery: /vue&type=style/,
|
|
332
337
|
type: "javascript/auto",
|
|
333
338
|
use: [
|
|
334
|
-
isProduction
|
|
339
|
+
isProduction
|
|
340
|
+
? rspack.CssExtractRspackPlugin.loader
|
|
341
|
+
: "style-loader",
|
|
335
342
|
{
|
|
336
343
|
loader: "css-loader",
|
|
337
344
|
options: {
|
|
338
345
|
modules: {
|
|
339
346
|
auto: (_resourcePath, resourceQuery) =>
|
|
340
|
-
typeof resourceQuery === "string" &&
|
|
347
|
+
typeof resourceQuery === "string" &&
|
|
348
|
+
resourceQuery.includes("module="),
|
|
341
349
|
},
|
|
342
350
|
},
|
|
343
351
|
},
|
|
@@ -361,7 +369,10 @@ export default {
|
|
|
361
369
|
{
|
|
362
370
|
test: /\.css$/,
|
|
363
371
|
type: "javascript/auto",
|
|
364
|
-
use: [
|
|
372
|
+
use: [
|
|
373
|
+
isProduction ? rspack.CssExtractRspackPlugin.loader : "style-loader",
|
|
374
|
+
"css-loader",
|
|
375
|
+
],
|
|
365
376
|
},
|
|
366
377
|
|
|
367
378
|
// Regular SCSS files (non-Vue)
|
|
@@ -424,6 +435,7 @@ new VizePlugin({
|
|
|
424
435
|
compilerOptions: {}; // Extra @vizejs/native compileSfc options
|
|
425
436
|
debug: boolean; // Enable debug logging (default: false)
|
|
426
437
|
autoRules: boolean; // Auto-clone CSS rules for Vue style sub-requests (default: true)
|
|
438
|
+
typescript: boolean; // Auto-inject builtin:swc-loader for .vue post-processing (default: true)
|
|
427
439
|
});
|
|
428
440
|
// Debug logging uses Rspack's infrastructure logger.
|
|
429
441
|
// Control verbosity via `infrastructureLogging.level` in your rspack config.
|
|
@@ -463,11 +475,92 @@ Compilation errors cause the loader to fail immediately (`callback(error)`) inst
|
|
|
463
475
|
|
|
464
476
|
#### TypeScript
|
|
465
477
|
|
|
466
|
-
`@vizejs/native compileSfc` preserves TypeScript syntax in its output (same behavior as `@vue/compiler-sfc`).
|
|
478
|
+
`@vizejs/native compileSfc` preserves TypeScript syntax in its output (same behavior as `@vue/compiler-sfc`). By default, `VizePlugin` injects a `.vue` `enforce: "post"` rule using Rspack's built-in `builtin:swc-loader` to strip those type annotations for main SFC requests.
|
|
479
|
+
|
|
480
|
+
- **Default behavior**: No extra config is required. `new VizePlugin()` automatically injects the SWC post-processing rule.
|
|
481
|
+
- **Opt out**: Set `new VizePlugin({ typescript: false })` if you want to manage `.vue` TypeScript stripping yourself.
|
|
482
|
+
- **Custom loader**: When opting out, use `esbuild-loader`, `builtin:swc-loader`, or any other TS transpiler as your own `enforce: "post"` rule for `.vue` files (excluding `type=style` requests).
|
|
483
|
+
|
|
484
|
+
<details>
|
|
485
|
+
<summary>Advanced: builtin:swc-loader</summary>
|
|
486
|
+
|
|
487
|
+
```javascript
|
|
488
|
+
// rspack.config.mjs
|
|
489
|
+
import { defineConfig } from "@rspack/cli";
|
|
490
|
+
import { VizePlugin } from "@vizejs/rspack-plugin";
|
|
491
|
+
|
|
492
|
+
export default defineConfig({
|
|
493
|
+
module: {
|
|
494
|
+
rules: [
|
|
495
|
+
{
|
|
496
|
+
test: /\.vue$/,
|
|
497
|
+
loader: "@vizejs/rspack-plugin/loader",
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
test: /\.vue$/,
|
|
501
|
+
resourceQuery: { not: [/type=/] },
|
|
502
|
+
enforce: "post",
|
|
503
|
+
loader: "builtin:swc-loader",
|
|
504
|
+
options: {
|
|
505
|
+
jsc: {
|
|
506
|
+
parser: {
|
|
507
|
+
syntax: "typescript",
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
type: "javascript/auto",
|
|
512
|
+
},
|
|
513
|
+
],
|
|
514
|
+
},
|
|
515
|
+
plugins: [
|
|
516
|
+
new VizePlugin({
|
|
517
|
+
typescript: false,
|
|
518
|
+
}),
|
|
519
|
+
],
|
|
520
|
+
});
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
</details>
|
|
524
|
+
|
|
525
|
+
<details>
|
|
526
|
+
<summary>Advanced: esbuild-loader</summary>
|
|
527
|
+
|
|
528
|
+
```javascript
|
|
529
|
+
// rspack.config.mjs
|
|
530
|
+
import { defineConfig } from "@rspack/cli";
|
|
531
|
+
import { VizePlugin } from "@vizejs/rspack-plugin";
|
|
532
|
+
|
|
533
|
+
export default defineConfig({
|
|
534
|
+
module: {
|
|
535
|
+
rules: [
|
|
536
|
+
{
|
|
537
|
+
test: /\.vue$/,
|
|
538
|
+
loader: "@vizejs/rspack-plugin/loader",
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
test: /\.vue$/,
|
|
542
|
+
resourceQuery: { not: [/type=/] },
|
|
543
|
+
enforce: "post",
|
|
544
|
+
loader: "esbuild-loader",
|
|
545
|
+
options: {
|
|
546
|
+
loader: "ts",
|
|
547
|
+
target: "es2020",
|
|
548
|
+
},
|
|
549
|
+
type: "javascript/auto",
|
|
550
|
+
},
|
|
551
|
+
],
|
|
552
|
+
},
|
|
553
|
+
plugins: [
|
|
554
|
+
new VizePlugin({
|
|
555
|
+
typescript: false,
|
|
556
|
+
}),
|
|
557
|
+
],
|
|
558
|
+
});
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
> Requires `esbuild-loader` and `esbuild` to be installed in your project.
|
|
467
562
|
|
|
468
|
-
|
|
469
|
-
- **Custom loader**: Use `esbuild-loader` or any other TS transpiler
|
|
470
|
-
- **Manual**: Add your own `enforce: "post"` rule for `.vue` files (exclude `type=style` requests)
|
|
563
|
+
</details>
|
|
471
564
|
|
|
472
565
|
The `isTs` option is auto-detected from `<script lang="ts">` and passed to the native compiler for correct parsing.
|
|
473
566
|
|
|
@@ -128,6 +128,13 @@ interface VizeRspackPluginOptions {
|
|
|
128
128
|
debug?: boolean;
|
|
129
129
|
/** Auto-clone CSS rules for Vue style sub-requests (like VueLoaderPlugin). @default true */
|
|
130
130
|
autoRules?: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Auto-inject a `builtin:swc-loader` post-processing rule to strip TypeScript
|
|
133
|
+
* annotations from compiled `.vue` output. Safe for non-TS SFCs (SWC passes
|
|
134
|
+
* plain JS through unchanged). Set to `false` to handle TS stripping yourself.
|
|
135
|
+
* @default true
|
|
136
|
+
*/
|
|
137
|
+
typescript?: boolean;
|
|
131
138
|
}
|
|
132
139
|
/** Loader entry: either a string (loader name/path) or an object with loader + options */
|
|
133
140
|
type LoaderEntry = string | {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-CrdHfSbU.mjs";
|
|
2
2
|
import vizeLoader from "./loader/index.mjs";
|
|
3
3
|
import vizeStyleLoader from "./loader/style-loader.mjs";
|
|
4
4
|
import vizeScopeLoader from "./loader/scope-loader.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e,c as t,i as n,o as r,r as i,s as a,t as o}from"./utils-
|
|
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-DDd2p4Wp.mjs";import{a as s,i as c,n as l,r as u,t as d}from"./loader-BGVyAZvr.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)}}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: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};
|
package/dist/loader/index.d.mts
CHANGED
package/dist/loader/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../utils-
|
|
1
|
+
import"../utils-DDd2p4Wp.mjs";import{t as e}from"../loader-BGVyAZvr.mjs";export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as e}from"../utils-
|
|
1
|
+
import{l as e}from"../utils-DDd2p4Wp.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"../utils-
|
|
1
|
+
import{a as e}from"../utils-DDd2p4Wp.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};
|
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-DDd2p4Wp.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
2
|
/* hot reload */
|
|
3
3
|
if (module.hot) {
|
|
4
4
|
_sfc_main.__hmrId = "${e}"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
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
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(?:=["']([^"']+)["'])
|
|
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(?:=["']([^"']+)["'])?/),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
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/rspack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "High-performance Rspack plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@vizejs/native": "0.
|
|
53
|
+
"@vizejs/native": "0.39.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@rspack/core": "^1.7.7",
|