@vizejs/unplugin 0.170.0 → 0.172.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 CHANGED
@@ -46,6 +46,36 @@ export default {
46
46
  };
47
47
  ```
48
48
 
49
+ Webpack 5 is detected through `compiler.webpack`. Webpack 4 is supported by resolving
50
+ `DefinePlugin` from the host project's `webpack` package:
51
+
52
+ ```javascript
53
+ import Vize from "@vizejs/unplugin/webpack";
54
+
55
+ export default {
56
+ plugins: [
57
+ Vize({
58
+ compatibility: {
59
+ webpackVersion: 4,
60
+ },
61
+ }),
62
+ ],
63
+ };
64
+ ```
65
+
66
+ For Vue 0.11, Vue 1, Vue 2, or Nuxt 2 projects that already use the legacy
67
+ Vue/Webpack compiler chain, keep Vize non-invasive and let the host compiler
68
+ handle `.vue` files:
69
+
70
+ ```javascript
71
+ Vize({
72
+ compatibility: {
73
+ vueVersion: 2,
74
+ webpackVersion: 4,
75
+ },
76
+ });
77
+ ```
78
+
49
79
  ### rolldown
50
80
 
51
81
  ```javascript
@@ -86,5 +116,5 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
86
116
 
87
117
  - Vite is still the recommended integration if you need the most complete behavior today.
88
118
  - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
89
- - If your bundler inlines the Vue runtime, configure the usual Vue compile-time feature flags for that bundler.
119
+ - If your bundler inlines the Vue runtime, Vize injects the usual Vue 3 compile-time feature flags for Rollup-like and Webpack hosts when its compiler is active.
90
120
  - Test carefully before depending on this package in production.
package/dist/babel.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as VizeUnpluginOptions } from "./types-CcN4XyQ3.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-oQVaBbVI.mjs";
2
2
 
3
3
  //#region src/babel.d.ts
4
4
  type BabelParserOptions = Record<string, unknown> & {
package/dist/babel.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BhadWZfz.mjs";
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = normalizeOptions(rawOptions);
@@ -1,4 +1,4 @@
1
- import { n as VizeUnpluginOptions } from "./types-CcN4XyQ3.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-oQVaBbVI.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/esbuild.d.ts
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BhadWZfz.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
- import { n as VizeUnpluginOptions, t as MacroArtifact } from "./types-CcN4XyQ3.mjs";
1
+ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-oQVaBbVI.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
-
4
3
  //#region src/unplugin.d.ts
5
4
  declare const vizeUnplugin: _$unplugin.UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
6
5
  //#endregion
7
- export { type MacroArtifact, type VizeUnpluginOptions, vizeUnplugin as default, vizeUnplugin };
6
+ export { type MacroArtifact, type VizeCompatibilityOptions, type VizeUnpluginOptions, type VizeVueVersion, vizeUnplugin as default, vizeUnplugin };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BhadWZfz.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
@@ -1,4 +1,4 @@
1
- import { n as VizeUnpluginOptions } from "./types-CcN4XyQ3.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-oQVaBbVI.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/rolldown.d.ts
package/dist/rolldown.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BhadWZfz.mjs";
2
2
  //#region src/rolldown.ts
3
3
  var rolldown_default = vizeUnplugin.rollup;
4
4
  //#endregion
package/dist/rollup.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as VizeUnpluginOptions } from "./types-CcN4XyQ3.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-oQVaBbVI.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
 
4
4
  //#region src/rollup.d.ts
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BhadWZfz.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -0,0 +1,61 @@
1
+ //#region src/types.d.ts
2
+ interface MacroArtifact {
3
+ kind: string;
4
+ name: string;
5
+ source: string;
6
+ content: string;
7
+ moduleCode?: string;
8
+ start: number;
9
+ end: number;
10
+ }
11
+ interface VizeUnpluginOptions {
12
+ include?: string | RegExp | Array<string | RegExp>;
13
+ exclude?: string | RegExp | Array<string | RegExp>;
14
+ compatibility?: VizeCompatibilityOptions;
15
+ isProduction?: boolean;
16
+ ssr?: boolean;
17
+ sourceMap?: boolean;
18
+ mode?: "module" | "function";
19
+ vapor?: boolean;
20
+ customRenderer?: boolean;
21
+ vueParserQuirks?: boolean;
22
+ runtimeModuleName?: string;
23
+ runtimeGlobalName?: string;
24
+ vueVersion?: VizeVueVersion;
25
+ root?: string;
26
+ debug?: boolean;
27
+ }
28
+ type VizeVueVersion = 0.11 | 1 | 2 | 3 | "legacy";
29
+ interface VizeCompatibilityOptions {
30
+ /**
31
+ * Host Vue version. Vue 0.11/1/2 opt into host-compiler compatibility.
32
+ */
33
+ vueVersion?: VizeVueVersion;
34
+ /**
35
+ * Keep .vue files on the existing Vue compiler for legacy Vue runtimes.
36
+ * @default true when vueVersion is 0.11, 1, 2, or "legacy"
37
+ */
38
+ hostCompiler?: boolean;
39
+ /**
40
+ * Enable function-body output for CDN/global Vue evaluation.
41
+ */
42
+ scriptSetupInStandalone?: boolean;
43
+ /**
44
+ * Allow Vapor output for Options API SFCs when vapor is enabled.
45
+ */
46
+ optionsApiVapor?: boolean;
47
+ /**
48
+ * Override the host Nuxt major when this option object is shared with Nuxt.
49
+ */
50
+ nuxtVersion?: 2 | 3 | 4;
51
+ /**
52
+ * Force Webpack compatibility behavior.
53
+ *
54
+ * Webpack 4 does not expose `compiler.webpack`, so the plugin resolves
55
+ * `DefinePlugin` from the host `webpack` package when this is `4` or when
56
+ * auto-detection sees a Webpack 4 compiler shape.
57
+ */
58
+ webpackVersion?: 4 | 5;
59
+ }
60
+ //#endregion
61
+ export { VizeVueVersion as i, VizeCompatibilityOptions as n, VizeUnpluginOptions as r, MacroArtifact as t };
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import fs from "node:fs";
2
3
  import { createUnplugin } from "unplugin";
