@intlify/unplugin-vue-i18n 11.1.0 → 11.1.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/lib/index.cjs +35 -46
- package/lib/index.mjs +35 -46
- package/package.json +6 -2
package/lib/index.cjs
CHANGED
|
@@ -204,19 +204,6 @@ function resourcePlugin({
|
|
|
204
204
|
escapeHtml,
|
|
205
205
|
transformI18nBlock
|
|
206
206
|
}, meta, collector) {
|
|
207
|
-
let viteModule = null;
|
|
208
|
-
async function getViteModule() {
|
|
209
|
-
if (viteModule != null) {
|
|
210
|
-
return viteModule;
|
|
211
|
-
}
|
|
212
|
-
try {
|
|
213
|
-
viteModule = await import('vite');
|
|
214
|
-
} catch (e) {
|
|
215
|
-
error(`vite not found, please install vite.`, e.message);
|
|
216
|
-
throw e;
|
|
217
|
-
}
|
|
218
|
-
return viteModule;
|
|
219
|
-
}
|
|
220
207
|
function resolveIncludeExclude() {
|
|
221
208
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
222
209
|
return include ? [[...include, customBlockInclude], exclude] : [[RE_RESOURCE_FORMAT, customBlockInclude], exclude];
|
|
@@ -233,15 +220,12 @@ function resourcePlugin({
|
|
|
233
220
|
if (meta.framework == "webpack") {
|
|
234
221
|
debug$3("Using filter for webpack");
|
|
235
222
|
_filter = pluginutils.createFilter(...resolveIncludeExclude());
|
|
223
|
+
} else if (hasViteJsonPlugin) {
|
|
224
|
+
debug$3("Using filter for rollup-vite");
|
|
225
|
+
_filter = pluginutils.createFilter(...resolveIncludeExcludeForLegacy());
|
|
236
226
|
} else {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
debug$3("Using filter for rolldown-vite");
|
|
240
|
-
_filter = pluginutils.createFilter(...resolveIncludeExclude());
|
|
241
|
-
} else {
|
|
242
|
-
debug$3("Using filter for rollup-vite");
|
|
243
|
-
_filter = pluginutils.createFilter(...resolveIncludeExcludeForLegacy());
|
|
244
|
-
}
|
|
227
|
+
debug$3("Using filter for rolldown-vite");
|
|
228
|
+
_filter = pluginutils.createFilter(...resolveIncludeExclude());
|
|
245
229
|
}
|
|
246
230
|
return _filter;
|
|
247
231
|
}
|
|
@@ -250,6 +234,7 @@ function resourcePlugin({
|
|
|
250
234
|
};
|
|
251
235
|
let isProduction = false;
|
|
252
236
|
let sourceMap = false;
|
|
237
|
+
let hasViteJsonPlugin = false;
|
|
253
238
|
const vueI18nAliasName = module;
|
|
254
239
|
debug$3(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
255
240
|
let vuePlugin = null;
|
|
@@ -299,28 +284,28 @@ function resourcePlugin({
|
|
|
299
284
|
isProduction = config.isProduction;
|
|
300
285
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
301
286
|
debug$3(`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
if (
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
const { query } = parseVueRequest(id);
|
|
314
|
-
if (query.vue) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
debug$3("org json plugin");
|
|
318
|
-
return orgTransform.apply(this, [code, id]);
|
|
287
|
+
const jsonPlugin = getVitePlugin(config, "vite:json");
|
|
288
|
+
hasViteJsonPlugin = !!jsonPlugin;
|
|
289
|
+
if (jsonPlugin && jsonPlugin.transform) {
|
|
290
|
+
const transform = jsonPlugin.transform;
|
|
291
|
+
const isObjectHook = typeof transform !== "function" && "handler" in transform;
|
|
292
|
+
const orgTransform = isObjectHook ? transform.handler : transform;
|
|
293
|
+
async function overrideJson(code, id) {
|
|
294
|
+
const filter = await getFilter();
|
|
295
|
+
if (!/\.json$/.test(id) || filter(id)) {
|
|
296
|
+
return;
|
|
319
297
|
}
|
|
320
|
-
|
|
321
|
-
if (
|
|
322
|
-
|
|
298
|
+
const { query } = parseVueRequest(id);
|
|
299
|
+
if (query.vue) {
|
|
300
|
+
return;
|
|
323
301
|
}
|
|
302
|
+
debug$3("org json plugin");
|
|
303
|
+
return orgTransform.apply(this, [code, id]);
|
|
304
|
+
}
|
|
305
|
+
if (isObjectHook) {
|
|
306
|
+
transform.handler = overrideJson;
|
|
307
|
+
} else {
|
|
308
|
+
jsonPlugin.transform = overrideJson;
|
|
324
309
|
}
|
|
325
310
|
}
|
|
326
311
|
},
|
|
@@ -458,7 +443,7 @@ function resourcePlugin({
|
|
|
458
443
|
langInfo = defaultSFCLang;
|
|
459
444
|
}
|
|
460
445
|
debug$3("langInfo", langInfo);
|
|
461
|
-
const generate =
|
|
446
|
+
const generate = getGenerator(langInfo, bundleUtils.generateYAML);
|
|
462
447
|
const isGlobalBlock = globalSFCScope || !!query.global;
|
|
463
448
|
const parseOptions = getOptions(
|
|
464
449
|
filename,
|
|
@@ -468,6 +453,7 @@ function resourcePlugin({
|
|
|
468
453
|
{
|
|
469
454
|
inSourceMap,
|
|
470
455
|
isGlobal: globalSFCScope,
|
|
456
|
+
allowDynamic,
|
|
471
457
|
jit: true,
|
|
472
458
|
strictMessage,
|
|
473
459
|
escapeHtml,
|
|
@@ -493,7 +479,10 @@ function resourcePlugin({
|
|
|
493
479
|
warn("transformI18nBlock should return a string");
|
|
494
480
|
}
|
|
495
481
|
}
|
|
496
|
-
|
|
482
|
+
if (/\.?[cm]?[jt]s$/.test(langInfo)) {
|
|
483
|
+
source = `export default ${source.replace(/^[\s;]+/, "")}`;
|
|
484
|
+
}
|
|
485
|
+
const { code: generatedCode, map } = await generate(source, parseOptions);
|
|
497
486
|
debug$3("generated code", generatedCode);
|
|
498
487
|
debug$3("sourcemap", map, sourceMap);
|
|
499
488
|
if (code === generatedCode) return;
|
|
@@ -513,13 +502,13 @@ function getGenerator(ext, fallback = bundleUtils.generateJSON) {
|
|
|
513
502
|
if (/\.?json5?$/.test(ext)) {
|
|
514
503
|
return bundleUtils.generateJSON;
|
|
515
504
|
}
|
|
516
|
-
if (
|
|
505
|
+
if (/\.?ya?ml$/.test(ext)) {
|
|
517
506
|
return bundleUtils.generateYAML;
|
|
518
507
|
}
|
|
519
|
-
if (
|
|
508
|
+
if (/\.?[cm]?js$/.test(ext)) {
|
|
520
509
|
return bundleUtils.generateJavaScript;
|
|
521
510
|
}
|
|
522
|
-
if (
|
|
511
|
+
if (/\.?[cm]?ts$/.test(ext)) {
|
|
523
512
|
return bundleUtils.generateTypescript;
|
|
524
513
|
}
|
|
525
514
|
return fallback;
|
package/lib/index.mjs
CHANGED
|
@@ -192,19 +192,6 @@ function resourcePlugin({
|
|
|
192
192
|
escapeHtml,
|
|
193
193
|
transformI18nBlock
|
|
194
194
|
}, meta, collector) {
|
|
195
|
-
let viteModule = null;
|
|
196
|
-
async function getViteModule() {
|
|
197
|
-
if (viteModule != null) {
|
|
198
|
-
return viteModule;
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
viteModule = await import('vite');
|
|
202
|
-
} catch (e) {
|
|
203
|
-
error(`vite not found, please install vite.`, e.message);
|
|
204
|
-
throw e;
|
|
205
|
-
}
|
|
206
|
-
return viteModule;
|
|
207
|
-
}
|
|
208
195
|
function resolveIncludeExclude() {
|
|
209
196
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
210
197
|
return include ? [[...include, customBlockInclude], exclude] : [[RE_RESOURCE_FORMAT, customBlockInclude], exclude];
|
|
@@ -221,15 +208,12 @@ function resourcePlugin({
|
|
|
221
208
|
if (meta.framework == "webpack") {
|
|
222
209
|
debug$3("Using filter for webpack");
|
|
223
210
|
_filter = createFilter(...resolveIncludeExclude());
|
|
211
|
+
} else if (hasViteJsonPlugin) {
|
|
212
|
+
debug$3("Using filter for rollup-vite");
|
|
213
|
+
_filter = createFilter(...resolveIncludeExcludeForLegacy());
|
|
224
214
|
} else {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
debug$3("Using filter for rolldown-vite");
|
|
228
|
-
_filter = createFilter(...resolveIncludeExclude());
|
|
229
|
-
} else {
|
|
230
|
-
debug$3("Using filter for rollup-vite");
|
|
231
|
-
_filter = createFilter(...resolveIncludeExcludeForLegacy());
|
|
232
|
-
}
|
|
215
|
+
debug$3("Using filter for rolldown-vite");
|
|
216
|
+
_filter = createFilter(...resolveIncludeExclude());
|
|
233
217
|
}
|
|
234
218
|
return _filter;
|
|
235
219
|
}
|
|
@@ -238,6 +222,7 @@ function resourcePlugin({
|
|
|
238
222
|
};
|
|
239
223
|
let isProduction = false;
|
|
240
224
|
let sourceMap = false;
|
|
225
|
+
let hasViteJsonPlugin = false;
|
|
241
226
|
const vueI18nAliasName = module;
|
|
242
227
|
debug$3(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
243
228
|
let vuePlugin = null;
|
|
@@ -287,28 +272,28 @@ function resourcePlugin({
|
|
|
287
272
|
isProduction = config.isProduction;
|
|
288
273
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
289
274
|
debug$3(`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
if (
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
const { query } = parseVueRequest(id);
|
|
302
|
-
if (query.vue) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
debug$3("org json plugin");
|
|
306
|
-
return orgTransform.apply(this, [code, id]);
|
|
275
|
+
const jsonPlugin = getVitePlugin(config, "vite:json");
|
|
276
|
+
hasViteJsonPlugin = !!jsonPlugin;
|
|
277
|
+
if (jsonPlugin && jsonPlugin.transform) {
|
|
278
|
+
const transform = jsonPlugin.transform;
|
|
279
|
+
const isObjectHook = typeof transform !== "function" && "handler" in transform;
|
|
280
|
+
const orgTransform = isObjectHook ? transform.handler : transform;
|
|
281
|
+
async function overrideJson(code, id) {
|
|
282
|
+
const filter = await getFilter();
|
|
283
|
+
if (!/\.json$/.test(id) || filter(id)) {
|
|
284
|
+
return;
|
|
307
285
|
}
|
|
308
|
-
|
|
309
|
-
if (
|
|
310
|
-
|
|
286
|
+
const { query } = parseVueRequest(id);
|
|
287
|
+
if (query.vue) {
|
|
288
|
+
return;
|
|
311
289
|
}
|
|
290
|
+
debug$3("org json plugin");
|
|
291
|
+
return orgTransform.apply(this, [code, id]);
|
|
292
|
+
}
|
|
293
|
+
if (isObjectHook) {
|
|
294
|
+
transform.handler = overrideJson;
|
|
295
|
+
} else {
|
|
296
|
+
jsonPlugin.transform = overrideJson;
|
|
312
297
|
}
|
|
313
298
|
}
|
|
314
299
|
},
|
|
@@ -446,7 +431,7 @@ function resourcePlugin({
|
|
|
446
431
|
langInfo = defaultSFCLang;
|
|
447
432
|
}
|
|
448
433
|
debug$3("langInfo", langInfo);
|
|
449
|
-
const generate =
|
|
434
|
+
const generate = getGenerator(langInfo, generateYAML);
|
|
450
435
|
const isGlobalBlock = globalSFCScope || !!query.global;
|
|
451
436
|
const parseOptions = getOptions(
|
|
452
437
|
filename,
|
|
@@ -456,6 +441,7 @@ function resourcePlugin({
|
|
|
456
441
|
{
|
|
457
442
|
inSourceMap,
|
|
458
443
|
isGlobal: globalSFCScope,
|
|
444
|
+
allowDynamic,
|
|
459
445
|
jit: true,
|
|
460
446
|
strictMessage,
|
|
461
447
|
escapeHtml,
|
|
@@ -481,7 +467,10 @@ function resourcePlugin({
|
|
|
481
467
|
warn("transformI18nBlock should return a string");
|
|
482
468
|
}
|
|
483
469
|
}
|
|
484
|
-
|
|
470
|
+
if (/\.?[cm]?[jt]s$/.test(langInfo)) {
|
|
471
|
+
source = `export default ${source.replace(/^[\s;]+/, "")}`;
|
|
472
|
+
}
|
|
473
|
+
const { code: generatedCode, map } = await generate(source, parseOptions);
|
|
485
474
|
debug$3("generated code", generatedCode);
|
|
486
475
|
debug$3("sourcemap", map, sourceMap);
|
|
487
476
|
if (code === generatedCode) return;
|
|
@@ -501,13 +490,13 @@ function getGenerator(ext, fallback = generateJSON) {
|
|
|
501
490
|
if (/\.?json5?$/.test(ext)) {
|
|
502
491
|
return generateJSON;
|
|
503
492
|
}
|
|
504
|
-
if (
|
|
493
|
+
if (/\.?ya?ml$/.test(ext)) {
|
|
505
494
|
return generateYAML;
|
|
506
495
|
}
|
|
507
|
-
if (
|
|
496
|
+
if (/\.?[cm]?js$/.test(ext)) {
|
|
508
497
|
return generateJavaScript;
|
|
509
498
|
}
|
|
510
|
-
if (
|
|
499
|
+
if (/\.?[cm]?ts$/.test(ext)) {
|
|
511
500
|
return generateTypescript;
|
|
512
501
|
}
|
|
513
502
|
return fallback;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.2",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"petite-vue-i18n": "*",
|
|
14
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
14
15
|
"vue": "^3.2.25",
|
|
15
16
|
"vue-i18n": "*"
|
|
16
17
|
},
|
|
@@ -18,6 +19,9 @@
|
|
|
18
19
|
"petite-vue-i18n": {
|
|
19
20
|
"optional": true
|
|
20
21
|
},
|
|
22
|
+
"vite": {
|
|
23
|
+
"optional": true
|
|
24
|
+
},
|
|
21
25
|
"vue-i18n": {
|
|
22
26
|
"optional": true
|
|
23
27
|
}
|
|
@@ -35,7 +39,7 @@
|
|
|
35
39
|
"picocolors": "^1.0.0",
|
|
36
40
|
"unplugin": "^2.3.4",
|
|
37
41
|
"vue": "^3.5.21",
|
|
38
|
-
"@intlify/bundle-utils": "11.1.
|
|
42
|
+
"@intlify/bundle-utils": "11.1.2"
|
|
39
43
|
},
|
|
40
44
|
"devDependencies": {
|
|
41
45
|
"@intlify/core-base": "next",
|