Skip to content

Commit c27fa2c

Browse files
authored
revert: change default ES module bundler module (#256)
* revert: change default ES module bundler module * update textlintrc * updates docs * update docs
1 parent a1cd110 commit c27fa2c

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

.textlintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = {
2828
'JSON5',
2929
'HTTP',
3030
'CLI',
31+
'CSP',
3132
'SFC',
3233
'PHP',
3334
'SSR',

docs/.vitepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const config = {
170170
},
171171
{
172172
text: 'Optimaization',
173-
link: '/advanced/optimaization',
173+
link: '/advanced/optimization',
174174
}
175175
]
176176
},

docs/advanced/optimization.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,65 @@ You can pre-translation with vue-i18n-extensions.
77

88
About how to usage, see [here](https://github.com/intlify/vue-i18n-extensions).
99

10+
## Improve performance and reduce bundle size with runtime build only
11+
12+
As described in "[installation](installation##from-cdn-or-without-a-bundler)" section, Vue I18n offer the following two built ES modules for Bundler.
13+
14+
- message compiler + runtime: **`vue-i18n.esm-bundler.js`**
15+
- runtime only: **`vue-i18n.runtime.esm-bundler.js`**
16+
17+
For bundler, it’s configured to bundle `vue-i18n.esm-bundler.js` by default. If you want to reduce the bundle size further, you can configure the bundler to use `vue-i18n.runtime.esm-bundler.js`, which is runtime only.
18+
19+
The use of this ES Module means that **all locale messages have to pre-compile to Message functions**.
20+
21+
:::danger NOTE
22+
In the [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) environment, `vue-i18n.esm-bundler.js` does not work with compiler due to policy, so you need to use `vue-i18n.runtime.esm-bundler.js` in that environment as well.
23+
:::
24+
25+
### webpack
26+
27+
In webpack, use `resolve.alias` as below:
28+
29+
```js
30+
module.exports = {
31+
// ...
32+
resolve: {
33+
alias: {
34+
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
35+
}
36+
},
37+
// ...
38+
}
39+
```
40+
41+
:::tip NOTE
42+
For more information about pre-compiling locale messages, see [`@intlify/vue-i18n-loader`](https://github.com/intlify/vue-i18n-loader)
43+
:::
44+
45+
### rollup
46+
47+
In rollup, use [`@rollup/plugin-alias`](https://github.com/rollup/plugins/tree/master/packages/alias) as below:
48+
49+
```js
50+
import path from 'path'
51+
import alias from '@rollup/plugin-alias'
52+
53+
module.exports = {
54+
// ...
55+
plugins: [
56+
alias({
57+
entries: {
58+
'vue-i18n': path.resolve(__dirname, './node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js')
59+
}
60+
})
61+
],
62+
// ...
63+
}
64+
```
65+
66+
### vite
67+
68+
TODO:
1069

1170
## Reduce bundle size with feature build flags
1271

docs/installation.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,16 @@ Global builds are not [UMD](https://github.com/umdjs/umd) builds. They are built
109109
- Imported dependencies are also `esm-bundler` builds and will in turn import their dependencies (e.g. `@intlify/message-compiler` imports `@intlify/shared`)
110110
- This means you **can** install/import these deps individually without ending up with different instances of these dependencies, but you must make sure they all resolve to the same version
111111
- In-browser locale messages compilation:
112-
- **`vue-i18n.runtime.esm-bundler.js` (default)** is runtime only, and requires all locale messages to be pre-compiled. This is the default entry for bundlers (via `module` field in `package.json`) because when using a bundler templates are typically pre-compiled (e.g. in `*.json` files)
113-
- **`vue-i18n.esm-bundler.js`**: includes the runtime compiler. Use this if you are using a bundler but still want locale messages compilation (e.g. templates via inline JavaScript strings)
112+
- **`vue-i18n.runtime.esm-bundler.js`** is runtime only, and requires all locale messages to be pre-compiled. This is the default entry for bundlers (via `module` field in `package.json`) because when using a bundler templates are typically pre-compiled (e.g. in `*.json` files)
113+
- **`vue-i18n.esm-bundler.js` (default)**: includes the runtime compiler. Use this if you are using a bundler but still want locale messages compilation (e.g. templates via inline JavaScript strings)
114+
115+
:::tip NOTE
116+
If you use `vue-i18n.runtime.esm-bundler.js`, you will need to precompile all locale messages, and you can do that with `.json` (`.json5`) or `.yaml`, i18n custom blocks to manage i18n resources. Therefore, you can be going to pre-compile all locale messages with bundler and the following loader / plugin.
117+
118+
- [`@intlify/vue-i18n-loader`](https://github.com/intlify/vue-i18n-loader)
119+
- [`@intlify/rollup-plugin-vue-i18n`](https://github.com/intlify/rollup-plugin-vue-i18n)
120+
- [`@intlify/vite-plugin-vue-i18n`](https://github.com/intlify/vite-plugin-vue-i18n)
121+
:::
114122
115123
### For Node.js (Server-Side)
116124

packages/vue-i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dist"
3030
],
3131
"main": "index.js",
32-
"module": "dist/vue-i18n.runtime.esm-bundler.js",
32+
"module": "dist/vue-i18n.esm-bundler.js",
3333
"unpkg": "dist/vue-i18n.global.js",
3434
"jsdelivr": "dist/vue-i18n.global.js",
3535
"types": "dist/vue-i18n.d.ts",

0 commit comments

Comments
 (0)