@vizejs/unplugin 0.206.0 → 0.210.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/dist/babel.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-B13SJWBj.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-CgwReHH2.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-BvkszWH0.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-BBdWoA7s.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 { r as VizeUnpluginOptions } from "./types-B13SJWBj.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-CgwReHH2.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-BvkszWH0.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-B13SJWBj.mjs";
1
+ import { i as VizeVueVersion, n as VizeCompatibilityOptions, r as VizeUnpluginOptions, t as MacroArtifact } from "./types-CgwReHH2.mjs";
2
2
  import * as _$unplugin from "unplugin";
3
3
  //#region src/unplugin.d.ts
4
4
  declare const vizeUnplugin: _$unplugin.UnpluginInstance<VizeUnpluginOptions | undefined, boolean>;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-BvkszWH0.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-B13SJWBj.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-CgwReHH2.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-BvkszWH0.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.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 { r as VizeUnpluginOptions } from "./types-B13SJWBj.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-CgwReHH2.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-BvkszWH0.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -17,6 +17,13 @@ interface VizeUnpluginOptions {
17
17
  sourceMap?: boolean;
18
18
  mode?: "module" | "function";
19
19
  vapor?: boolean;
20
+ /**
21
+ * Default output mode for `.jsx`/`.tsx` components without a `"use vue:*"`
22
+ * directive. Distinct from `vapor` (which targets `.vue` SFCs). A
23
+ * per-component directive overrides it.
24
+ * @default "vdom"
25
+ */
26
+ jsxMode?: "vdom" | "vapor";
20
27
  customRenderer?: boolean;
21
28
  templateSyntax?: VizeTemplateSyntax;
22
29
  runtimeModuleName?: string;
@@ -7,7 +7,7 @@ import { generateSfcScopeId, wrapSfcScopedPreprocessorStyle } from "@vizejs/nati
7
7
  import { transform } from "oxc-transform";
8
8
  //#region src/filter.ts
9
9
  function createFilter(include, exclude) {
10
- const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/];
10
+ const includePatterns = include ? Array.isArray(include) ? include : [include] : [/\.vue$/, /\.[jt]sx$/];
11
11
  const excludePatterns = exclude ? Array.isArray(exclude) ? exclude : [exclude] : [/node_modules/];
12
12
  return (id) => {
13
13
  const matchInclude = includePatterns.some((pattern) => matchesPattern(pattern, id));
@@ -46,6 +46,35 @@ function generateScopeId(filename, root, isProduction, source) {
46
46
  function supportsTemplateOnlyHmr(output) {
47
47
  return /(?:^|\n)(?:_sfc_main|__sfc__)\.render\s*=\s*render\b/m.test(output);
48
48
  }
49
+ /**
50
+ * Prepend a runtime `<style>` injection for plain CSS to a module's output.
51
+ *
52
+ * This is the same inline-CSS path plain SFC `<style>` blocks use (see
53
+ * {@link generateOutput}): a guarded `document.createElement("style")` keyed by
54
+ * a stable id, so the rule is appended once and idempotently. `styleKey` seeds
55
+ * the element id (deduping re-injection across HMR/multiple imports). Used for
56
+ * both SFC plain CSS and JSX `<style scoped>` CSS (#1495, #1533), whose content
57
+ * is already scope-rewritten by the compiler.
58
+ */
59
+ function prependInlineStyleInjection(output, css, styleKey) {
60
+ return `
61
+ export const __vize_css__ = ${JSON.stringify(css)};
62
+ const __vize_css_id__ = ${JSON.stringify(`vize-style-${styleKey}`)};
63
+ (function() {
64
+ if (typeof document !== "undefined") {
65
+ let style = document.getElementById(__vize_css_id__);
66
+ if (!style) {
67
+ style = document.createElement("style");
68
+ style.id = __vize_css_id__;
69
+ style.textContent = __vize_css__;
70
+ document.head.appendChild(style);
71
+ } else {
72
+ style.textContent = __vize_css__;
73
+ }
74
+ }
75
+ })();
76
+ ${output}`;
77
+ }
49
78
  function generateOutput(compiled, options) {
50
79
  const { isProduction, isDev, extractCss, filePath } = options;
51
80
  let output = compiled.code;
@@ -92,23 +121,7 @@ function generateOutput(compiled, options) {
92
121
  }).join("\n");
93
122
  output = output.replace(/^export default _sfc_main;?$/m, `${cssModuleSetup}\nexport default _sfc_main;`);
94
123
  }
95
- } else if (compiled.css && !(isProduction && extractCss)) output = `
96
- export const __vize_css__ = ${JSON.stringify(compiled.css)};
97
- const __vize_css_id__ = ${JSON.stringify(`vize-style-${compiled.scopeId}`)};
98
- (function() {
99
- if (typeof document !== "undefined") {
100
- let style = document.getElementById(__vize_css_id__);
101
- if (!style) {
102
- style = document.createElement("style");
103
- style.id = __vize_css_id__;
104
- style.textContent = __vize_css__;
105
- document.head.appendChild(style);
106
- } else {
107
- style.textContent = __vize_css__;
108
- }
109
- }
110
- })();
111
- ${output}`;
124
+ } else if (compiled.css && !(isProduction && extractCss)) output = prependInlineStyleInjection(output, compiled.css, compiled.scopeId);
112
125
  if (!isProduction && isDev && hasExportDefault && supportsTemplateOnlyHmr(output)) output += "";
