@intlify/unplugin-vue-i18n 6.0.4 → 6.0.6

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
@@ -280,17 +280,11 @@ About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimi
280
280
 
281
281
  If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
282
282
 
283
- > [!WARNING]
284
- >
285
- > `json` resources matches this option, it will be handled **before the internal json plugin of bundler, and will not be processed afterwards**, else the option doesn't match, the bundler side will handle.
283
+ > [!WARNING] > `json` resources matches this option, it will be handled **before the internal json plugin of bundler, and will not be processed afterwards**, else the option doesn't match, the bundler side will handle.
286
284
 
287
- > [!WARNING]
288
- >
289
- > `yaml` resources don't support multi documentation with `|`, alias with `&` and `*`, tags with `! `, `@`, etc. Only simple data structures.
285
+ > [!WARNING] > `yaml` resources don't support multi documentation with `|`, alias with `&` and `*`, tags with `! `, `@`, etc. Only simple data structures.
290
286
 
291
- > [!WARNING]
292
- >
293
- > `js` and `ts` resources are set **simple export (`export default`) as locale messages object, as default**.
287
+ > [!WARNING] > `js` and `ts` resources are set **simple export (`export default`) as locale messages object, as default**.
294
288
 
295
289
  ```js
296
290
  export default {
@@ -309,22 +303,22 @@ If you need to use programmatically dynamic resource construction, you would be
309
303
  - **Type:** `string`
310
304
  - **Default:** `'vue-i18n'`
311
305
 
312
- > [!NOTE]
313
- > This options is supported from v5.1.0, and works with vue-i18n v10 and later.
306
+ > [!NOTE]
307
+ > This options is supported from v5.1.0, and works with vue-i18n v10 and later.
314
308
 
315
- Bundle target vue-i18n module. You can specify either `‘vue-i18n’` or `‘petite-vue-i18n’`.
309
+ Bundle target vue-i18n module. You can specify either `‘vue-i18n’` or `‘petite-vue-i18n’`.
316
310
 
317
- The default is `'vue-i18n'`, and the following installed in node_modules will be bundled.
311
+ The default is `'vue-i18n'`, and the following installed in node_modules will be bundled.
318
312
 
319
- - development: `vue-i18n.esm-bundler.js`
320
- - production: `vue-i18n.runtime.esm-bundler.js`
313
+ - development: `vue-i18n.esm-bundler.js`
314
+ - production: `vue-i18n.runtime.esm-bundler.js`
321
315
 
322
- In the case of `‘petite-vue-i18n’`, the following installed in node_modules will be bundled.
316
+ In the case of `‘petite-vue-i18n’`, the following installed in node_modules will be bundled.
323
317
 
324
- - development: `petite-vue-i18n.esm-bundler.js`
325
- - production: `petite-vue-i18n.runtime.esm-bundler.js`
318
+ - development: `petite-vue-i18n.esm-bundler.js`
319
+ - production: `petite-vue-i18n.runtime.esm-bundler.js`
326
320
 
327
- If you are using petite-vue-i18n, you will need to set this value.
321
+ If you are using petite-vue-i18n, you will need to set this value.
328
322
 
329
323
  ### `strictMessage`
330
324
 
@@ -366,7 +360,7 @@ If you are using petite-vue-i18n, you will need to set this value.
366
360
  }
367
361
  ```
368
362
 
