@intlify/unplugin-vue-i18n 0.9.0 → 0.9.2
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 +34 -3
- package/lib/index.cjs +6 -2
- package/lib/index.mjs +6 -2
- package/lib/types.d.ts +1 -0
- package/package.json +2 -2
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
@@ -263,7 +265,6 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
263
265
|
bridge ? createBridgeCodeGenerator(_code, query) : void 0
|
|
264
266
|
);
|
|
265
267
|
debug("generated code", generatedCode);
|
|
266
|
-
console.log("generated code", generatedCode);
|
|
267
268
|
debug("sourcemap", map, sourceMap);
|
|
268
269
|
if (_code === generatedCode)
|
|
269
270
|
return;
|
|
@@ -411,6 +412,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
411
412
|
inSourceMap,
|
|
412
413
|
isGlobal: globalSFCScope,
|
|
413
414
|
useClassComponent,
|
|
415
|
+
allowDynamic,
|
|
414
416
|
bridge,
|
|
415
417
|
exportESM: esm,
|
|
416
418
|
forceStringify
|
|
@@ -584,7 +586,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
584
586
|
isGlobal = false,
|
|
585
587
|
bridge = false,
|
|
586
588
|
exportESM = true,
|
|
587
|
-
useClassComponent = false
|
|
589
|
+
useClassComponent = false,
|
|
590
|
+
allowDynamic = false
|
|
588
591
|
}) {
|
|
589
592
|
const mode = isProduction ? "production" : "development";
|
|
590
593
|
const baseOptions = {
|
|
@@ -593,6 +596,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
593
596
|
inSourceMap,
|
|
594
597
|
forceStringify,
|
|
595
598
|
useClassComponent,
|
|
599
|
+
allowDynamic,
|
|
596
600
|
bridge,
|
|
597
601
|
exportESM,
|
|
598
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
|
|
@@ -259,7 +261,6 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
259
261
|
bridge ? createBridgeCodeGenerator(_code, query) : void 0
|
|
260
262
|
);
|
|
261
263
|
debug("generated code", generatedCode);
|
|
262
|
-
console.log("generated code", generatedCode);
|
|
263
264
|
debug("sourcemap", map, sourceMap);
|
|
264
265
|
if (_code === generatedCode)
|
|
265
266
|
return;
|
|
@@ -407,6 +408,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
407
408
|
inSourceMap,
|
|
408
409
|
isGlobal: globalSFCScope,
|
|
409
410
|
useClassComponent,
|
|
411
|
+
allowDynamic,
|
|
410
412
|
bridge,
|
|
411
413
|
exportESM: esm,
|
|
412
414
|
forceStringify
|
|
@@ -580,7 +582,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
580
582
|
isGlobal = false,
|
|
581
583
|
bridge = false,
|
|
582
584
|
exportESM = true,
|
|
583
|
-
useClassComponent = false
|
|
585
|
+
useClassComponent = false,
|
|
586
|
+
allowDynamic = false
|
|
584
587
|
}) {
|
|
585
588
|
const mode = isProduction ? "production" : "development";
|
|
586
589
|
const baseOptions = {
|
|
@@ -589,6 +592,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
589
592
|
inSourceMap,
|
|
590
593
|
forceStringify,
|
|
591
594
|
useClassComponent,
|
|
595
|
+
allowDynamic,
|
|
592
596
|
bridge,
|
|
593
597
|
exportESM,
|
|
594
598
|
env: mode,
|
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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.
|
|
29
|
+
"@intlify/bundle-utils": "^5.1.2",
|
|
30
30
|
"@intlify/shared": "next",
|
|
31
31
|
"@rollup/pluginutils": "^5.0.2",
|
|
32
32
|
"@vue/compiler-sfc": "^3.2.47",
|