@intlify/unplugin-vue-i18n 0.11.0 → 0.12.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
@@ -8,6 +8,7 @@
8
8
  unplugin for Vue I18n
9
9
 
10
10
  ## 🌟 Features
11
+
11
12
  - i18n resource pre-compilation
12
13
  - i18n custom block
13
14
  - i18n resource definition
@@ -84,14 +85,11 @@ export default defineNuxtConfig({
84
85
 
85
86
  ## 🚀 Usage
86
87
 
87
- ### i18n resources pre-compilation
88
-
89
- Since `vue-i18n@v9.x`, the locale messages are handled with message compiler, which converts them to javascript functions after compiling. After compiling, message compiler converts them into javascript functions, which can improve the performance of the application.
88
+ ### locale messages pre-compilation
90
89
 
91
- However, with the message compiler, the javascript function conversion will not work in some environments (e.g. CSP). For this reason, `vue-i18n@v9.x` and later offer a full version that includes compiler and runtime, and a runtime only version.
92
-
93
- If you are using the runtime version, you will need to compile before importing locale messages by managing them in a file such as `.json`.
90
+ Since `vue-i18n@v9.x`, the locale messages are handled with message compiler, which transform them to javascript functions or AST objects after compiling, so these can improve the performance of the application.
94
91
 
92
+ If you want to maximize the performance of vue-i18n, we recommend using unplugin-vue-i18n for locale messages.
95
93
 
96
94
  ### i18n custom block
97
95
 
@@ -241,7 +239,9 @@ If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplu
241
239
 
242
240
 
243
241
  ## 📦 Automatic bundling
242
+
244
243
  ### For Vue I18n
244
+
245
245
  As noted [here](https://vue-i18n.intlify.dev/guide/installation.html#explanation-of-different-builds), NPM provides many different builds of Vue I18n.
246
246
 
247
247
  This plugin will automatically select and bundle Vue I18n build according to the following behavior:
@@ -345,6 +345,22 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
345
345
 
346
346
  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).
347
347
 
348
+ ### `jitCompilation`
349
+
350
+ - **Type:** `boolean`
351
+ - **Default:** `false`
352
+
353
+ Whether locale mesages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.
354
+
355
+ > ⚠️ NOTE:
356
+ This option works with vue-i18n v9.3 and later.
357
+
358
+ 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.
359
+
360
+ > ⚠️ NOTE:
361
+ 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.
362
+
363
+ About JIT compilation, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#jit-compilation)
348
364
 
349
365
  ### `runtimeOnly`
350
366
 
@@ -360,6 +376,8 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
360
376
 
361
377
  If `false` is specified, Vue I18n (vue-i18n) package.json `module` field will be used.
362
378
 
379
+ **If you want to dynamically handle with locale mesages, such as fetch from back-end DB, set this option to `false`**.
380
+
363
381
  For more details, See [here](#-automatic-bundling)
364
382
 
365
383
  ### `compositionOnly`
package/lib/index.cjs CHANGED
@@ -121,6 +121,8 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
121
121
  debug("bridge", bridge);
122
122
  const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
123
123
  debug("runtimeOnly", runtimeOnly);
124
+ const jitCompilation = !!options.jitCompilation;
125
+ debug("jitCompilation", jitCompilation);
124
126
  const compositionOnly = installedPkg === "vue-i18n" ? shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
125
127
  debug("compositionOnly", compositionOnly);
126
128
  const fullInstall = installedPkg === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
@@ -214,6 +216,10 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
214
216
  debug(
215
217
  `set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`
216
218
  );
219
+ config.define["__INTLIFY_JIT_COMPILATION__"] = jitCompilation;
220
+ debug(
221
+ `set __INTLIFY_JIT_COMPILATION__ is '${config.define["__INTLIFY_JIT_COMPILATION__"]}'`
222
+ );
217
223
  config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
218
224
  },
219
225
  configResolved(config) {
@@ -269,6 +275,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
269
275
  strictMessage,
270
276
  escapeHtml,
271
277
  bridge,
278
+ jit: jitCompilation,
272
279
  exportESM: esm,
273
280
  forceStringify
274
281
  }
@@ -435,6 +442,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
435
442
  strictMessage,
436
443
  escapeHtml,
437
444
  bridge,
445
+ jit: jitCompilation,
438
446
  exportESM: esm,
439
447
  forceStringify
440
448
  }
@@ -474,6 +482,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
474
482
  isGlobal: globalSFCScope,
475
483
  useClassComponent,
476
484
  bridge,
485
+ jit: jitCompilation,
477
486
  strictMessage,
478
487
  escapeHtml,
479
488
  exportESM: esm,
@@ -546,7 +555,8 @@ async function generateBundleResources(resources, query, isProduction, {
546
555
  exportESM = true,
547
556
  strictMessage = true,
548
557
  escapeHtml = false,
549
- useClassComponent = false
558
+ useClassComponent = false,
559
+ jit = false
550
560
  }) {
551
561
  const codes = [];
552
562
  for (const res of resources) {
@@ -559,6 +569,7 @@ async function generateBundleResources(resources, query, isProduction, {
559
569
  isGlobal,
560
570
  useClassComponent,
561
571
  bridge,
572
+ jit,
562
573
  exportESM,
563
574
  strictMessage,
564
575
  escapeHtml,
@@ -620,7 +631,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
620
631
  useClassComponent = false,
621
632
  allowDynamic = false,
622
633
  strictMessage = true,
623
- escapeHtml = false
634
+ escapeHtml = false,
635
+ jit = false
624
636
  }) {
625
637
  const mode = isProduction ? "production" : "development";
626
638
  const baseOptions = {
@@ -633,6 +645,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
633
645
  strictMessage,
634
646
  escapeHtml,
635
647
  bridge,
648
+ jit,
636
649
  exportESM,
637
650
  env: mode,
638
651
  onWarn: (msg) => {
package/lib/index.mjs CHANGED
@@ -117,6 +117,8 @@ const unplugin = createUnplugin((options = {}, meta) => {
117
117
  debug("bridge", bridge);
118
118
  const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
119
119
  debug("runtimeOnly", runtimeOnly);
120
+ const jitCompilation = !!options.jitCompilation;
121
+ debug("jitCompilation", jitCompilation);
120
122
  const compositionOnly = installedPkg === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
121
123
  debug("compositionOnly", compositionOnly);
122
124
  const fullInstall = installedPkg === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
@@ -210,6 +212,10 @@ const unplugin = createUnplugin((options = {}, meta) => {
210
212
  debug(
211
213
  `set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`
212
214
  );
215
+ config.define["__INTLIFY_JIT_COMPILATION__"] = jitCompilation;
216
+ debug(
217
+ `set __INTLIFY_JIT_COMPILATION__ is '${config.define["__INTLIFY_JIT_COMPILATION__"]}'`
218
+ );
213
219
  config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
214
220
  },
215
221
  configResolved(config) {
@@ -265,6 +271,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
265
271
  strictMessage,
266
272
  escapeHtml,
267
273
  bridge,
274
+ jit: jitCompilation,
268
275
  exportESM: esm,
269
276
  forceStringify
270
277
  }
@@ -431,6 +438,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
431
438
  strictMessage,
432
439
  escapeHtml,
433
440
  bridge,
441
+ jit: jitCompilation,
434
442
  exportESM: esm,
435
443
  forceStringify
436
444
  }
@@ -470,6 +478,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
470
478
  isGlobal: globalSFCScope,
471
479
  useClassComponent,
472
480
  bridge,
481
+ jit: jitCompilation,
473
482
  strictMessage,
474
483
  escapeHtml,
475
484
  exportESM: esm,
@@ -542,7 +551,8 @@ async function generateBundleResources(resources, query, isProduction, {
542
551
  exportESM = true,
543
552
  strictMessage = true,
544
553
  escapeHtml = false,
545
- useClassComponent = false
554
+ useClassComponent = false,
555
+ jit = false
546
556
  }) {
547
557
  const codes = [];
548
558
  for (const res of resources) {
@@ -555,6 +565,7 @@ async function generateBundleResources(resources, query, isProduction, {
555
565
  isGlobal,
556
566
  useClassComponent,
557
567
  bridge,
568
+ jit,
558
569
  exportESM,
559
570
  strictMessage,
560
571
  escapeHtml,
@@ -616,7 +627,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
616
627
  useClassComponent = false,
617
628
  allowDynamic = false,
618
629
  strictMessage = true,
619
- escapeHtml = false
630
+ escapeHtml = false,
631
+ jit = false
620
632
  }) {
621
633
  const mode = isProduction ? "production" : "development";
622
634
  const baseOptions = {
@@ -629,6 +641,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
629
641
  strictMessage,
630
642
  escapeHtml,
631
643
  bridge,
644
+ jit,
632
645
  exportESM,
633
646
  env: mode,
634
647
  onWarn: (msg) => {
package/lib/types.d.ts CHANGED
@@ -2,6 +2,7 @@ type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
2
2
  interface PluginOptions {
3
3
  include?: string | string[];
4
4
  allowDynamic?: boolean;
5
+ jitCompilation?: boolean;
5
6
  runtimeOnly?: boolean;
6
7
  compositionOnly?: boolean;
7
8
  fullInstall?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -26,8 +26,8 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@intlify/bundle-utils": "^6.0.1",
30
- "@intlify/shared": "9.3.0-beta.17",
29
+ "@intlify/bundle-utils": "^7.0.0",
30
+ "@intlify/shared": "9.3.0-beta.20",
31
31
  "@rollup/pluginutils": "^5.0.2",
32
32
  "@vue/compiler-sfc": "^3.2.47",
33
33
  "debug": "^4.3.3",
@@ -36,7 +36,7 @@
36
36
  "json5": "^2.2.3",
37
37
  "pathe": "^1.0.0",
38
38
  "picocolors": "^1.0.0",
39
- "source-map": "0.6.1",
39
+ "source-map-js": "^1.0.2",
40
40
  "unplugin": "^1.1.0"
41
41
  },
42
42
  "devDependencies": {