369
- If you fetch some resources from the backend, the data **must be pre-compiled** for production. example is [here](https://github.com/intlify/vue-i18n-next/tree/master/examples/backend).
363
+ If you fetch some resources from the backend, the data **must be pre-compiled** for production. exmaple is [here](https://github.com/intlify/vue-i18n-next/tree/master/examples/backend).
370
364
 
371
365
  ### `jitCompilation`
372
366
 
@@ -374,15 +368,15 @@ If you are using petite-vue-i18n, you will need to set this value.
374
368
  - **Default:** `true`
375
369
 
376
370
  > [!IMPORTANT]
377
- > 'jitCompilation' option is deprecated in v5.
371
+ > 'jitCompilation' option is deprected in v5.
378
372
  > This option will be supported with vue-i18n until v9 latest version.
379
373
 
380
- Whether locale messages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.
374
+ Whether locale mesages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.
381
375
 
382
- JIT compilation has been supported since vue-i18n v9.3. This means that since v9 was released until now, the message compiler compiles to executable JavaScript code, however it did not work in the CSP environment. Also, since this was an AOT (Ahead of Time) compilation, it was not possible to dynamically retrieve locale messages from the back-end Database and compose locale messages with programatic.
376
+ JIT compilation has been supported since vue-i18n v9.3. This means that since v9 was released until now, the message compiler compiles to executable JavaScript code, however it did not work in the CSP environment. Also, since this was an AOT (Ahead of Time) compilation, it was not possible to dynamically retrieve locale messages from the back-end Database and compose locale mesages with programatic.
383
377
 
384
378
  > [!WARNING]
385
- > Enabling JIT compilation causes the message compiler to generate AST objects for locale messages instead of JavaScript code. If you pre-compile locale messages with a tool such as the [Intlify CLI](https://github.com/intlify/cli) and import them dynamically, you need to rebuild that resource.
379
+ > Enabling JIT compilation causes the message compiler to generate AST objects for locale mesages instead of JavaScript code. If you pre-compile locale messages with a tool such as the [Intlify CLI](https://github.com/intlify/cli) and import them dynamically, you need to rebuild that resource.
386
380
 
387
381
  About JIT compilation, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#jit-compilation)
388
382
 
@@ -439,9 +433,6 @@ If do you will use this option, you need to enable `jitCompilation` option.
439
433
 
440
434
  For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
441
435
 
442
- > [!CAUTION]
443
- > This option will be removed in v7
444
-
445
436
  ### `fullInstall`
446
437
 
447
438
  - **Type:** `boolean`
@@ -449,7 +440,7 @@ If do you will use this option, you need to enable `jitCompilation` option.
449
440
 
450
441
  Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.
451
442
 
452
- If `false` is specified, **build-in components and directive will not be installed in vue and will be tree-shaken.**
443
+ If `false` is specified, **buld-in components and directive will not be installed in vue and will be tree-shaken.**
453
444
 
454
445
  For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
455
446
 
@@ -606,10 +597,8 @@ If do you will use this option, you need to enable `jitCompilation` option.
606
597
 
607
598
  This option that to use i18n custom blocks in `vue-class-component`.
608
599
 
609
- > [!IMPORTANT]
610
- >
611
- > `useClassComponent` option is deprecated in v5.
612
- > This option will be supported with vue-i18n until v9 latest version.
600
+ > [!IMPORTANT] > `useClassComponent` option is deprecated in v5.
601
+ > This option will be supported with vue-i18n until v9 latest version.
613
602
 
614
603
  ### `onlyLocales`
615
604
 
@@ -625,12 +614,10 @@ If do you will use this option, you need to enable `jitCompilation` option.
625
614
 
626
615
  Whether to use the import name of `petite-vue-i18n` with the same import name as vue-i18n (`import { xxx } from 'vue-i18n'`).
627
616
 
628
- This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhancement.
617
+ This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhacement.
629
618
 
630
- > [!IMPORTANT]
631
- >
632
- > `useVueI18nImportName` option is deprecated in v5.
633
- > This option will be supported with vue-i18n until v9 latest version.
619
+ > [!IMPORTANT] > `useVueI18nImportName` option is deprecated in v5.
620
+ > This option will be supported with vue-i18n until v9 latest version.
634
621
 
635
622
  ### `optimizeTranslationDirective`
636
623
 
@@ -641,8 +628,8 @@ If do you will use this option, you need to enable `jitCompilation` option.
641
628
 
642
629
  If you want to put it manually, you can specify the signature of the translation function as a string or a string array.
643
630
 
644
- > [!WARNING]
645
- > About for manually signature, see the details [vue-i18n-extensions API docs](https://github.com/intlify/vue-i18n-extensions/blob/next/docs/%40intlify/vue-i18n-extensions-api.md#translationsignatures) and [usecase from vue-i18n-extensions PR](https://github.com/intlify/vue-i18n-extensions/pull/217/files#diff-3fb9543f91e011d4b0dc9beff44082fe1a99c9eab70c1afab23c3c34352b7c38R121-R200)
631
+ > [!WARNING]
632
+ > About for manually signature, see the details [vue-i18n-extensions API docs](https://github.com/intlify/vue-i18n-extensions/blob/next/docs/%40intlify/vue-i18n-extensions-api.md#translationsignatures) and [usecase from vue-i18n-extensions PR](https://github.com/intlify/vue-i18n-extensions/pull/217/files#diff-3fb9543f91e011d4b0dc9beff44082fe1a99c9eab70c1afab23c3c34352b7c38R121-R200)
646
633
 
647
634
  ### `transformI18nBlock`
648
635
 
@@ -694,8 +681,8 @@ If do you will use this option, you need to enable `jitCompilation` option.
694
681
  </i18n>
695
682
  ```
696
683
 
697
- > [!IMPORTANT]
698
- > The function **must** return a string or the build will fail.
684
+ > [!IMPORTANT]
685
+ > The function **must** return a string or the build will fail.
699
686
 
700
687
  ## 📜 Changelog
701
688
 
package/lib/index.cjs CHANGED
@@ -44,6 +44,23 @@ function resolveNamespace(name) {
44
44
  function getVitePlugin(config, name) {
45
45
  return config.plugins.find((p) => p.name === name);
46
46
  }
47
+ function getVitePluginTransform(plugin) {
48
+ if (plugin.transform) {
49
+ return "handler" in plugin.transform ? [plugin.transform.handler, "handler"] : [plugin.transform, "transform"];
50
+ } else {
51
+ return [void 0, void 0];
52
+ }
53
+ }
54
+ function overrideVitePluginTransform(plugin, override, to) {
55
+ if (plugin.transform == void 0) {
56
+ throw new Error("plugin.transform is undefined");
57
+ }
58
+ if (to === "handler" && "handler" in plugin.transform) {
59
+ plugin.transform.handler = override;
60
+ } else {
61
+ plugin.transform = override;
62
+ }
63
+ }
47
64
  function checkVuePlugin(vuePlugin) {
48
65
  if (vuePlugin == null || !vuePlugin.api) {
49
66
  error(
@@ -84,6 +101,7 @@ function resolveOptions(options) {
84
101
  const globalSFCScope = !!options.globalSFCScope;
85
102
  const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
86
103
  const dropMessageCompiler = !!options.dropMessageCompiler;
104
+ const compositionOnly = moduleType === "vue-i18n" ? shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
87
105
  const fullInstall = moduleType === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
88
106
  const ssrBuild = !!options.ssr;
89
107
  const allowDynamic = !!options.allowDynamic;
@@ -102,6 +120,7 @@ function resolveOptions(options) {
102
120
  globalSFCScope,
103
121
  runtimeOnly,
104
122
  dropMessageCompiler,
123
+ compositionOnly,
105
124
  fullInstall,
106
125
  ssrBuild,
107
126
  allowDynamic,
@@ -191,6 +210,7 @@ function resourcePlugin({
191
210
  globalSFCScope,
192
211
  runtimeOnly,
193
212
  dropMessageCompiler,
213
+ compositionOnly,
194
214
  fullInstall,
195
215
  ssrBuild,
196
216
  strictMessage,
@@ -200,7 +220,7 @@ function resourcePlugin({
200
220
  }, meta) {
201
221
  const filter = pluginutils.createFilter(include, exclude);
202
222
  const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
203
- return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.js"}`;
223
+ return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
204
224
  };
205
225
  let isProduction = false;
206
226
  let sourceMap = false;
@@ -225,6 +245,7 @@ function resourcePlugin({
225
245
  config() {
226
246
  const defineConfig = {
227
247
  define: {
248
+ __VUE_I18N_LEGACY_API__: !compositionOnly,
228
249
  __VUE_I18N_FULL_INSTALL__: fullInstall,
229
250
  __INTLIFY_DROP_MESSAGE_COMPILER__: dropMessageCompiler,
230
251
  __VUE_I18N_PROD_DEVTOOLS__: false
@@ -256,8 +277,11 @@ function resourcePlugin({
256
277
  );
257
278
  const jsonPlugin = getVitePlugin(config, "vite:json");
258
279
  if (jsonPlugin) {
259
- const orgTransform = jsonPlugin.transform;
260
- jsonPlugin.transform = async function(code, id) {
280
+ const [orgTransform, transformWay] = getVitePluginTransform(jsonPlugin);
281
+ if (!orgTransform) {
282
+ throw new Error("vite:json plugin not found!");
283
+ }
284
+ async function overrideViteJsonPlugin(code, id) {
261
285
  if (!/\.json$/.test(id) || filter(id)) {
262
286
  return;
263
287
  }
@@ -267,7 +291,12 @@ function resourcePlugin({
267
291
  }
268
292
  debug$2("org json plugin");
269
293
  return orgTransform.apply(this, [code, id]);
270
- };
294
+ }
295
+ overrideVitePluginTransform(
296
+ jsonPlugin,
297
+ overrideViteJsonPlugin,
298
+ transformWay
299
+ );
271
300
  }
272
301
  const esbuildPlugin = getVitePlugin(config, "vite:esbuild");
273
302
  if (esbuildPlugin) {
@@ -352,10 +381,12 @@ function resourcePlugin({
352
381
  if (webpack) {
353
382
  compiler.options.plugins.push(
354
383
  new webpack.DefinePlugin({
384
+ __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
355
385
  __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
356
386
  __INTLIFY_PROD_DEVTOOLS__: "false"
357
387
  })
358
388
  );
389
+ debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
359
390
  debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
360
391
  } else {
361
392
  debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
package/lib/index.mjs CHANGED
@@ -32,6 +32,23 @@ function resolveNamespace(name) {
32
32
  function getVitePlugin(config, name) {
33
33
  return config.plugins.find((p) => p.name === name);
34
34
  }
35
+ function getVitePluginTransform(plugin) {
36
+ if (plugin.transform) {
37
+ return "handler" in plugin.transform ? [plugin.transform.handler, "handler"] : [plugin.transform, "transform"];
38
+ } else {
39
+ return [void 0, void 0];
40
+ }
41
+ }
42
+ function overrideVitePluginTransform(plugin, override, to) {
43
+ if (plugin.transform == void 0) {
44
+ throw new Error("plugin.transform is undefined");
45
+ }
46
+ if (to === "handler" && "handler" in plugin.transform) {
47
+ plugin.transform.handler = override;
48
+ } else {
49
+ plugin.transform = override;
50
+ }
51
+ }
35
52
  function checkVuePlugin(vuePlugin) {
36
53
  if (vuePlugin == null || !vuePlugin.api) {
37
54
  error(
@@ -72,6 +89,7 @@ function resolveOptions(options) {
72
89
  const globalSFCScope = !!options.globalSFCScope;
73
90
  const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
74
91
  const dropMessageCompiler = !!options.dropMessageCompiler;
92
+ const compositionOnly = moduleType === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
75
93
  const fullInstall = moduleType === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
76
94
  const ssrBuild = !!options.ssr;
77
95
  const allowDynamic = !!options.allowDynamic;
@@ -90,6 +108,7 @@ function resolveOptions(options) {
90
108
  globalSFCScope,
91
109
  runtimeOnly,
92
110
  dropMessageCompiler,
111
+ compositionOnly,
93
112
  fullInstall,
94
113
  ssrBuild,
95
114
  allowDynamic,
@@ -179,6 +198,7 @@ function resourcePlugin({
179
198
  globalSFCScope,
180
199
  runtimeOnly,
181
200
  dropMessageCompiler,
201
+ compositionOnly,
182
202
  fullInstall,
183
203
  ssrBuild,
184
204
  strictMessage,
@@ -188,7 +208,7 @@ function resourcePlugin({
188
208
  }, meta) {
189
209
  const filter = createFilter(include, exclude);
190
210
  const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
191
- return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.js"}`;
211
+ return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
192
212
  };
193
213
  let isProduction = false;
194
214
  let sourceMap = false;
@@ -213,6 +233,7 @@ function resourcePlugin({
213
233
  config() {
214
234
  const defineConfig = {
215
235
  define: {
236
+ __VUE_I18N_LEGACY_API__: !compositionOnly,
216
237
  __VUE_I18N_FULL_INSTALL__: fullInstall,
217
238
  __INTLIFY_DROP_MESSAGE_COMPILER__: dropMessageCompiler,
218
239
  __VUE_I18N_PROD_DEVTOOLS__: false
@@ -244,8 +265,11 @@ function resourcePlugin({
244
265
  );
245
266
  const jsonPlugin = getVitePlugin(config, "vite:json");
246
267
  if (jsonPlugin) {
247
- const orgTransform = jsonPlugin.transform;
248
- jsonPlugin.transform = async function(code, id) {
268
+ const [orgTransform, transformWay] = getVitePluginTransform(jsonPlugin);
269
+ if (!orgTransform) {
270
+ throw new Error("vite:json plugin not found!");
271
+ }
272
+ async function overrideViteJsonPlugin(code, id) {
249
273
  if (!/\.json$/.test(id) || filter(id)) {
250
274
  return;
251
275
  }
@@ -255,7 +279,12 @@ function resourcePlugin({
255
279
  }
256
280
  debug$2("org json plugin");
257
281
  return orgTransform.apply(this, [code, id]);
258
- };
282
+ }
283
+ overrideVitePluginTransform(
284
+ jsonPlugin,
285
+ overrideViteJsonPlugin,
286
+ transformWay
287
+ );
259
288
  }
260
289
  const esbuildPlugin = getVitePlugin(config, "vite:esbuild");
261
290
  if (esbuildPlugin) {
@@ -340,10 +369,12 @@ function resourcePlugin({
340
369
  if (webpack) {
341
370
  compiler.options.plugins.push(
342
371
  new webpack.DefinePlugin({
372
+ __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
343
373
  __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
344
374
  __INTLIFY_PROD_DEVTOOLS__: "false"
345
375
  })
346
376
  );
377
+ debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
347
378
  debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
348
379
  } else {
349
380
  debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
package/lib/types.d.cts CHANGED
@@ -7,6 +7,7 @@ interface PluginOptions {
7
7
  module?: VueI18nModule;
8
8
  dropMessageCompiler?: boolean;
9
9
  runtimeOnly?: boolean;
10
+ compositionOnly?: boolean;
10
11
  ssr?: boolean;
11
12
  fullInstall?: boolean;
12
13
  forceStringify?: boolean;
package/lib/types.d.mts CHANGED
@@ -7,6 +7,7 @@ interface PluginOptions {
7
7
  module?: VueI18nModule;
8
8
  dropMessageCompiler?: boolean;
9
9
  runtimeOnly?: boolean;
10
+ compositionOnly?: boolean;
10
11
  ssr?: boolean;
11
12
  fullInstall?: boolean;
12
13
  forceStringify?: boolean;
package/lib/types.d.ts CHANGED
@@ -7,6 +7,7 @@ interface PluginOptions {
7
7
  module?: VueI18nModule;
8
8
  dropMessageCompiler?: boolean;
9
9
  runtimeOnly?: boolean;
10
+ compositionOnly?: boolean;
10
11
  ssr?: boolean;
11
12
  fullInstall?: boolean;
12
13
  forceStringify?: boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
3
  "type": "module",
4
- "version": "6.0.4",
4
+ "version": "6.0.6",
5
5
  "description": "unplugin for Vue I18n",
6
6
  "author": {
7
7
  "name": "kazuya kawaguchi",