3
4
  import { createHash } from "node:crypto";
@@ -135,6 +136,11 @@ function buildSignature(options) {
135
136
  options.customRenderer ? "1" : "0",
136
137
  options.vueParserQuirks ? "1" : "0",
137
138
  options.sourceMap ? "1" : "0",
139
+ options.mode,
140
+ options.runtimeModuleName,
141
+ options.runtimeGlobalName,
142
+ String(options.vueVersion),
143
+ options.hostCompiler ? "1" : "0",
138
144
  options.root
139
145
  ].join(":");
140
146
  }
@@ -152,11 +158,15 @@ function compileVueModule(filePath, source, options, cache) {
152
158
  const scopeId = generateScopeId(filePath, options.root, options.isProduction, source);
153
159
  const result = compileSfc(source, {
154
160
  filename: filePath,
161
+ mode: options.mode,
155
162
  sourceMap: options.sourceMap,
156
163
  ssr: options.ssr,
157
164
  vapor: options.vapor,
158
165
  customRenderer: options.customRenderer,
159
166
  vueParserQuirks: options.vueParserQuirks,
167
+ runtimeModuleName: options.runtimeModuleName,
168
+ runtimeGlobalName: options.runtimeGlobalName,
169
+ vueVersion: String(options.vueVersion),
160
170
  scopeId: `data-v-${scopeId}`
161
171
  });
162
172
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
@@ -252,17 +262,34 @@ async function stripTypeScript(filePath, code, sourceMap) {
252
262
  }
253
263
  //#endregion
254
264
  //#region src/unplugin.ts
265
+ const require = createRequire(import.meta.url);
266
+ function normalizeVueVersion(version) {
267
+ return version ?? 3;
268
+ }
269
+ function isLegacyVueVersion(version) {
270
+ return version === "legacy" || version === .11 || version === 1 || version === 2;
271
+ }
255
272
  function normalizeOptions(rawOptions = {}) {
256
273
  const isProduction = rawOptions.isProduction ?? process.env.NODE_ENV === "production";
274
+ const compatibility = rawOptions.compatibility ?? {};
275
+ const vueVersion = normalizeVueVersion(rawOptions.vueVersion ?? compatibility.vueVersion);
276
+ const mode = rawOptions.mode ?? (compatibility.scriptSetupInStandalone === true ? "function" : "module");
277
+ const hostCompiler = compatibility.hostCompiler ?? isLegacyVueVersion(vueVersion);
257
278
  return {
258
279
  include: rawOptions.include,
259
280
  exclude: rawOptions.exclude,
281
+ compatibility,
260
282
  isProduction,
261
283
  ssr: rawOptions.ssr ?? false,
262
284
  sourceMap: rawOptions.sourceMap ?? !isProduction,
285
+ mode,
263
286
  vapor: rawOptions.vapor ?? false,
264
287
  customRenderer: rawOptions.customRenderer ?? false,
265
288
  vueParserQuirks: rawOptions.vueParserQuirks ?? false,
289
+ runtimeModuleName: rawOptions.runtimeModuleName ?? "vue",
290
+ runtimeGlobalName: rawOptions.runtimeGlobalName ?? "Vue",
291
+ vueVersion,
292
+ hostCompiler,
266
293
  root: rawOptions.root ?? process.cwd(),
267
294
  debug: rawOptions.debug ?? false
268
295
  };
@@ -274,8 +301,17 @@ function createVueDefineMap(isProduction) {
274
301
  __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: JSON.stringify(!isProduction)
275
302
  };
276
303
  }
277
- function injectWebpackVueDefines(compiler, isProduction) {
278
- const { DefinePlugin } = compiler.webpack;
304
+ function resolveWebpackDefinePlugin(compiler, webpackVersion) {
305
+ if (webpackVersion !== 4 && compiler.webpack?.DefinePlugin) return compiler.webpack.DefinePlugin;
306
+ try {
307
+ return require("webpack").DefinePlugin ?? null;
308
+ } catch {
309
+ return null;
310
+ }
311
+ }
312
+ function injectWebpackVueDefines(compiler, isProduction, webpackVersion, definePluginConstructor) {
313
+ const DefinePlugin = definePluginConstructor ?? resolveWebpackDefinePlugin(compiler, webpackVersion);
314
+ if (!DefinePlugin) throw new Error("[vize] Could not resolve webpack DefinePlugin. Install webpack in the host project or disable the Vize compiler with compatibility.hostCompiler.");
279
315
  const existingDefines = /* @__PURE__ */ new Set();
280
316
  for (const plugin of compiler.options.plugins ?? []) {
281
317
  const definitions = plugin.definitions;
@@ -307,13 +343,16 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
307
343
  return {
308
344
  name: "unplugin-vize",
309
345
  resolveId(id) {
346
+ if (options.hostCompiler) return null;
310
347
  if (isVueStyleRequest(id)) return createVirtualStyleId(id);
311
348
  return null;
312
349
  },
313
350
  loadInclude(id) {
351
+ if (options.hostCompiler) return false;
314
352
  return isVirtualStyleId(id);
315
353
  },
316
354
  async load(id) {
355
+ if (options.hostCompiler) return null;
317
356
  if (!isVirtualStyleId(id)) return null;
318
357
  return {
319
358
  code: await loadStyleBlock(id, options, cache),
@@ -321,10 +360,12 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
321
360
  };
322
361
  },
323
362
  transformInclude(id) {
363
+ if (options.hostCompiler) return false;
324
364
  const request = parseVueRequest(id);
325
365
  return !request.query.vue && isVueFile(request.filename) && filter(request.filename);
326
366
  },
327
367
  async transform(code, id) {
368
+ if (options.hostCompiler) return null;
328
369
  if (!isVueFile(id) || !filter(id)) return null;
329
370
  const { compiled, warnings } = compileVueModule(id, code, options, cache);
330
371
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
@@ -342,7 +383,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
342
383
  if (isVueFile(id)) cache.delete(id);
343
384
  },
344
385
  webpack(compiler) {
345
- injectWebpackVueDefines(compiler, options.isProduction);
386
+ if (!options.hostCompiler) injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
346
387
  },
347
388
  esbuild: {
348
389
  onResolveFilter: /\.vue(?:$|\?)/,
@@ -353,6 +394,7 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
353
394
  return "js";
354
395
  },
355
396
  config(buildOptions) {
397
+ if (options.hostCompiler) return;
356
398
  buildOptions.define = {
357
399
  ...createVueDefineMap(options.isProduction),
358
400
  ...buildOptions.define
@@ -1,4 +1,4 @@
1
- import { n as VizeUnpluginOptions } from "./types-CcN4XyQ3.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-oQVaBbVI.mjs";
2
2
  import * as _$webpack from "webpack";
3
3
 
4
4
  //#region src/webpack.d.ts
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-BDyKPnrQ.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BhadWZfz.mjs";
2
2
  //#region src/webpack.ts
3
3
  var webpack_default = vizeUnplugin.webpack;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/unplugin",
3
- "version": "0.170.0",
3
+ "version": "0.172.0",
4
4
  "description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
5
5
  "keywords": [
6
6
  "babel",
@@ -67,7 +67,7 @@
67
67
  "access": "public"
68
68
  },
69
69
  "dependencies": {
70
- "@vizejs/native": "0.170.0",
70
+ "@vizejs/native": "0.172.0",
71
71
  "oxc-transform": "0.130.0",
72
72
  "unplugin": "3.0.0"
73
73
  },
@@ -80,6 +80,14 @@
80
80
  "vue": "3.6.0-beta.10",
81
81
  "webpack": "5.106.2"
82
82
  },
83
+ "peerDependencies": {
84
+ "webpack": "^4.46.0 || ^5.0.0"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "webpack": {
88
+ "optional": true
89
+ }
90
+ },
83
91
  "engines": {
84
92
  "node": ">=22"
85
93
  },
@@ -1,24 +0,0 @@
1
- //#region src/types.d.ts
2
- interface MacroArtifact {
3
- kind: string;
4
- name: string;
5
- source: string;
6
- content: string;
7
- moduleCode?: string;
8
- start: number;
9
- end: number;
10
- }
11
- interface VizeUnpluginOptions {
12
- include?: string | RegExp | Array<string | RegExp>;
13
- exclude?: string | RegExp | Array<string | RegExp>;
14
- isProduction?: boolean;
15
- ssr?: boolean;
16
- sourceMap?: boolean;
17
- vapor?: boolean;
18
- customRenderer?: boolean;
19
- vueParserQuirks?: boolean;
20
- root?: string;
21
- debug?: boolean;
22
- }
23
- //#endregion
24
- export { VizeUnpluginOptions as n, MacroArtifact as t };