@intlify/unplugin-vue-i18n 0.9.1 → 0.9.3

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
@@ -277,9 +277,16 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
277
277
  - ts
278
278
  ```
279
279
 
280
- Note `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.
280
+ If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
281
+
282
+ > ⚠️ NOTE:
283
+ `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.
284
+
285
+ > ⚠️ NOTE:
286
+ `yaml` resources don't support multi documentation with `|`, alias with `&` and `*`, tags with `! `, `@`, etc. Only simple data structures.
281
287
 
282
- Note that `js` and `ts` resources are limited to **simple export (`export default`) as locale messages object only**, such as programmatically dynamic resource construction is not guaranteed to work currently.
288
+ > ⚠️ NOTE:
289
+ `js` and `ts` resources are set **simple export (`export default`) as locale messages object, as default**.
283
290
 
284
291
  ```js
285
292
  export default {
@@ -288,7 +295,31 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
288
295
  }
289
296
  ```
290
297
 
291
- If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
298
+ If you need to use programmatically dynamic resource construction, you would be enable `allowDynamic` option. about details, see the section.
299
+
300
+ > ⚠️ NOTE:
301
+ If you use the `js` and `ts` resources formats, set the paths, so your application code is not targeted. We recommend that resources be isolated from the application code.
302
+
303
+ ### `allowDynamic`
304
+
305
+ - **Type:** `boolean`
306
+ - **Default:** `false`
307
+
308
+ Whether or not programmatically dynamic resource construction for `js` or `ts` resource format.
309
+
310
+ In this case, you need to export the function with `export default` and construct the resource with the function:
311
+
312
+ ```js
313
+ import resources from './locales/all.json'
314
+
315
+ export default async function loadResource(url) {
316
+ const res = await import(url).then(r => r.default || r)
317
+ return { ...resources, ...res }
318
+ }
319
+ ```
320
+
321
+ 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).
322
+
292
323
 
293
324
  ### `runtimeOnly`
294
325
 
package/lib/index.cjs CHANGED
@@ -135,6 +135,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
135
135
  const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
136
136
  const esm = shared.isBoolean(options.esm) ? options.esm : true;
137
137
  debug("esm", esm);
138
+ const allowDynamic = !!options.allowDynamic;
138
139
  let isProduction = false;
139
140
  let sourceMap = false;
140
141
  const vueI18nAliasName = getVueI18nAliasName();
@@ -251,6 +252,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
251
252
  inSourceMap,
252
253
  isGlobal: globalSFCScope,
253
254
  useClassComponent,
255
+ allowDynamic,
254
256
  bridge,
255
257
  exportESM: esm,
256
258
  forceStringify
@@ -410,6 +412,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
410
412
  inSourceMap,
411
413
  isGlobal: globalSFCScope,
412
414
  useClassComponent,
415
+ allowDynamic,
413
416
  bridge,
414
417
  exportESM: esm,
415
418
  forceStringify
@@ -583,7 +586,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
583
586
  isGlobal = false,
584
587
  bridge = false,
585
588
  exportESM = true,
586
- useClassComponent = false
589
+ useClassComponent = false,
590
+ allowDynamic = false
587
591
  }) {
588
592
  const mode = isProduction ? "production" : "development";
589
593
  const baseOptions = {
@@ -592,6 +596,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
592
596
  inSourceMap,
593
597
  forceStringify,
594
598
  useClassComponent,
599
+ allowDynamic,
595
600
  bridge,
596
601
  exportESM,
597
602
  env: mode,
package/lib/index.mjs CHANGED
@@ -131,6 +131,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
131
131
  const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
132
132
  const esm = isBoolean(options.esm) ? options.esm : true;
133
133
  debug("esm", esm);
134
+ const allowDynamic = !!options.allowDynamic;
134
135
  let isProduction = false;
135
136
  let sourceMap = false;
136
137
  const vueI18nAliasName = getVueI18nAliasName();
@@ -247,6 +248,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
247
248
  inSourceMap,
248
249
  isGlobal: globalSFCScope,
249
250
  useClassComponent,
251
+ allowDynamic,
250
252
  bridge,
251
253
  exportESM: esm,
252
254
  forceStringify
@@ -406,6 +408,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
406
408
  inSourceMap,
407
409
  isGlobal: globalSFCScope,
408
410
  useClassComponent,
411
+ allowDynamic,
409
412
  bridge,
410
413
  exportESM: esm,
411
414
  forceStringify
@@ -579,7 +582,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
579
582
  isGlobal = false,
580
583
  bridge = false,
581
584
  exportESM = true,
582
- useClassComponent = false
585
+ useClassComponent = false,
586
+ allowDynamic = false
583
587
  }) {
584
588
  const mode = isProduction ? "production" : "development";
585
589
  const baseOptions = {
@@ -588,6 +592,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
588
592
  inSourceMap,
589
593
  forceStringify,
590
594
  useClassComponent,
595
+ allowDynamic,
591
596
  bridge,
592
597
  exportESM,
593
598
  env: mode,
package/lib/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
2
2
  interface PluginOptions {
3
3
  include?: string | string[];
4
+ allowDynamic?: boolean;
4
5
  runtimeOnly?: boolean;
5
6
  compositionOnly?: boolean;
6
7
  fullInstall?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
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": "^5.0.0",
29
+ "@intlify/bundle-utils": "^5.3.1",
30
30
  "@intlify/shared": "next",
31
31
  "@rollup/pluginutils": "^5.0.2",
32
32
  "@vue/compiler-sfc": "^3.2.47",