Skip to content
This repository was archived by the owner on Jul 4, 2021. It is now read-only.

Commit ff31cb3

Browse files
authored
feat: runtimeOnly option (#57)
* feat: runtimeOnly option * update docs
1 parent 92b5e02 commit ff31cb3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ $ yarn add -D @intlify/vite-plugin-vue-i18n
3030

3131
When this plugin is installed, Vue I18n can only use the Composition API, and if you want to use the Legacy API, you need to set the `compositionOnly` option to `false`.
3232

33+
Also, if you do a production build with vite, Vue I18n will automatically bundle the runtime only module. If you need on-demand compilation with Message compiler, you need to set the `runtimeOnly` option to `false`.
3334

3435
## :rocket: Usage
3536

@@ -215,6 +216,15 @@ About details, See the below section
215216

216217
Note `json` resources matches this option, it will be handled **before the internal json plugin of Vite, and will not be processed afterwards**, else the option doesn't match, the Vite side will handle.
217218

219+
### `runtimeOnly`
220+
- **Type:** `boolean`
221+
- **Default:** `true`
222+
223+
Whether or not to automatically use Vue I18n **runtime-only** in production build, set in the `vue-i18n` field of Vite `alias` option.
224+
If `false` is specified, Vue I18n (vue-i18n) package.json `module` field will be used.
225+
226+
For more details, See [here](#package-automatic-vue-i18n-bundling)
227+
218228
### `compositionOnly`
219229

220230
- **Type:** `boolean`

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function pluginI18n(
4343

4444
const env = process.env.NODE_ENV || 'development'
4545
const filter = createFilter(include)
46+
const runtimeOnly = isBoolean(options.runtimeOnly)
47+
? options.runtimeOnly
48+
: true
4649
const compositionOnly = isBoolean(options.compositionOnly)
4750
? options.compositionOnly
4851
: true
@@ -58,7 +61,7 @@ function pluginI18n(
5861
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5962
const partialConfig: any = { define: {}, alias: {} }
6063

61-
if (env === 'production') {
64+
if (env === 'production' && runtimeOnly) {
6265
partialConfig.alias['vue-i18n'] =
6366
'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
6467
debug('set vue-i18n runtime only')

src/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export type VitePluginVueI18nOptions = {
22
forceStringify?: boolean
3+
runtimeOnly?: boolean
34
compositionOnly?: boolean
45
fullInstall?: boolean
56
include?: string | string[]

0 commit comments

Comments
 (0)