Skip to content

Commit c1df0c8

Browse files
authored
feat(unplugin-vue-i18n): support esm options for bridge (#138)
1 parent 2f67ee4 commit c1df0c8

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

packages/unplugin-vue-i18n/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimi
414414

415415
> ⚠️ Note that if you set `bridge: true`, the bundle size will increase. It is recommended to disable this mode after the migration from [email protected] to [email protected] is completed.
416416
417+
### `esm`
418+
419+
- **Type:** `boolean`
420+
- **Default:** `true`
421+
422+
For `bridge` option is `true`, whether to bundle locale resources with ESM. By default ESM, if you need to bundl with commonjs for especialy webpack, you need to set `false`
423+
417424
### `useClassComponent`
418425

419426
- **Type:** `boolean`

packages/unplugin-vue-i18n/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,28 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
5353
: 'json'
5454
const globalSFCScope = !!options.globalSFCScope
5555
const useClassComponent = !!options.useClassComponent
56+
5657
const bridge = !!options.bridge
5758
debug('bridge', bridge)
59+
5860
const runtimeOnly = isBoolean(options.runtimeOnly)
5961
? options.runtimeOnly
6062
: true
6163
debug('runtimeOnly', runtimeOnly)
64+
6265
const compositionOnly = isBoolean(options.compositionOnly)
6366
? options.compositionOnly
6467
: true
6568
debug('compositionOnly', compositionOnly)
69+
6670
const fullInstall = isBoolean(options.fullInstall)
6771
? options.fullInstall
6872
: true
6973
debug('fullInstall', fullInstall)
7074

75+
const esm = isBoolean(options.esm) ? options.esm : true
76+
debug('esm', esm)
77+
7178
let isProduction = false
7279
let sourceMap = false
7380

@@ -246,6 +253,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
246253
{
247254
forceStringify,
248255
bridge,
256+
exportESM: esm,
249257
useClassComponent
250258
}
251259
)
@@ -284,6 +292,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
284292
isGlobal: globalSFCScope,
285293
useClassComponent,
286294
bridge,
295+
exportESM: esm,
287296
forceStringify
288297
}
289298
) as CodeGenOptions
@@ -341,6 +350,7 @@ export const unplugin = createUnplugin<PluginOptions>((options = {}, meta) => {
341350
isGlobal: globalSFCScope,
342351
useClassComponent,
343352
bridge,
353+
exportESM: esm,
344354
forceStringify
345355
}
346356
) as CodeGenOptions
@@ -416,11 +426,13 @@ async function generateBundleResources(
416426
forceStringify = false,
417427
isGlobal = false,
418428
bridge = false,
429+
exportESM = true,
419430
useClassComponent = false
420431
}: {
421432
forceStringify?: boolean
422433
isGlobal?: boolean
423434
bridge?: boolean
435+
exportESM?: boolean
424436
useClassComponent?: boolean
425437
}
426438
) {
@@ -436,6 +448,7 @@ async function generateBundleResources(
436448
isGlobal,
437449
useClassComponent,
438450
bridge,
451+
exportESM,
439452
forceStringify
440453
}) as CodeGenOptions
441454
parseOptions.type = 'bare'
@@ -511,12 +524,14 @@ function getOptions(
511524
forceStringify = false,
512525
isGlobal = false,
513526
bridge = false,
527+
exportESM = true,
514528
useClassComponent = false
515529
}: {
516530
inSourceMap?: RawSourceMap
517531
forceStringify?: boolean
518532
isGlobal?: boolean
519533
bridge?: boolean
534+
exportESM?: boolean
520535
useClassComponent?: boolean
521536
}
522537
): Record<string, unknown> {
@@ -529,6 +544,7 @@ function getOptions(
529544
forceStringify,
530545
useClassComponent,
531546
bridge,
547+
exportESM,
532548
env: mode,
533549
onWarn: (msg: string): void => {
534550
warn(`${filename} ${msg}`)

packages/unplugin-vue-i18n/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface PluginOptions {
44
runtimeOnly?: boolean
55
compositionOnly?: boolean
66
fullInstall?: boolean
7+
esm?: boolean
78
forceStringify?: boolean
89
defaultSFCLang?: SFCLangFormat
910
globalSFCScope?: boolean

0 commit comments

Comments
 (0)