@intlify/unplugin-vue-i18n 6.0.3 → 7.0.0-beta.1
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 +61 -28
- package/lib/index.cjs +103 -56
- package/lib/index.mjs +103 -56
- package/lib/rspack.cjs +22 -0
- package/lib/rspack.d.cts +6 -0
- package/lib/rspack.d.mts +6 -0
- package/lib/rspack.d.ts +6 -0
- package/lib/rspack.mjs +20 -0
- package/lib/types.d.cts +0 -1
- package/lib/types.d.mts +0 -1
- package/lib/types.d.ts +0 -1
- package/package.json +9 -4
- package/rspack.d.ts +1 -0
package/README.md
CHANGED
|
@@ -59,6 +59,25 @@ module.exports = {
|
|
|
59
59
|
|
|
60
60
|
<br></details>
|
|
61
61
|
|
|
62
|
+
<details>
|
|
63
|
+
<summary>Rspack</summary><br>
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/rspack')
|
|
67
|
+
|
|
68
|
+
// rspack.config.js
|
|
69
|
+
module.exports = {
|
|
70
|
+
/* ... */
|
|
71
|
+
plugins: [
|
|
72
|
+
VueI18nPlugin({
|
|
73
|
+
/* options */
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
<br></details>
|
|
80
|
+
|
|
62
81
|
<details>
|
|
63
82
|
<summary>Nuxt</summary><br>
|
|
64
83
|
|
|
@@ -280,11 +299,17 @@ About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimi
|
|
|
280
299
|
|
|
281
300
|
If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
|
|
282
301
|
|
|
283
|
-
> [!WARNING]
|
|
302
|
+
> [!WARNING]
|
|
303
|
+
>
|
|
304
|
+
> `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
305
|
|
|
285
|
-
> [!WARNING]
|
|
306
|
+
> [!WARNING]
|
|
307
|
+
>
|
|
308
|
+
> `yaml` resources don't support multi documentation with `|`, alias with `&` and `*`, tags with `! `, `@`, etc. Only simple data structures.
|
|
286
309
|
|
|
287
|
-
> [!WARNING]
|
|
310
|
+
> [!WARNING]
|
|
311
|
+
>
|
|
312
|
+
> `js` and `ts` resources are set **simple export (`export default`) as locale messages object, as default**.
|
|
288
313
|
|
|
289
314
|
```js
|
|
290
315
|
export default {
|
|
@@ -303,22 +328,22 @@ If you need to use programmatically dynamic resource construction, you would be
|
|
|
303
328
|
- **Type:** `string`
|
|
304
329
|
- **Default:** `'vue-i18n'`
|
|
305
330
|
|
|
306
|
-
|
|
307
|
-
|
|
331
|
+
> [!NOTE]
|
|
332
|
+
> This options is supported from v5.1.0, and works with vue-i18n v10 and later.
|
|
308
333
|
|
|
309
|
-
|
|
334
|
+
Bundle target vue-i18n module. You can specify either `‘vue-i18n’` or `‘petite-vue-i18n’`.
|
|
310
335
|
|
|
311
|
-
|
|
336
|
+
The default is `'vue-i18n'`, and the following installed in node_modules will be bundled.
|
|
312
337
|
|
|
313
|
-
|
|
314
|
-
|
|
338
|
+
- development: `vue-i18n.esm-bundler.js`
|
|
339
|
+
- production: `vue-i18n.runtime.esm-bundler.js`
|
|
315
340
|
|
|
316
|
-
|
|
341
|
+
In the case of `‘petite-vue-i18n’`, the following installed in node_modules will be bundled.
|
|
317
342
|
|
|
318
|
-
|
|
319
|
-
|
|
343
|
+
- development: `petite-vue-i18n.esm-bundler.js`
|
|
344
|
+
- production: `petite-vue-i18n.runtime.esm-bundler.js`
|
|
320
345
|
|
|
321
|
-
|
|
346
|
+
If you are using petite-vue-i18n, you will need to set this value.
|
|
322
347
|
|
|
323
348
|
### `strictMessage`
|
|
324
349
|
|
|
@@ -360,7 +385,7 @@ If you need to use programmatically dynamic resource construction, you would be
|
|
|
360
385
|
}
|
|
361
386
|
```
|
|
362
387
|
|
|
363
|
-
If you fetch some resources from the backend, the data **must be pre-compiled** for production.
|
|
388
|
+
If you fetch some resources from the backend, the data **must be pre-compiled** for production. example is [here](https://github.com/intlify/vue-i18n-next/tree/master/examples/backend).
|
|
364
389
|
|
|
365
390
|
### `jitCompilation`
|
|
366
391
|
|
|
@@ -368,15 +393,15 @@ If you need to use programmatically dynamic resource construction, you would be
|
|
|
368
393
|
- **Default:** `true`
|
|
369
394
|
|
|
370
395
|
> [!IMPORTANT]
|
|
371
|
-
> 'jitCompilation' option is
|
|
396
|
+
> 'jitCompilation' option is deprecated in v5.
|
|
372
397
|
> This option will be supported with vue-i18n until v9 latest version.
|
|
373
398
|
|
|
374
|
-
Whether locale
|
|
399
|
+
Whether locale messages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.
|
|
375
400
|
|
|
376
|
-
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
|
|
401
|
+
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 messages with programmatic.
|
|
377
402
|
|
|
378
403
|
> [!WARNING]
|
|
379
|
-
> Enabling JIT compilation causes the message compiler to generate AST objects for locale
|
|
404
|
+
> Enabling JIT compilation causes the message compiler to generate AST objects for locale messages 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.
|
|
380
405
|
|
|
381
406
|
About JIT compilation, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#jit-compilation)
|
|
382
407
|
|
|
@@ -418,6 +443,7 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
418
443
|
```
|
|
419
444
|
- vite config: `resolve.alias`
|
|
420
445
|
- webpack config: `resolve.alias`
|
|
446
|
+
- rspack config: `resolve.alias`
|
|
421
447
|
```
|
|
422
448
|
|
|
423
449
|
If `false` is specified, Vue I18n (vue-i18n) package.json `module` field will be used.
|
|
@@ -433,6 +459,9 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
433
459
|
|
|
434
460
|
For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
|
|
435
461
|
|
|
462
|
+
> [!CAUTION]
|
|
463
|
+
> This option will be removed in v7
|
|
464
|
+
|
|
436
465
|
### `fullInstall`
|
|
437
466
|
|
|
438
467
|
- **Type:** `boolean`
|
|
@@ -440,7 +469,7 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
440
469
|
|
|
441
470
|
Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.
|
|
442
471
|
|
|
443
|
-
If `false` is specified, **
|
|
472
|
+
If `false` is specified, **build-in components and directive will not be installed in vue and will be tree-shaken.**
|
|
444
473
|
|
|
445
474
|
For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
|
|
446
475
|
|
|
@@ -597,8 +626,10 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
597
626
|
|
|
598
627
|
This option that to use i18n custom blocks in `vue-class-component`.
|
|
599
628
|
|
|
600
|
-
|
|
601
|
-
|
|
629
|
+
> [!IMPORTANT]
|
|
630
|
+
>
|
|
631
|
+
> `useClassComponent` option is deprecated in v5.
|
|
632
|
+
> This option will be supported with vue-i18n until v9 latest version.
|
|
602
633
|
|
|
603
634
|
### `onlyLocales`
|
|
604
635
|
|
|
@@ -614,10 +645,12 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
614
645
|
|
|
615
646
|
Whether to use the import name of `petite-vue-i18n` with the same import name as vue-i18n (`import { xxx } from 'vue-i18n'`).
|
|
616
647
|
|
|
617
|
-
This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive
|
|
648
|
+
This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhancement.
|
|
618
649
|
|
|
619
|
-
|
|
620
|
-
|
|
650
|
+
> [!IMPORTANT]
|
|
651
|
+
>
|
|
652
|
+
> `useVueI18nImportName` option is deprecated in v5.
|
|
653
|
+
> This option will be supported with vue-i18n until v9 latest version.
|
|
621
654
|
|
|
622
655
|
### `optimizeTranslationDirective`
|
|
623
656
|
|
|
@@ -628,8 +661,8 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
628
661
|
|
|
629
662
|
If you want to put it manually, you can specify the signature of the translation function as a string or a string array.
|
|
630
663
|
|
|
631
|
-
|
|
632
|
-
|
|
664
|
+
> [!WARNING]
|
|
665
|
+
> About for manually signature, see the details [vue-i18n-extensions API docs](https://github.com/intlify/vue-i18n-extensions/blob/next/docs/%40intlify/vue-i18n-extensions-api.md#translationsignatures) and [usecase from vue-i18n-extensions PR](https://github.com/intlify/vue-i18n-extensions/pull/217/files#diff-3fb9543f91e011d4b0dc9beff44082fe1a99c9eab70c1afab23c3c34352b7c38R121-R200)
|
|
633
666
|
|
|
634
667
|
### `transformI18nBlock`
|
|
635
668
|
|
|
@@ -681,8 +714,8 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
681
714
|
</i18n>
|
|
682
715
|
```
|
|
683
716
|
|
|
684
|
-
|
|
685
|
-
|
|
717
|
+
> [!IMPORTANT]
|
|
718
|
+
> The function **must** return a string or the build will fail.
|
|
686
719
|
|
|
687
720
|
## 📜 Changelog
|
|
688
721
|
|
package/lib/index.cjs
CHANGED
|
@@ -84,7 +84,6 @@ function resolveOptions(options) {
|
|
|
84
84
|
const globalSFCScope = !!options.globalSFCScope;
|
|
85
85
|
const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
86
86
|
const dropMessageCompiler = !!options.dropMessageCompiler;
|
|
87
|
-
const compositionOnly = moduleType === "vue-i18n" ? shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
88
87
|
const fullInstall = moduleType === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
89
88
|
const ssrBuild = !!options.ssr;
|
|
90
89
|
const allowDynamic = !!options.allowDynamic;
|
|
@@ -103,7 +102,6 @@ function resolveOptions(options) {
|
|
|
103
102
|
globalSFCScope,
|
|
104
103
|
runtimeOnly,
|
|
105
104
|
dropMessageCompiler,
|
|
106
|
-
compositionOnly,
|
|
107
105
|
fullInstall,
|
|
108
106
|
ssrBuild,
|
|
109
107
|
allowDynamic,
|
|
@@ -193,7 +191,6 @@ function resourcePlugin({
|
|
|
193
191
|
globalSFCScope,
|
|
194
192
|
runtimeOnly,
|
|
195
193
|
dropMessageCompiler,
|
|
196
|
-
compositionOnly,
|
|
197
194
|
fullInstall,
|
|
198
195
|
ssrBuild,
|
|
199
196
|
strictMessage,
|
|
@@ -203,7 +200,7 @@ function resourcePlugin({
|
|
|
203
200
|
}, meta) {
|
|
204
201
|
const filter = pluginutils.createFilter(include, exclude);
|
|
205
202
|
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
|
|
206
|
-
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.
|
|
203
|
+
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.js"}`;
|
|
207
204
|
};
|
|
208
205
|
let isProduction = false;
|
|
209
206
|
let sourceMap = false;
|
|
@@ -228,7 +225,6 @@ function resourcePlugin({
|
|
|
228
225
|
config() {
|
|
229
226
|
const defineConfig = {
|
|
230
227
|
define: {
|
|
231
|
-
__VUE_I18N_LEGACY_API__: !compositionOnly,
|
|
232
228
|
__VUE_I18N_FULL_INSTALL__: fullInstall,
|
|
233
229
|
__INTLIFY_DROP_MESSAGE_COMPILER__: dropMessageCompiler,
|
|
234
230
|
__VUE_I18N_PROD_DEVTOOLS__: false
|
|
@@ -335,47 +331,30 @@ function resourcePlugin({
|
|
|
335
331
|
}
|
|
336
332
|
},
|
|
337
333
|
webpack(compiler) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
334
|
+
webpackLike(compiler, "webpack", {
|
|
335
|
+
isProduction,
|
|
336
|
+
meta,
|
|
337
|
+
sourceMap,
|
|
338
|
+
getVueI18nAliasPath,
|
|
339
|
+
vueI18nAliasName,
|
|
340
|
+
ssrBuild,
|
|
341
|
+
runtimeOnly,
|
|
342
|
+
fullInstall,
|
|
343
|
+
filter
|
|
348
344
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
362
|
-
})
|
|
363
|
-
);
|
|
364
|
-
debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
365
|
-
debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
366
|
-
} else {
|
|
367
|
-
debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
|
|
368
|
-
}
|
|
345
|
+
},
|
|
346
|
+
rspack(compiler) {
|
|
347
|
+
webpackLike(compiler, "rspack", {
|
|
348
|
+
isProduction,
|
|
349
|
+
meta,
|
|
350
|
+
sourceMap,
|
|
351
|
+
getVueI18nAliasPath,
|
|
352
|
+
vueI18nAliasName,
|
|
353
|
+
ssrBuild,
|
|
354
|
+
runtimeOnly,
|
|
355
|
+
fullInstall,
|
|
356
|
+
filter
|
|
369
357
|
});
|
|
370
|
-
if (compiler.options.module) {
|
|
371
|
-
compiler.options.module.rules.push({
|
|
372
|
-
test: /\.(json5?|ya?ml)$/,
|
|
373
|
-
type: "javascript/auto",
|
|
374
|
-
include(resource) {
|
|
375
|
-
return filter(resource);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
358
|
},
|
|
380
359
|
resolveId(id, importer) {
|
|
381
360
|
debug$2("resolveId", id, importer);
|
|
@@ -383,6 +362,9 @@ function resourcePlugin({
|
|
|
383
362
|
return asVirtualId(id, meta.framework);
|
|
384
363
|
}
|
|
385
364
|
},
|
|
365
|
+
loadInclude(id) {
|
|
366
|
+
return INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework);
|
|
367
|
+
},
|
|
386
368
|
async load(id) {
|
|
387
369
|
debug$2("load", id);
|
|
388
370
|
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework) && include) {
|
|
@@ -514,34 +496,99 @@ function resourcePlugin({
|
|
|
514
496
|
function getGenerator(ext, defaultGen = bundleUtils.generateJSON) {
|
|
515
497
|
return /\.?json5?$/.test(ext) ? bundleUtils.generateJSON : /\.ya?ml$/.test(ext) ? bundleUtils.generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? bundleUtils.generateJavaScript : defaultGen;
|
|
516
498
|
}
|
|
499
|
+
function webpackLike(compiler, framework, {
|
|
500
|
+
isProduction,
|
|
501
|
+
sourceMap,
|
|
502
|
+
meta,
|
|
503
|
+
getVueI18nAliasPath,
|
|
504
|
+
vueI18nAliasName,
|
|
505
|
+
ssrBuild,
|
|
506
|
+
runtimeOnly,
|
|
507
|
+
fullInstall,
|
|
508
|
+
filter
|
|
509
|
+
}) {
|
|
510
|
+
isProduction = compiler.options.mode !== "development";
|
|
511
|
+
sourceMap = !!compiler.options.devtool;
|
|
512
|
+
debug$2(
|
|
513
|
+
`${framework}: isProduction = ${isProduction}, sourceMap = ${sourceMap}`
|
|
514
|
+
);
|
|
515
|
+
compiler.options.resolve = normalizeConfigResolveAlias(
|
|
516
|
+
compiler.options.resolve,
|
|
517
|
+
meta.framework
|
|
518
|
+
);
|
|
519
|
+
compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath({
|
|
520
|
+
ssr: ssrBuild,
|
|
521
|
+
runtimeOnly
|
|
522
|
+
});
|
|
523
|
+
debug$2(
|
|
524
|
+
`set ${vueI18nAliasName}: ${getVueI18nAliasPath({
|
|
525
|
+
ssr: ssrBuild,
|
|
526
|
+
runtimeOnly
|
|
527
|
+
})}`
|
|
528
|
+
);
|
|
529
|
+
const loader = framework === "webpack" ? loadWebpack : loadRspack;
|
|
530
|
+
loader().then((mod) => {
|
|
531
|
+
if (mod) {
|
|
532
|
+
compiler.options.plugins.push(
|
|
533
|
+
// @ts-expect-error type issue
|
|
534
|
+
new mod.DefinePlugin({
|
|
535
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
536
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
537
|
+
})
|
|
538
|
+
);
|
|
539
|
+
debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
540
|
+
} else {
|
|
541
|
+
debug$2(`ignore vue-i18n feature flags with ${framework}.DefinePlugin`);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
if (compiler.options.module) {
|
|
545
|
+
compiler.options.module.rules.push({
|
|
546
|
+
test: /\.(json5?|ya?ml)$/,
|
|
547
|
+
type: "javascript/auto",
|
|
548
|
+
include(resource) {
|
|
549
|
+
return filter(resource);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
517
554
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
518
555
|
if (resolve && resolve.alias) {
|
|
519
556
|
return resolve;
|
|
520
557
|
}
|
|
558
|
+
const webpackLike2 = framework === "webpack" || framework === "rspack";
|
|
521
559
|
if (!resolve) {
|
|
522
560
|
if (framework === "vite") {
|
|
523
561
|
return { alias: [] };
|
|
524
|
-
} else if (
|
|
562
|
+
} else if (webpackLike2) {
|
|
525
563
|
return { alias: {} };
|
|
526
564
|
}
|
|
527
565
|
} else if (!resolve.alias) {
|
|
528
566
|
if (framework === "vite") {
|
|
529
567
|
resolve.alias = [];
|
|
530
568
|
return resolve;
|
|
531
|
-
} else if (
|
|
569
|
+
} else if (webpackLike2) {
|
|
532
570
|
resolve.alias = {};
|
|
533
571
|
return resolve;
|
|
534
572
|
}
|
|
535
573
|
}
|
|
536
574
|
}
|
|
537
575
|
async function loadWebpack() {
|
|
538
|
-
let webpack = null;
|
|
539
576
|
try {
|
|
540
|
-
|
|
577
|
+
const mod = await import('webpack');
|
|
578
|
+
return mod.default || mod;
|
|
541
579
|
} catch (_e) {
|
|
542
580
|
warn(`webpack not found, please install webpack.`);
|
|
543
581
|
}
|
|
544
|
-
return
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
async function loadRspack() {
|
|
585
|
+
try {
|
|
586
|
+
const { rspack } = await import('@rspack/core');
|
|
587
|
+
return rspack;
|
|
588
|
+
} catch (_e) {
|
|
589
|
+
warn(`rspack not found, please install rspack.`);
|
|
590
|
+
}
|
|
591
|
+
return null;
|
|
545
592
|
}
|
|
546
593
|
async function generateBundleResources(resources, isProduction, {
|
|
547
594
|
forceStringify = false,
|
|
@@ -603,9 +650,9 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
|
|
|
603
650
|
if (!shared.isNumber(index)) {
|
|
604
651
|
raiseError(`unexpected index: ${index}`);
|
|
605
652
|
}
|
|
606
|
-
if (framework === "webpack") {
|
|
653
|
+
if (framework === "webpack" || framework === "rspack") {
|
|
607
654
|
if (issuerPath) {
|
|
608
|
-
debug$2(`getCode (
|
|
655
|
+
debug$2(`getCode (${framework}) ${index} via issuerPath`, issuerPath);
|
|
609
656
|
return await getRaw(filename);
|
|
610
657
|
} else {
|
|
611
658
|
const result = parser(await getRaw(filename), {
|
|
@@ -615,7 +662,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
|
|
|
615
662
|
const block = result.descriptor.customBlocks[index];
|
|
616
663
|
if (block) {
|
|
617
664
|
const code = block.src ? await getRaw(block.src) : block.content;
|
|
618
|
-
debug$2(`getCode (
|
|
665
|
+
debug$2(`getCode (${framework}) ${index} from SFC`, code);
|
|
619
666
|
return code;
|
|
620
667
|
} else {
|
|
621
668
|
return source;
|
|
@@ -974,17 +1021,17 @@ function resolveIdentifier(localVariables, returnVariable) {
|
|
|
974
1021
|
const debug = createDebug__default(resolveNamespace("root"));
|
|
975
1022
|
const unpluginFactory = (options = {}, meta) => {
|
|
976
1023
|
debug("meta framework", meta.framework);
|
|
977
|
-
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
978
|
-
raiseError(`This plugin is supported 'vite' and '
|
|
1024
|
+
if (!["vite", "webpack", "rspack"].includes(meta.framework)) {
|
|
1025
|
+
raiseError(`This plugin is supported 'vite', 'webpack' and 'rspack' only`);
|
|
979
1026
|
}
|
|
980
1027
|
debug("plugin options (resolving):", options);
|
|
981
1028
|
const resolvedOptions = resolveOptions(options);
|
|
982
1029
|
debug("plugin options (resolved):", resolvedOptions);
|
|
983
1030
|
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
984
1031
|
if (resolvedOptions.optimizeTranslationDirective) {
|
|
985
|
-
if (meta.framework === "webpack") {
|
|
1032
|
+
if (meta.framework === "webpack" || meta.framework === "rspack") {
|
|
986
1033
|
raiseError(
|
|
987
|
-
`The 'optimizeTranslationDirective' option still is not supported for
|
|
1034
|
+
`The 'optimizeTranslationDirective' option still is not supported for ${meta.framework}.
|
|
988
1035
|
We are waiting for your Pull Request \u{1F642}.`
|
|
989
1036
|
);
|
|
990
1037
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -72,7 +72,6 @@ function resolveOptions(options) {
|
|
|
72
72
|
const globalSFCScope = !!options.globalSFCScope;
|
|
73
73
|
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
74
74
|
const dropMessageCompiler = !!options.dropMessageCompiler;
|
|
75
|
-
const compositionOnly = moduleType === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
76
75
|
const fullInstall = moduleType === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
77
76
|
const ssrBuild = !!options.ssr;
|
|
78
77
|
const allowDynamic = !!options.allowDynamic;
|
|
@@ -91,7 +90,6 @@ function resolveOptions(options) {
|
|
|
91
90
|
globalSFCScope,
|
|
92
91
|
runtimeOnly,
|
|
93
92
|
dropMessageCompiler,
|
|
94
|
-
compositionOnly,
|
|
95
93
|
fullInstall,
|
|
96
94
|
ssrBuild,
|
|
97
95
|
allowDynamic,
|
|
@@ -181,7 +179,6 @@ function resourcePlugin({
|
|
|
181
179
|
globalSFCScope,
|
|
182
180
|
runtimeOnly,
|
|
183
181
|
dropMessageCompiler,
|
|
184
|
-
compositionOnly,
|
|
185
182
|
fullInstall,
|
|
186
183
|
ssrBuild,
|
|
187
184
|
strictMessage,
|
|
@@ -191,7 +188,7 @@ function resourcePlugin({
|
|
|
191
188
|
}, meta) {
|
|
192
189
|
const filter = createFilter(include, exclude);
|
|
193
190
|
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
|
|
194
|
-
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.
|
|
191
|
+
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.js"}`;
|
|
195
192
|
};
|
|
196
193
|
let isProduction = false;
|
|
197
194
|
let sourceMap = false;
|
|
@@ -216,7 +213,6 @@ function resourcePlugin({
|
|
|
216
213
|
config() {
|
|
217
214
|
const defineConfig = {
|
|
218
215
|
define: {
|
|
219
|
-
__VUE_I18N_LEGACY_API__: !compositionOnly,
|
|
220
216
|
__VUE_I18N_FULL_INSTALL__: fullInstall,
|
|
221
217
|
__INTLIFY_DROP_MESSAGE_COMPILER__: dropMessageCompiler,
|
|
222
218
|
__VUE_I18N_PROD_DEVTOOLS__: false
|
|
@@ -323,47 +319,30 @@ function resourcePlugin({
|
|
|
323
319
|
}
|
|
324
320
|
},
|
|
325
321
|
webpack(compiler) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
322
|
+
webpackLike(compiler, "webpack", {
|
|
323
|
+
isProduction,
|
|
324
|
+
meta,
|
|
325
|
+
sourceMap,
|
|
326
|
+
getVueI18nAliasPath,
|
|
327
|
+
vueI18nAliasName,
|
|
328
|
+
ssrBuild,
|
|
329
|
+
runtimeOnly,
|
|
330
|
+
fullInstall,
|
|
331
|
+
filter
|
|
336
332
|
});
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
350
|
-
})
|
|
351
|
-
);
|
|
352
|
-
debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
353
|
-
debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
354
|
-
} else {
|
|
355
|
-
debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
|
|
356
|
-
}
|
|
333
|
+
},
|
|
334
|
+
rspack(compiler) {
|
|
335
|
+
webpackLike(compiler, "rspack", {
|
|
336
|
+
isProduction,
|
|
337
|
+
meta,
|
|
338
|
+
sourceMap,
|
|
339
|
+
getVueI18nAliasPath,
|
|
340
|
+
vueI18nAliasName,
|
|
341
|
+
ssrBuild,
|
|
342
|
+
runtimeOnly,
|
|
343
|
+
fullInstall,
|
|
344
|
+
filter
|
|
357
345
|
});
|
|
358
|
-
if (compiler.options.module) {
|
|
359
|
-
compiler.options.module.rules.push({
|
|
360
|
-
test: /\.(json5?|ya?ml)$/,
|
|
361
|
-
type: "javascript/auto",
|
|
362
|
-
include(resource) {
|
|
363
|
-
return filter(resource);
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
346
|
},
|
|
368
347
|
resolveId(id, importer) {
|
|
369
348
|
debug$2("resolveId", id, importer);
|
|
@@ -371,6 +350,9 @@ function resourcePlugin({
|
|
|
371
350
|
return asVirtualId(id, meta.framework);
|
|
372
351
|
}
|
|
373
352
|
},
|
|
353
|
+
loadInclude(id) {
|
|
354
|
+
return INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework);
|
|
355
|
+
},
|
|
374
356
|
async load(id) {
|
|
375
357
|
debug$2("load", id);
|
|
376
358
|
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework) && include) {
|
|
@@ -502,34 +484,99 @@ function resourcePlugin({
|
|
|
502
484
|
function getGenerator(ext, defaultGen = generateJSON) {
|
|
503
485
|
return /\.?json5?$/.test(ext) ? generateJSON : /\.ya?ml$/.test(ext) ? generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? generateJavaScript : defaultGen;
|
|
504
486
|
}
|
|
487
|
+
function webpackLike(compiler, framework, {
|
|
488
|
+
isProduction,
|
|
489
|
+
sourceMap,
|
|
490
|
+
meta,
|
|
491
|
+
getVueI18nAliasPath,
|
|
492
|
+
vueI18nAliasName,
|
|
493
|
+
ssrBuild,
|
|
494
|
+
runtimeOnly,
|
|
495
|
+
fullInstall,
|
|
496
|
+
filter
|
|
497
|
+
}) {
|
|
498
|
+
isProduction = compiler.options.mode !== "development";
|
|
499
|
+
sourceMap = !!compiler.options.devtool;
|
|
500
|
+
debug$2(
|
|
501
|
+
`${framework}: isProduction = ${isProduction}, sourceMap = ${sourceMap}`
|
|
502
|
+
);
|
|
503
|
+
compiler.options.resolve = normalizeConfigResolveAlias(
|
|
504
|
+
compiler.options.resolve,
|
|
505
|
+
meta.framework
|
|
506
|
+
);
|
|
507
|
+
compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath({
|
|
508
|
+
ssr: ssrBuild,
|
|
509
|
+
runtimeOnly
|
|
510
|
+
});
|
|
511
|
+
debug$2(
|
|
512
|
+
`set ${vueI18nAliasName}: ${getVueI18nAliasPath({
|
|
513
|
+
ssr: ssrBuild,
|
|
514
|
+
runtimeOnly
|
|
515
|
+
})}`
|
|
516
|
+
);
|
|
517
|
+
const loader = framework === "webpack" ? loadWebpack : loadRspack;
|
|
518
|
+
loader().then((mod) => {
|
|
519
|
+
if (mod) {
|
|
520
|
+
compiler.options.plugins.push(
|
|
521
|
+
// @ts-expect-error type issue
|
|
522
|
+
new mod.DefinePlugin({
|
|
523
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
524
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
525
|
+
})
|
|
526
|
+
);
|
|
527
|
+
debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
528
|
+
} else {
|
|
529
|
+
debug$2(`ignore vue-i18n feature flags with ${framework}.DefinePlugin`);
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
if (compiler.options.module) {
|
|
533
|
+
compiler.options.module.rules.push({
|
|
534
|
+
test: /\.(json5?|ya?ml)$/,
|
|
535
|
+
type: "javascript/auto",
|
|
536
|
+
include(resource) {
|
|
537
|
+
return filter(resource);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
505
542
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
506
543
|
if (resolve && resolve.alias) {
|
|
507
544
|
return resolve;
|
|
508
545
|
}
|
|
546
|
+
const webpackLike2 = framework === "webpack" || framework === "rspack";
|
|
509
547
|
if (!resolve) {
|
|
510
548
|
if (framework === "vite") {
|
|
511
549
|
return { alias: [] };
|
|
512
|
-
} else if (
|
|
550
|
+
} else if (webpackLike2) {
|
|
513
551
|
return { alias: {} };
|
|
514
552
|
}
|
|
515
553
|
} else if (!resolve.alias) {
|
|
516
554
|
if (framework === "vite") {
|
|
517
555
|
resolve.alias = [];
|
|
518
556
|
return resolve;
|
|
519
|
-
} else if (
|
|
557
|
+
} else if (webpackLike2) {
|
|
520
558
|
resolve.alias = {};
|
|
521
559
|
return resolve;
|
|
522
560
|
}
|
|
523
561
|
}
|
|
524
562
|
}
|
|
525
563
|
async function loadWebpack() {
|
|
526
|
-
let webpack = null;
|
|
527
564
|
try {
|
|
528
|
-
|
|
565
|
+
const mod = await import('webpack');
|
|
566
|
+
return mod.default || mod;
|
|
529
567
|
} catch (_e) {
|
|
530
568
|
warn(`webpack not found, please install webpack.`);
|
|
531
569
|
}
|
|
532
|
-
return
|
|
570
|
+
return null;
|
|
571
|
+
}
|
|
572
|
+
async function loadRspack() {
|
|
573
|
+
try {
|
|
574
|
+
const { rspack } = await import('@rspack/core');
|
|
575
|
+
return rspack;
|
|
576
|
+
} catch (_e) {
|
|
577
|
+
warn(`rspack not found, please install rspack.`);
|
|
578
|
+
}
|
|
579
|
+
return null;
|
|
533
580
|
}
|
|
534
581
|
async function generateBundleResources(resources, isProduction, {
|
|
535
582
|
forceStringify = false,
|
|
@@ -591,9 +638,9 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
|
|
|
591
638
|
if (!isNumber(index)) {
|
|
592
639
|
raiseError(`unexpected index: ${index}`);
|
|
593
640
|
}
|
|
594
|
-
if (framework === "webpack") {
|
|
641
|
+
if (framework === "webpack" || framework === "rspack") {
|
|
595
642
|
if (issuerPath) {
|
|
596
|
-
debug$2(`getCode (
|
|
643
|
+
debug$2(`getCode (${framework}) ${index} via issuerPath`, issuerPath);
|
|
597
644
|
return await getRaw(filename);
|
|
598
645
|
} else {
|
|
599
646
|
const result = parser(await getRaw(filename), {
|
|
@@ -603,7 +650,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
|
|
|
603
650
|
const block = result.descriptor.customBlocks[index];
|
|
604
651
|
if (block) {
|
|
605
652
|
const code = block.src ? await getRaw(block.src) : block.content;
|
|
606
|
-
debug$2(`getCode (
|
|
653
|
+
debug$2(`getCode (${framework}) ${index} from SFC`, code);
|
|
607
654
|
return code;
|
|
608
655
|
} else {
|
|
609
656
|
return source;
|
|
@@ -962,17 +1009,17 @@ function resolveIdentifier(localVariables, returnVariable) {
|
|
|
962
1009
|
const debug = createDebug(resolveNamespace("root"));
|
|
963
1010
|
const unpluginFactory = (options = {}, meta) => {
|
|
964
1011
|
debug("meta framework", meta.framework);
|
|
965
|
-
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
966
|
-
raiseError(`This plugin is supported 'vite' and '
|
|
1012
|
+
if (!["vite", "webpack", "rspack"].includes(meta.framework)) {
|
|
1013
|
+
raiseError(`This plugin is supported 'vite', 'webpack' and 'rspack' only`);
|
|
967
1014
|
}
|
|
968
1015
|
debug("plugin options (resolving):", options);
|
|
969
1016
|
const resolvedOptions = resolveOptions(options);
|
|
970
1017
|
debug("plugin options (resolved):", resolvedOptions);
|
|
971
1018
|
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
972
1019
|
if (resolvedOptions.optimizeTranslationDirective) {
|
|
973
|
-
if (meta.framework === "webpack") {
|
|
1020
|
+
if (meta.framework === "webpack" || meta.framework === "rspack") {
|
|
974
1021
|
raiseError(
|
|
975
|
-
`The 'optimizeTranslationDirective' option still is not supported for
|
|
1022
|
+
`The 'optimizeTranslationDirective' option still is not supported for ${meta.framework}.
|
|
976
1023
|
We are waiting for your Pull Request \u{1F642}.`
|
|
977
1024
|
);
|
|
978
1025
|
}
|
package/lib/rspack.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const unplugin = require('unplugin');
|
|
4
|
+
const index = require('./index.cjs');
|
|
5
|
+
require('debug');
|
|
6
|
+
require('picocolors');
|
|
7
|
+
require('node:path');
|
|
8
|
+
require('pathe');
|
|
9
|
+
require('@intlify/shared');
|
|
10
|
+
require('@intlify/bundle-utils');
|
|
11
|
+
require('@rollup/pluginutils');
|
|
12
|
+
require('fast-glob');
|
|
13
|
+
require('node:fs');
|
|
14
|
+
require('vue/compiler-sfc');
|
|
15
|
+
require('@intlify/vue-i18n-extensions');
|
|
16
|
+
require('@typescript-eslint/scope-manager');
|
|
17
|
+
require('@typescript-eslint/typescript-estree');
|
|
18
|
+
require('@eslint-community/eslint-utils');
|
|
19
|
+
|
|
20
|
+
const rspack = unplugin.createRspackPlugin(index.unpluginFactory);
|
|
21
|
+
|
|
22
|
+
module.exports = rspack;
|
package/lib/rspack.d.cts
ADDED
package/lib/rspack.d.mts
ADDED
package/lib/rspack.d.ts
ADDED
package/lib/rspack.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRspackPlugin } from 'unplugin';
|
|
2
|
+
import { unpluginFactory } from './index.mjs';
|
|
3
|
+
import 'debug';
|
|
4
|
+
import 'picocolors';
|
|
5
|
+
import 'node:path';
|
|
6
|
+
import 'pathe';
|
|
7
|
+
import '@intlify/shared';
|
|
8
|
+
import '@intlify/bundle-utils';
|
|
9
|
+
import '@rollup/pluginutils';
|
|
10
|
+
import 'fast-glob';
|
|
11
|
+
import 'node:fs';
|
|
12
|
+
import 'vue/compiler-sfc';
|
|
13
|
+
import '@intlify/vue-i18n-extensions';
|
|
14
|
+
import '@typescript-eslint/scope-manager';
|
|
15
|
+
import '@typescript-eslint/typescript-estree';
|
|
16
|
+
import '@eslint-community/eslint-utils';
|
|
17
|
+
|
|
18
|
+
const rspack = createRspackPlugin(unpluginFactory);
|
|
19
|
+
|
|
20
|
+
export { rspack as default };
|
package/lib/types.d.cts
CHANGED
package/lib/types.d.mts
CHANGED
package/lib/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-beta.1",
|
|
5
5
|
"description": "unplugin for Vue I18n",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "kazuya kawaguchi",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"pathe": "^1.0.0",
|
|
39
39
|
"picocolors": "^1.0.0",
|
|
40
40
|
"source-map-js": "^1.0.2",
|
|
41
|
-
"unplugin": "^
|
|
41
|
+
"unplugin": "^2.2.0",
|
|
42
42
|
"vue": "^3.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"@types/node": "^20.14.8",
|
|
46
|
+
"unbuild": "^2.0.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">= 18"
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"unplugin",
|
|
60
60
|
"transform",
|
|
61
61
|
"webpack",
|
|
62
|
+
"rspack",
|
|
62
63
|
"vite",
|
|
63
64
|
"vue",
|
|
64
65
|
"vue-i18n"
|
|
@@ -80,6 +81,10 @@
|
|
|
80
81
|
"import": "./lib/webpack.mjs",
|
|
81
82
|
"require": "./lib/webpack.cjs"
|
|
82
83
|
},
|
|
84
|
+
"./rspack": {
|
|
85
|
+
"import": "./lib/rspack.mjs",
|
|
86
|
+
"require": "./lib/rspack.cjs"
|
|
87
|
+
},
|
|
83
88
|
"./types": {
|
|
84
89
|
"import": {
|
|
85
90
|
"types": "./lib/types.d.mts"
|
package/rspack.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './lib/rspack'
|