@intlify/unplugin-vue-i18n 1.2.0 → 1.4.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
@@ -377,6 +377,16 @@ This option works with vue-i18n v9.3 and later.
377
377
  > ⚠️ NOTE:
378
378
  If you enable this option, **you should check resources in your application are pre-compiled with this plugin.** If you will be loading resources dynamically from the back-end via the API, enabling this option do not work because there is not message compiler.
379
379
 
380
+ ### `ssr`
381
+
382
+ - **Type:** `boolean`
383
+ - **Default:** `false`
384
+
385
+ Whether to bundle vue-i18n module for SSR at build time
386
+
387
+ > ⚠️ NOTE:
388
+ This option works with vue-i18n v9.4 and later.
389
+
380
390
  ### `runtimeOnly`
381
391
 
382
392
  - **Type:** `boolean`
@@ -549,6 +559,13 @@ If you enable this option, **you should check resources in your application are
549
559
 
550
560
  This option that to use i18n custom blocks in `vue-class-component`.
551
561
 
562
+ ### `onlyLocales`
563
+
564
+ - **Type:** `string | string[]`
565
+ - **Default:** `[]`
566
+
567
+ By using it you can exclude from the bundle those localizations that are not specified in this option.
568
+
552
569
  ### `useVueI18nImportName` (Experimental)
553
570
 
554
571
  - **Type:** `boolean`
package/lib/index.cjs CHANGED
@@ -109,6 +109,10 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
109
109
  if (!["vite", "webpack"].includes(meta.framework)) {
110
110
  raiseError(`This plugin is supported 'vite' and 'webpack' only`);
111
111
  }
112
+ let onlyLocales = [];
113
+ if (options.onlyLocales) {
114
+ onlyLocales = Array.isArray(options.onlyLocales) ? options.onlyLocales : [options.onlyLocales];
115
+ }
112
116
  let include = options.include;
113
117
  let exclude = null;
