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

Commit 3918914

Browse files
authored
feat: vue-i18n dist module optimization (#48)
* feat: vue-i18n dist module optimization * updates
1 parent 9b070cf commit 3918914

File tree

8 files changed

+85
-106
lines changed

8 files changed

+85
-106
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,29 @@ ja:
125125
</i18n>
126126
```
127127

128-
### Bundling optimizations
128+
### Bundle optimizations
129129

130-
vite-plugin-vue-i18n allows you to specify options in the plugin option to support bundling size optimization provided by vue-i18n.
130+
vite-plugin-vue-i18n allows you to support bundle size optimization provided by vue-i18n.
131131

132-
The same thing can be [configured](https://vue-i18n-next.intlify.dev/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags) with the `define` option, but the plugin option is more friendly. Especially if you are using typescript, you can use intelisense.
132+
## :package: Automatic Vue I18n bundling
133133

134-
About details, See the below section
134+
As noted [here](https://vue-i18n.intlify.dev/installation.html#explanation-of-different-builds), NPM provides many different builds of Vue I18n.
135+
136+
vite-plugin-vue-i18n will automatically select and bundle Vue I18n build according to the following vite behavior:
135137

138+
- vite dev: `vue-i18n.esm-bundler.js`
139+
- vite build: `vue-i18n.runtime.esm-bundler.js`
140+
141+
About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#improve-performance-and-reduce-bundle-size-with-runtime-build-only)
136142

137143
## :wrench: Options
138144

145+
You can specify options in the plugin option to support bundle size optimization provided by vue-i18n.
146+
147+
The same thing can be [configured](https://vue-i18n-next.intlify.dev/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags) with the `define` option, but the plugin option is more friendly. Especially if you are using typescript, you can use intelisense.
148+
149+
About details, See the below section
150+
139151
### `include`
140152

141153
- **Type:** `string | string[] | undefined`
@@ -170,6 +182,8 @@ About details, See the below section
170182

171183
If `false` is specified, **buld-in components and directive will not be installed in vue and will be tree-shaken.**
172184

185+
For more details, See [here](https://vue-i18n-next.intlify.dev/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
186+
173187
### `forceStringify`
174188

175189
- **Type:** `boolean`

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@types/node": "^14.14.10",
3636
"@typescript-eslint/eslint-plugin": "^4.11.0",
3737
"@typescript-eslint/parser": "^4.11.0",
38-
"@vitejs/plugin-vue": "^1.0.4",
38+
"@vitejs/plugin-vue": "^1.1.4",
3939
"@vue/compiler-sfc": "^3.0.5",
4040
"debug": "^4.1.1",
4141
"eslint": "^7.16.0",
@@ -55,9 +55,9 @@
5555
"ts-jest": "^26.4.0",
5656
"typescript": "^4.1.3",
5757
"typescript-eslint-language-service": "^4.1.2",
58-
"vite": "2.0.0-beta.15",
58+
"vite": "2.0.0-beta.61",
5959
"vue": "^3.0.5",
60-
"vue-i18n": "^9.0.0-rc.1"
60+
"vue-i18n": "^9.0.0-rc.5"
6161
},
6262
"engines": {
6363
"node": ">= 12"

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function pluginI18n(
3838
}
3939
}
4040

41+
const env = process.env.NODE_ENV || 'development'
4142
const filter = createFilter(include)
4243
const compositionOnly = isBoolean(options.compositionOnly)
4344
? options.compositionOnly
@@ -54,6 +55,12 @@ function pluginI18n(
5455
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5556
const partialConfig: any = { define: {}, alias: {} }
5657

58+
if (env === 'production') {
59+
partialConfig.alias['vue-i18n'] =
60+
'node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
61+
debug('set vue-i18n runtime only')
62+
}
63+
5764
if (compositionOnly) {
5865
partialConfig.define['__VUE_I18N_LEGACY_API__'] = false
5966
debug('set __VUE_I18N_LEGACY_API__ is `false`')
@@ -71,7 +78,7 @@ function pluginI18n(
7178
config = _config
7279

7380
// json transform handling
74-
const jsonPlugin = config.plugins.find(p => p.name === 'json')
81+
const jsonPlugin = config.plugins.find(p => p.name === 'vite:json')
7582
if (jsonPlugin) {
7683
const orgTransform = jsonPlugin.transform // backup @rollup/plugin-json
7784
jsonPlugin.transform = async function (code: string, id: string) {

test/__snapshots__/custom-block.test.ts.snap

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ Array [
1313
]
1414
`;
1515

16-
exports[`fully-block 1`] = `
17-
Array [
18-
Object {
19-
"locale": "",
20-
"resource": Object {
21-
"en": Object {
22-
"hello": [Function],
23-
},
24-
},
25-
},
26-
]
27-
`;
28-
2916
exports[`global 1`] = `
3017
Array [
3118
Object {

test/custom-block.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,3 @@ test('global', async () => {
104104
expect(g.locale).toEqual('')
105105
expect(g.resource.en.hello(createMessageContext())).toEqual('hello global!')
106106
})
107-
108-
test('fully-block', async () => {
109-
const { module } = await bundleAndRun('fully-block.vue')
110-
expect(module.__i18n).toMatchSnapshot()
111-
const i18n = module.__i18n.pop()
112-
expect(i18n.locale).toEqual('')
113-
expect(i18n.resource.en.hello(createMessageContext())).toEqual('hello world!')
114-
})

test/fixtures/fully-block.vue

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import vueI18n from '../src/index'
88
async function bundle(fixture: string, options: Record<string, unknown> = {}) {
99
const input = (options.input as string) || './fixtures/entry.ts'
1010
const target = (options.target as string) || './fixtures'
11-
const include = (options.include as string[]) || []
11+
const include = (options.include as string[]) || [
12+
path.resolve(__dirname, './fixtures/**')
13+
]
1214
const silent = isBoolean(options.silent)
1315
? options.silent === false
1416
? 'info'

yarn.lock

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@
359359
"@intlify/runtime" "9.0.0-beta.16"
360360
"@intlify/shared" "9.0.0-beta.16"
361361

362-
"@intlify/[email protected].1":
363-
version "9.0.0-rc.1"
364-
resolved "https://registry.yarnpkg.com/@intlify/core-base/-/core-base-9.0.0-rc.1.tgz#92bd60c222626c1cb8a01234a1662cf11a5a7261"
365-
integrity sha512-PqC7FQByeFyNmDOW5LePJfBIV6wL4R4sv8+Gecv9l2SsnkJ4nDCTGcpBT0YRdDDDfKpLhSTHSm+sLdSuHv7EVQ==
362+
"@intlify/[email protected].5":
363+
version "9.0.0-rc.5"
364+
resolved "https://registry.yarnpkg.com/@intlify/core-base/-/core-base-9.0.0-rc.5.tgz#45b79a62be2873521de29e1f4b2cdd326e42e057"
365+
integrity sha512-Dj6lZR9fuDkvyLrc+uhQVY8joy6zkdlEvtHmnBr61Obl4nRzrYUdImoZBbz5makea/FN0YKk8T00Yb4eFGKvfQ==
366366
dependencies:
367-
"@intlify/message-compiler" "9.0.0-rc.1"
368-
"@intlify/message-resolver" "9.0.0-rc.1"
369-
"@intlify/runtime" "9.0.0-rc.1"
370-
"@intlify/shared" "9.0.0-rc.1"
367+
"@intlify/message-compiler" "9.0.0-rc.5"
368+
"@intlify/message-resolver" "9.0.0-rc.5"
369+
"@intlify/runtime" "9.0.0-rc.5"
370+
"@intlify/shared" "9.0.0-rc.5"
371371

372372
"@intlify/core-base@^9.0.0-beta.16":
373373
version "9.0.0-beta.18"
@@ -404,13 +404,13 @@
404404
"@intlify/shared" "9.0.0-beta.18"
405405
source-map "0.6.1"
406406

407-
"@intlify/[email protected].1":
408-
version "9.0.0-rc.1"
409-
resolved "https://registry.yarnpkg.com/@intlify/message-compiler/-/message-compiler-9.0.0-rc.1.tgz#152a971a634fe8b581a033a552bd637da2b2a259"
410-
integrity sha512-oPo/6v6lFvzbVj86ikWzYbHpRatyVQCSASJgGCIhvUGxdyvfxqKr+kQudbKWx/QiBq6cBioMuyh9hOGPhvBPMA==
407+
"@intlify/[email protected].5":
408+
version "9.0.0-rc.5"
409+
resolved "https://registry.yarnpkg.com/@intlify/message-compiler/-/message-compiler-9.0.0-rc.5.tgz#823d59dda2a48d32015ac5f4c5cf20fb4b3ed897"
410+
integrity sha512-TnWea88H3pTqYXNNXV7eZk62IVGXzS7dtoTpTdRj4mfJclyU+3neIqkcoeJC7WM8yeT9VWFkIdx882dWpoghPw==
411411
dependencies:
412-
"@intlify/message-resolver" "9.0.0-rc.1"
413-
"@intlify/shared" "9.0.0-rc.1"
412+
"@intlify/message-resolver" "9.0.0-rc.5"
413+
"@intlify/shared" "9.0.0-rc.5"
414414
source-map "0.6.1"
415415

416416
"@intlify/[email protected]":
@@ -423,10 +423,10 @@
423423
resolved "https://registry.yarnpkg.com/@intlify/message-resolver/-/message-resolver-9.0.0-beta.18.tgz#b84c0308c95c8d53a6c705f4b9688b498543eeb9"
424424
integrity sha512-SJhXBnAT/BUBqZGQuAEXv3Qlwcym0STrgr9ThEx7rsTqCogsrXdITr9A0Saq40DpbLufx31voxUHCWfq6w3fRA==
425425

426-
"@intlify/[email protected].1":
427-
version "9.0.0-rc.1"
428-
resolved "https://registry.yarnpkg.com/@intlify/message-resolver/-/message-resolver-9.0.0-rc.1.tgz#f3c4c1b6e2ffb9cd6c6f6cd40bf92d339b847c65"
429-
integrity sha512-vgt7qqHcHJenehnNG6APOmorpYi2XulD4TJHISNwISGlVz9Mf5+H4uilGkWA/+8k9kUOx5sh/5aN3IP2O8cgbA==
426+
"@intlify/[email protected].5":
427+
version "9.0.0-rc.5"
428+
resolved "https://registry.yarnpkg.com/@intlify/message-resolver/-/message-resolver-9.0.0-rc.5.tgz#144f61a09ff32a9451c37b8e92e806ed3efaf947"
429+
integrity sha512-cZT9kWy6TBB71zb17e5juCTuSNz2/RUf8PeqGYnGP+f/mrPG0X6D3KFqpY3tkWgYwSGcwswd8oBMEvmb0eTMTw==
430430

431431
"@intlify/[email protected]":
432432
version "9.0.0-beta.16"
@@ -446,14 +446,14 @@
446446
"@intlify/message-resolver" "9.0.0-beta.18"
447447
"@intlify/shared" "9.0.0-beta.18"
448448

449-
"@intlify/[email protected].1":
450-
version "9.0.0-rc.1"
451-
resolved "https://registry.yarnpkg.com/@intlify/runtime/-/runtime-9.0.0-rc.1.tgz#400a99eb6f01820d34ce5a5385a15657c004099a"
452-
integrity sha512-6n/Tf9cI+SfuB7GCIkI4AxMu9y4vTrhfrJYkAg8wOddE7jHf6TA4moXGnTnzcd+6gYWiB+UweNAfSebZt59MdQ==
449+
"@intlify/[email protected].5":
450+
version "9.0.0-rc.5"
451+
resolved "https://registry.yarnpkg.com/@intlify/runtime/-/runtime-9.0.0-rc.5.tgz#deffef7622aef0997d355636d76f63e22b6e94a3"
452+
integrity sha512-J6XGb8kOSg9YvSknEyU5CbKYiJGb6ObRqKWL+r8iOYzh1UQ3Q4YxeaIPH2Attt7FNj9dTGyp/5HZy7+nMp3mBA==
453453
dependencies:
454-
"@intlify/message-compiler" "9.0.0-rc.1"
455-
"@intlify/message-resolver" "9.0.0-rc.1"
456-
"@intlify/shared" "9.0.0-rc.1"
454+
"@intlify/message-compiler" "9.0.0-rc.5"
455+
"@intlify/message-resolver" "9.0.0-rc.5"
456+
"@intlify/shared" "9.0.0-rc.5"
457457

458458
"@intlify/[email protected]":
459459
version "9.0.0-beta.16"
@@ -465,10 +465,10 @@
465465
resolved "https://registry.yarnpkg.com/@intlify/shared/-/shared-9.0.0-beta.18.tgz#b2f04c061d02e34d667d36d807686b3a81724915"
466466
integrity sha512-h0kc0UhP9HKNq13ZKnC7asm3C5FwRIVKxdXZcDNVRCCzfJX0dO3REYkP1Szs8gOe5YGPqkKdsTZJtiffzMY+BA==
467467

468-
"@intlify/[email protected].1":
469-
version "9.0.0-rc.1"
470-
resolved "https://registry.yarnpkg.com/@intlify/shared/-/shared-9.0.0-rc.1.tgz#73a57c74682b09a6f7f69b1b43904384a344c05e"
471-
integrity sha512-pOOtAKEIIuGSos+cuy5FKlANMev3x8qG7VJS9wTKy8JJcBzk98Ypt1+oNTOv0B5aIXpRRpxZVAXatvAorXT5/A==
468+
"@intlify/[email protected].5":
469+
version "9.0.0-rc.5"
470+
resolved "https://registry.yarnpkg.com/@intlify/shared/-/shared-9.0.0-rc.5.tgz#8ed9ea92e73b3856031724dc4a11fcbf7f1f7a7c"
471+
integrity sha512-LGurIHW/TYo07WrbCWXBuZQ3Hg2CHAv5rXLFpxBfHjZawCTrrORQfD4NA+RPVbaWFgzMgw5VJybpJRd9iB1x6g==
472472

473473
"@istanbuljs/load-nyc-config@^1.0.0":
474474
version "1.1.0"
@@ -1054,10 +1054,10 @@
10541054
"@typescript-eslint/types" "4.11.1"
10551055
eslint-visitor-keys "^2.0.0"
10561056

1057-
"@vitejs/plugin-vue@^1.0.4":
1058-
version "1.0.4"
1059-
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.0.4.tgz#124b06b185a8b536210bdb00948c17e52ab589fe"
1060-
integrity sha512-VaXpbmriAOeCdstHKjw3L8/8GZ33fcshBbWlN6IocKQW+GOGV4Xm8Vp0Oa/VpPVCSTHMcqvKyQ4gGEBpDHdWHg==
1057+
"@vitejs/plugin-vue@^1.1.4":
1058+
version "1.1.4"
1059+
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-1.1.4.tgz#1dd388519b75439b7733601b55238ca691864796"
1060+
integrity sha512-cUDILd++9jdhdjpuhgJofQqOabOKe+kTWTE2HQY2PBHEUO2fgwTurLE0cJg9UcIo1x4lHfsp+59S9TBCHgTZkw==
10611061

10621062
10631063
version "3.0.5"
@@ -1108,10 +1108,10 @@
11081108
"@vue/compiler-dom" "3.0.5"
11091109
"@vue/shared" "3.0.5"
11101110

1111-
"@vue/devtools-api@^6.0.0-beta.3":
1112-
version "6.0.0-beta.3"
1113-
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.0.0-beta.3.tgz#5a66cc8beed688fe18c272ee7a8bd8ed7e35a54c"
1114-
integrity sha512-iJQhVyWzWIJxYIMjbZpljZQfU4gL2IMD5YQm3HXO8tQRU7RqqnD3f1WHn+vrqvrSvM8Qw2BeNugwdBBmbK8Oxg==
1111+
"@vue/devtools-api@^6.0.0-beta.5":
1112+
version "6.0.0-beta.5"
1113+
resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.0.0-beta.5.tgz#722296bb0b93c4d0018b6a2beda1e781a3ff8789"
1114+
integrity sha512-Xik8/zF+cu1lQmhJy2djGudZ2OmSGGB25mjtTIGhMsNN7jvvwnn44kD6qSN22+PdnX6sAK+2EQ51WDCXWmitwg==
11151115

11161116
11171117
version "3.0.5"
@@ -2419,10 +2419,10 @@ es6-promisify@^5.0.0:
24192419
dependencies:
24202420
es6-promise "^4.0.3"
24212421

2422-
esbuild@^0.8.26:
2423-
version "0.8.29"
2424-
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.29.tgz#cc20fb752e0905a3546d68ae1be58f9b97044c39"
2425-
integrity sha512-UDsEoeXuctVgG2hEts1Hwq2jYDGqV7nksEHEZaiCy2v+lXF5ButX4ErPAJAFi5ZNKKW+6Pom93pArV7hki6HnQ==
2422+
esbuild@^0.8.34:
2423+
version "0.8.39"
2424+
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.8.39.tgz#18b84a3d56173c55ee8f45bc6c7b5374b0a98ecb"
2425+
integrity sha512-/do5H74a5ChyeKRWfkDh3EpICXpsz6dWTtFFbotb7BlIHvWqnRrZYDb8IBubOHdEtKzuiksilRO19aBtp3/HHQ==
24262426

24272427
escalade@^3.1.1:
24282428
version "3.1.1"
@@ -7082,12 +7082,12 @@ [email protected]:
70827082
core-util-is "1.0.2"
70837083
extsprintf "^1.2.0"
70847084

7085-
7086-
version "2.0.0-beta.15"
7087-
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.15.tgz#cd2f1037b4767538839b4c6b4f71a1f9512c7654"
7088-
integrity sha512-S+NRqL+/QZooWbshnB/Rht1Ln0ldyUcGwghwprvmzI4fXAfM0rFU5g6uno0DdueYnHn0jDO3ExQktGyQuNb9Ww==
7085+
7086+
version "2.0.0-beta.61"
7087+
resolved "https://registry.yarnpkg.com/vite/-/vite-2.0.0-beta.61.tgz#da605152999cf8943672202ab6b38b68f4c7b9e4"
7088+
integrity sha512-NyRZ7vCwtfw/z18HmFr5ZIesum26Dg9x4ykuit1YmYsZlPxx/oF3il1U6MqkXZD2wy8HaR5fQi9d9B/6vEJMbw==
70897089
dependencies:
7090-
esbuild "^0.8.26"
7090+
esbuild "^0.8.34"
70917091
postcss "^8.2.1"
70927092
resolve "^1.19.0"
70937093
rollup "^2.35.1"
@@ -7118,14 +7118,14 @@ vue-eslint-parser@^7.3.0:
71187118
esquery "^1.0.1"
71197119
lodash "^4.17.15"
71207120

7121-
vue-i18n@^9.0.0-rc.1:
7122-
version "9.0.0-rc.1"
7123-
resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-9.0.0-rc.1.tgz#47188d60cb1de2818924cdb6abecedf4e97b5cda"
7124-
integrity sha512-pp1bLvu6iGV4QtaUnYB9WmDpOWAWb/j9fx9zIqhI6mYsKPY7kBACeVv8qskSeOoRQm4bjDxqUUQdion3UWfFCw==
7121+
vue-i18n@^9.0.0-rc.5:
7122+
version "9.0.0-rc.5"
7123+
resolved "https://registry.yarnpkg.com/vue-i18n/-/vue-i18n-9.0.0-rc.5.tgz#6d32448a44e2345a211c819f2d0627084c1600c6"
7124+
integrity sha512-sOi/bbUYsLH1rGeGgVeOZukeIxk4FlaeNQKcudtHM8Uc5Y7Fhnvv9APKwUoa1hs2GAflhVCiVZopPrd20HL2+w==
71257125
dependencies:
7126-
"@intlify/core-base" "9.0.0-rc.1"
7127-
"@intlify/shared" "9.0.0-rc.1"
7128-
"@vue/devtools-api" "^6.0.0-beta.3"
7126+
"@intlify/core-base" "9.0.0-rc.5"
7127+
"@intlify/shared" "9.0.0-rc.5"
7128+
"@vue/devtools-api" "^6.0.0-beta.5"
71297129

71307130
vue@^3.0.5:
71317131
version "3.0.5"

0 commit comments

Comments
 (0)