113
126
  return output;
114
127
  }
@@ -127,7 +140,7 @@ function toStyleBlockInfo(block) {
127
140
  }
128
141
  //#endregion
129
142
  //#region src/compiler.ts
130
- const { compileSfc } = native;
143
+ const { compileSfc, compileJsx } = native;
131
144
  function buildSignature(options) {
132
145
  return [
133
146
  options.isProduction ? "1" : "0",
@@ -191,12 +204,38 @@ function compileVueModule(filePath, source, options, cache) {
191
204
  warnings: result.warnings
192
205
  };
193
206
  }
207
+ function compileJsxModule(filePath, source, options) {
208
+ const result = compileJsx(source, {
209
+ filename: filePath,
210
+ lang: filePath.endsWith(".tsx") ? "tsx" : "jsx",
211
+ jsxMode: options.jsxMode,
212
+ vapor: options.vapor,
213
+ sourceMap: options.sourceMap
214
+ });
215
+ if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
216
+ const css = (result.scopedStyles ?? []).map((style) => style.css).join("\n");
217
+ let code = result.code;
218
+ let map = result.map ?? null;
219
+ if (css) {
220
+ const styleKey = result.scopedStyles[0].scopeId.replace(/^data-v-/, "");
221
+ code = prependInlineStyleInjection(code, css, styleKey);
222
+ map = null;
223
+ }
224
+ return {
225
+ code,
226
+ map,
227
+ warnings: result.warnings
228
+ };
229
+ }
194
230
  //#endregion
195
231
  //#region src/request.ts
196
232
  const STYLE_MARKER = ".__vize_style_";
197
233
  function isVueFile(id) {
198
234
  return id.endsWith(".vue");
199
235
  }
236
+ function isJsxFile(id) {
237
+ return id.endsWith(".jsx") || id.endsWith(".tsx");
238
+ }
200
239
  function isVueStyleRequest(id) {
201
240
  if (!id.includes("?vue")) return false;
202
241
  const { query } = parseVueRequest(id);
@@ -289,6 +328,7 @@ function normalizeOptions(rawOptions = {}) {
289
328
  sourceMap: rawOptions.sourceMap ?? !isProduction,
290
329
  mode,
291
330
  vapor: rawOptions.vapor ?? false,
331
+ jsxMode: rawOptions.jsxMode,
292
332
  customRenderer: rawOptions.customRenderer ?? false,
293
333
  templateSyntax,
294
334
  runtimeModuleName: rawOptions.runtimeModuleName ?? "vue",
@@ -366,12 +406,22 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
366
406
  },
367
407
  transformInclude(id) {
368
408
  if (options.hostCompiler) return false;
409
+ if (isJsxFile(id)) return filter(id);
369
410
  if (!id.includes(".vue")) return false;
370
411
  const request = parseVueRequest(id);
371
412
  return !request.query.vue && isVueFile(request.filename) && filter(request.filename);
372
413
  },
373
414
  async transform(code, id) {
374
415
  if (options.hostCompiler) return null;
416
+ if (isJsxFile(id)) {
417
+ if (!filter(id)) return null;
418
+ const { code: jsxCode, map: jsxMap, warnings } = compileJsxModule(id, code, options);
419
+ for (const warning of warnings) this.warn(`[vize] ${warning}`);
420
+ return {
421
+ code: jsxCode,
422
+ map: jsxMap
423
+ };
424
+ }
375
425
  if (!isVueFile(id) || !filter(id)) return null;
376
426
  const { compiled, warnings } = compileVueModule(id, code, options, cache);
377
427
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
@@ -392,8 +442,8 @@ const vizeUnplugin = createUnplugin((rawOptions = {}) => {
392
442
  if (!options.hostCompiler) injectWebpackVueDefines(compiler, options.isProduction, options.compatibility.webpackVersion);
393
443
  },
394
444
  esbuild: {
395
- onResolveFilter: /\.vue(?:$|\?)/,
396
- onLoadFilter: /\.vue(?:$|\?)/,
445
+ onResolveFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
446
+ onLoadFilter: /\.(?:vue|[jt]sx)(?:$|\?)/,
397
447
  loader(_code, id) {
398
448
  const request = parseVueRequest(id);
399
449
  if (request.query.type === "style") return request.query.module !== false ? "local-css" : "css";
@@ -1,4 +1,4 @@
1
- import { r as VizeUnpluginOptions } from "./types-B13SJWBj.mjs";
1
+ import { r as VizeUnpluginOptions } from "./types-CgwReHH2.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-BvkszWH0.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-BBdWoA7s.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.206.0",
3
+ "version": "0.210.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.206.0",
70
+ "@vizejs/native": "0.210.0",
71
71
  "oxc-transform": "0.130.0",
72
72
  "unplugin": "3.0.0"
73
73
  },