114
118
  if (include) {
@@ -137,6 +141,8 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
137
141
  debug("compositionOnly", compositionOnly);
138
142
  const fullInstall = installedPkg === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
139
143
  debug("fullInstall", fullInstall);
144
+ const ssrBuild = !!options.ssr;
145
+ debug("ssr", ssrBuild);
140
146
  const useVueI18nImportName = options.useVueI18nImportName;
141
147
  if (useVueI18nImportName != null) {
142
148
  warn(`'useVueI18nImportName' option is experimental`);
@@ -144,7 +150,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
144
150
  debug("useVueI18nImportName", useVueI18nImportName);
145
151
  const getVueI18nAliasName = () => vueI18nVersion === "9" || vueI18nVersion === "8" ? "vue-i18n" : vueI18nVersion === "unknown" && installedPkg === "petite-vue-i18n" && shared.isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : installedPkg;
146
152
  const getVueI18nBridgeAliasPath = () => `vue-i18n-bridge/dist/vue-i18n-bridge.runtime.esm-bundler.js`;
147
- const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
153
+ const getVueI18nAliasPath = (aliasName, { ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
154
+ return vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
155
+ };
148
156
  const esm = shared.isBoolean(options.esm) ? options.esm : true;
149
157
  debug("esm", esm);
150
158
  const allowDynamic = !!options.allowDynamic;
@@ -173,12 +181,15 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
173
181
  config.resolve,
174
182
  meta.framework
175
183
  );
176
- if (command === "build" && runtimeOnly) {
184
+ if (command === "build") {
177
185
  debug(`vue-i18n alias name: ${vueI18nAliasName}`);
178
186
  if (shared.isArray(config.resolve.alias)) {
179
187
  config.resolve.alias.push({
180
188
  find: vueI18nAliasName,
181
- replacement: getVueI18nAliasPath(vueI18nAliasName)
189
+ replacement: getVueI18nAliasPath(vueI18nAliasName, {
190
+ ssr: ssrBuild,
191
+ runtimeOnly
192
+ })
182
193
  });
183
194
  if (installedVueI18nBridge) {
184
195
  config.resolve.alias.push({
@@ -187,14 +198,21 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
187
198
  });
188
199
  }
189
200
  } else if (shared.isObject(config.resolve.alias)) {
190
- config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
201
+ config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName, {
202
+ ssr: ssrBuild,
203
+ runtimeOnly
204
+ });
191
205
  if (installedVueI18nBridge) {
192
206
  config.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
193
207
  }
194
208
  }
195
209
  debug(
196
210
  `set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
197
- vueI18nAliasName
211
+ vueI18nAliasName,
212
+ {
213
+ ssr: ssrBuild,
214
+ runtimeOnly
215
+ }
198
216
  )}`
199
217
  );
200
218
  if (installedVueI18nBridge) {
@@ -290,6 +308,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
290
308
  escapeHtml,
291
309
  bridge,
292
310
  jit: jitCompilation,
311
+ onlyLocales,
293
312
  exportESM: esm,
294
313
  forceStringify
295
314
  }
@@ -336,15 +355,19 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
336
355
  compiler.options.resolve,
337
356
  meta.framework
338
357
  );
339
- if (isProduction && runtimeOnly) {
340
- compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
358
+ if (isProduction) {
359
+ compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName, {
360
+ ssr: ssrBuild,
361
+ runtimeOnly
362
+ });
341
363
  if (installedVueI18nBridge) {
342
364
  compiler.options.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
343
365
  }
344
366
  debug(
345
- `set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
346
- vueI18nAliasName
347
- )}`
367
+ `set ${vueI18nAliasName}: ${getVueI18nAliasPath(vueI18nAliasName, {
368
+ ssr: ssrBuild,
369
+ runtimeOnly
370
+ })}`
348
371
  );
349
372
  if (installedVueI18nBridge) {
350
373
  debug(
@@ -458,6 +481,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
458
481
  escapeHtml,
459
482
  bridge,
460
483
  jit: jitCompilation,
484
+ onlyLocales,
461
485
  exportESM: esm,
462
486
  forceStringify
463
487
  }
@@ -501,6 +525,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
501
525
  jit: jitCompilation,
502
526
  strictMessage,
503
527
  escapeHtml,
528
+ onlyLocales,
504
529
  exportESM: esm,
505
530
  forceStringify
506
531
  }
@@ -569,6 +594,7 @@ async function generateBundleResources(resources, query, isProduction, {
569
594
  forceStringify = false,
570
595
  isGlobal = false,
571
596
  bridge = false,
597
+ onlyLocales = [],
572
598
  exportESM = true,
573
599
  strictMessage = true,
574
600
  escapeHtml = false,
@@ -587,6 +613,7 @@ async function generateBundleResources(resources, query, isProduction, {
587
613
  useClassComponent,
588
614
  bridge,
589
615
  jit,
616
+ onlyLocales,
590
617
  exportESM,
591
618
  strictMessage,
592
619
  escapeHtml,
@@ -644,6 +671,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
644
671
  forceStringify = false,
645
672
  isGlobal = false,
646
673
  bridge = false,
674
+ onlyLocales = [],
647
675
  exportESM = true,
648
676
  useClassComponent = false,
649
677
  allowDynamic = false,
@@ -663,6 +691,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
663
691
  escapeHtml,
664
692
  bridge,
665
693
  jit,
694
+ onlyLocales,
666
695
  exportESM,
667
696
  env: mode,
668
697
  onWarn: (msg) => {
package/lib/index.mjs CHANGED
@@ -97,6 +97,10 @@ const unplugin = createUnplugin((options = {}, meta) => {
97
97
  if (!["vite", "webpack"].includes(meta.framework)) {
98
98
  raiseError(`This plugin is supported 'vite' and 'webpack' only`);
99
99
  }
100
+ let onlyLocales = [];
101
+ if (options.onlyLocales) {
102
+ onlyLocales = Array.isArray(options.onlyLocales) ? options.onlyLocales : [options.onlyLocales];
103
+ }
100
104
  let include = options.include;
101
105
  let exclude = null;
102
106
  if (include) {
@@ -125,6 +129,8 @@ const unplugin = createUnplugin((options = {}, meta) => {
125
129
  debug("compositionOnly", compositionOnly);
126
130
  const fullInstall = installedPkg === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
127
131
  debug("fullInstall", fullInstall);
132
+ const ssrBuild = !!options.ssr;
133
+ debug("ssr", ssrBuild);
128
134
  const useVueI18nImportName = options.useVueI18nImportName;
129
135
  if (useVueI18nImportName != null) {
130
136
  warn(`'useVueI18nImportName' option is experimental`);
@@ -132,7 +138,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
132
138
  debug("useVueI18nImportName", useVueI18nImportName);
133
139
  const getVueI18nAliasName = () => vueI18nVersion === "9" || vueI18nVersion === "8" ? "vue-i18n" : vueI18nVersion === "unknown" && installedPkg === "petite-vue-i18n" && isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : installedPkg;
134
140
  const getVueI18nBridgeAliasPath = () => `vue-i18n-bridge/dist/vue-i18n-bridge.runtime.esm-bundler.js`;
135
- const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
141
+ const getVueI18nAliasPath = (aliasName, { ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
142
+ return vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
143
+ };
136
144
  const esm = isBoolean(options.esm) ? options.esm : true;
137
145
  debug("esm", esm);
138
146
  const allowDynamic = !!options.allowDynamic;
@@ -161,12 +169,15 @@ const unplugin = createUnplugin((options = {}, meta) => {
161
169
  config.resolve,
162
170
  meta.framework
163
171
  );
164
- if (command === "build" && runtimeOnly) {
172
+ if (command === "build") {
165
173
  debug(`vue-i18n alias name: ${vueI18nAliasName}`);
166
174
  if (isArray(config.resolve.alias)) {
167
175
  config.resolve.alias.push({
168
176
  find: vueI18nAliasName,
169
- replacement: getVueI18nAliasPath(vueI18nAliasName)
177
+ replacement: getVueI18nAliasPath(vueI18nAliasName, {
178
+ ssr: ssrBuild,
179
+ runtimeOnly
180
+ })
170
181
  });
171
182
  if (installedVueI18nBridge) {
172
183
  config.resolve.alias.push({
@@ -175,14 +186,21 @@ const unplugin = createUnplugin((options = {}, meta) => {
175
186
  });
176
187
  }
177
188
  } else if (isObject(config.resolve.alias)) {
178
- config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
189
+ config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName, {
190
+ ssr: ssrBuild,
191
+ runtimeOnly
192
+ });
179
193
  if (installedVueI18nBridge) {
180
194
  config.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
181
195
  }
182
196
  }
183
197
  debug(
184
198
  `set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
185
- vueI18nAliasName
199
+ vueI18nAliasName,
200
+ {
201
+ ssr: ssrBuild,
202
+ runtimeOnly
203
+ }
186
204
  )}`
187
205
  );
188
206
  if (installedVueI18nBridge) {
@@ -278,6 +296,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
278
296
  escapeHtml,
279
297
  bridge,
280
298
  jit: jitCompilation,
299
+ onlyLocales,
281
300
  exportESM: esm,
282
301
  forceStringify
283
302
  }
@@ -324,15 +343,19 @@ const unplugin = createUnplugin((options = {}, meta) => {
324
343
  compiler.options.resolve,
325
344
  meta.framework
326
345
  );
327
- if (isProduction && runtimeOnly) {
328
- compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
346
+ if (isProduction) {
347
+ compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName, {
348
+ ssr: ssrBuild,
349
+ runtimeOnly
350
+ });
329
351
  if (installedVueI18nBridge) {
330
352
  compiler.options.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
331
353
  }
332
354
  debug(
333
- `set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
334
- vueI18nAliasName
335
- )}`
355
+ `set ${vueI18nAliasName}: ${getVueI18nAliasPath(vueI18nAliasName, {
356
+ ssr: ssrBuild,
357
+ runtimeOnly
358
+ })}`
336
359
  );
337
360
  if (installedVueI18nBridge) {
338
361
  debug(
@@ -446,6 +469,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
446
469
  escapeHtml,
447
470
  bridge,
448
471
  jit: jitCompilation,
472
+ onlyLocales,
449
473
  exportESM: esm,
450
474
  forceStringify
451
475
  }
@@ -489,6 +513,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
489
513
  jit: jitCompilation,
490
514
  strictMessage,
491
515
  escapeHtml,
516
+ onlyLocales,
492
517
  exportESM: esm,
493
518
  forceStringify
494
519
  }
@@ -557,6 +582,7 @@ async function generateBundleResources(resources, query, isProduction, {
557
582
  forceStringify = false,
558
583
  isGlobal = false,
559
584
  bridge = false,
585
+ onlyLocales = [],
560
586
  exportESM = true,
561
587
  strictMessage = true,
562
588
  escapeHtml = false,
@@ -575,6 +601,7 @@ async function generateBundleResources(resources, query, isProduction, {
575
601
  useClassComponent,
576
602
  bridge,
577
603
  jit,
604
+ onlyLocales,
578
605
  exportESM,
579
606
  strictMessage,
580
607
  escapeHtml,
@@ -632,6 +659,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
632
659
  forceStringify = false,
633
660
  isGlobal = false,
634
661
  bridge = false,
662
+ onlyLocales = [],
635
663
  exportESM = true,
636
664
  useClassComponent = false,
637
665
  allowDynamic = false,
@@ -651,6 +679,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
651
679
  escapeHtml,
652
680
  bridge,
653
681
  jit,
682
+ onlyLocales,
654
683
  exportESM,
655
684
  env: mode,
656
685
  onWarn: (msg) => {
package/lib/types.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
2
2
  interface PluginOptions {
3
3
  include?: string | string[];
4
+ onlyLocales?: string | string[];
4
5
  allowDynamic?: boolean;
5
6
  jitCompilation?: boolean;
6
7
  dropMessageCompiler?: boolean;
7
8
  runtimeOnly?: boolean;
8
9
  compositionOnly?: boolean;
10
+ ssr?: boolean;
9
11
  fullInstall?: boolean;
10
12
  esm?: boolean;
11
13
  forceStringify?: boolean;
package/lib/types.d.mts CHANGED
@@ -1,11 +1,13 @@
1
1
  type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
2
2
  interface PluginOptions {
3
3
  include?: string | string[];
4
+ onlyLocales?: string | string[];
4
5
  allowDynamic?: boolean;
5
6
  jitCompilation?: boolean;
6
7
  dropMessageCompiler?: boolean;
7
8
  runtimeOnly?: boolean;
8
9
  compositionOnly?: boolean;
10
+ ssr?: boolean;
9
11
  fullInstall?: boolean;
10
12
  esm?: boolean;
11
13
  forceStringify?: boolean;
package/lib/types.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
2
2
  interface PluginOptions {
3
3
  include?: string | string[];
4
+ onlyLocales?: string | string[];
4
5
  allowDynamic?: boolean;
5
6
  jitCompilation?: boolean;
6
7
  dropMessageCompiler?: boolean;
7
8
  runtimeOnly?: boolean;
8
9
  compositionOnly?: boolean;
10
+ ssr?: boolean;
9
11
  fullInstall?: boolean;
10
12
  esm?: boolean;
11
13
  forceStringify?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -26,7 +26,7 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@intlify/bundle-utils": "^7.3.0",
29
+ "@intlify/bundle-utils": "^7.4.0",
30
30
  "@intlify/shared": "^9.4.0",
31
31
  "@rollup/pluginutils": "^5.0.2",
32
32
  "@vue/compiler-sfc": "^3.2.47",