Skip to content

Commit 3141c81

Browse files
committed
update docs
1 parent 11a0c10 commit 3141c81

File tree

3 files changed

+144
-52
lines changed

3 files changed

+144
-52
lines changed

docs/guide/advanced/optimization.md

Lines changed: 138 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,183 @@
11
# Optimization
22

33

4-
## Improve performance and reduce bundle size with runtime build only
4+
## Performance
55

66
As described in "[installation](../../installation##from-cdn-or-without-a-bundler)" section, Vue I18n offer the following two built ES modules for Bundler.
77

88
- message compiler + runtime: **`vue-i18n.esm-bundler.js`**
99
- runtime only: **`vue-i18n.runtime.esm-bundler.js`**
1010

11-
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.
12-
13-
The use of this ES Module means that **all locale messages have to pre-compile to Message functions**.
11+
For bundler, it’s configured to bundle `vue-i18n.esm-bundler.js` with [`@intlify/bundle-tools`](https://github.com/intlify/bundle-tools#intlifybundle-tools) as 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.
1412

1513
:::danger NOTE
1614
IF [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) is enabled, `vue-i18n.esm-bundler.js` would not work with compiler due to `eval` statements. These statements violate the `default-src 'self'` header. Instead you need to use `vue-i18n.runtime.esm-bundler.js`.
1715
:::
1816

19-
### vite
17+
The use of this ES Module means that **all locale messages have to pre-compile to Message functions**. what this means it improves performance because vue-i18n just only execute Message functions, so no compilation.
18+
19+
Also, the message compiler is not bundled, therefore **bundle size can be reduced**
20+
21+
## How to configure
22+
23+
We can configure these modules with module path using the module resolve alias feature (e.g. `resolve.alias` vite and webpack) of some bundler, but It takes time and effort.
24+
Intlify project provides plugins/loaders for some bundlers, for simplicity
25+
26+
### `@intlify/unplugin-vue-i18n`
2027

21-
In vite, use `alias` option as below:
28+
[`unplugin`](https://github.com/unjs/unplugin) is an unified plugin system for bundle tool such as vite, webpack, rollup, esbuild and etc.
29+
30+
Intlify project is providing [`@intlify/unplugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n) for vite and webpack.
31+
32+
If you do a production build, Vue I18n will automatically bundle the runtime only module
33+
34+
#### Install plugin
35+
36+
```sh
37+
npm install --save-dev @intlify/unplugin-vue-i18n
38+
```
39+
40+
#### Configure plugin for vite
2241

2342
```js
24-
import path from 'path'
43+
// vite.config.ts
2544
import { defineConfig } from 'vite'
26-
import vue from '@vitejs/plugin-vue'
27-
import vueI18n from '@intlify/vite-plugin-vue-i18n'
45+
import { resolve, dirname } from 'node:path'
46+
import { fileURLToPath } from 'url'
47+
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
2848

2949
export default defineConfig({
30-
// ...
31-
alias: {
32-
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
33-
},
50+
/* ... */
3451
plugins: [
35-
vue(),
36-
vueI18n({
37-
include: path.resolve(__dirname, './path/to/src/locales/**')
38-
})
52+
/* ... */
53+
VueI18nPlugin({
54+
/* options */
55+
// locale messages resourece pre-compile option
56+
include: resolve(dirname(fileURLToPath(import.meta.url)), './path/to/src/locales/**'),
57+
}),
3958
],
40-
// ...
4159
})
4260
```
4361
44-
:::tip NOTE
45-
If you are using Vite, you can do the same thing by specifying the option in the [plugin provided officially](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n).
62+
#### Configure plugin for webpack
63+
64+
```js
65+
// webpack.config.js
66+
const paht = require('path')
67+
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/webpack')
68+
69+
module.exports = {
70+
/* ... */
71+
plugins: [
72+
/* ... */
73+
VueI18nPlugin({
74+
/* options */
75+
// locale messages resourece pre-compile option
76+
include: path.resolve(__dirname, './path/to/src/locales/**'),
77+
})
78+
]
79+
}
80+
```
81+
82+
#### More configuration
83+
84+
About optoins and features, see the deital [page](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#intlifyunplugin-vue-i18n)
85+
86+
### `@intlify/vite-plugin-vue-i18n`
87+
88+
[`vite`](https://vitejs.dev/) is next generation frontend tooling.
89+
90+
Intlify project is providing [`@intlify/vite-plugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
91+
92+
If you do a production build, Vue I18n will automatically bundle the runtime only module
93+
94+
:::warning NOTICE
95+
This plugin will be deprecated in the near future, because we can replace `@intlify/unplugin-vue-i18n`.
4696
:::
4797
48-
### webpack
98+
#### Install plugin
99+
100+
```sh
101+
npm install --save-dev @intlify/vite-plugin-vue-i18n
102+
```
49103
50-
In webpack, use `resolve.alias` as below:
104+
#### Configure
51105
52106
```js
53-
module.exports = {
54-
// ...
55-
resolve: {
56-
alias: {
57-
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
58-
}
59-
},
60-
// ...
61-
}
107+
// vite.config.ts
108+
import { defineConfig } from 'vite'
109+
import { resolve, dirname } from 'node:path'
110+
import { fileURLToPath } from 'url'
111+
import vueI18n from '@intlify/vite-plugin-vue-i18n'
112+
113+
export default defineConfig({
114+
/* ... */
115+
plugins: [
116+
/* ... */
117+
vueI18n({
118+
/* options */
119+
// locale messages resourece pre-compile option
120+
include: resolve(dirname(fileURLToPath(import.meta.url)), './path/to/src/locales/**'),
121+
}),
122+
]
123+
})
62124
```
63125
64-
:::tip NOTE
65-
For more information about pre-compiling locale messages, see [`@intlify/vue-i18n-loader`](https://github.com/intlify/vue-i18n-loader)
126+
#### More configuration
127+
128+
About optoins and features, see the deital [page](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
129+
130+
### `@intlify/vue-i18n-loader`
131+
132+
[webpack](https://webpack.js.org/) is a static module bundler for modern JavaScript applications.
133+
134+
Intlify project is providing [`@intlify/vue-i18n-loader`](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
135+
136+
:::danger NOTICE
137+
This plugin will be deprecated in the near future, because we can replace `@intlify/unplugin-vue-i18n`.
66138
:::
67139
68-
### rollup
140+
#### Install loader
69141
70-
In rollup, use [`@rollup/plugin-alias`](https://github.com/rollup/plugins/tree/master/packages/alias) as below:
142+
```sh
143+
npm install --save-dev @intlify/vue-i18n-loader
144+
```
145+
146+
#### Configure
71147
72148
```js
73-
import path from 'path'
74-
import alias from '@rollup/plugin-alias'
149+
// webpack.config.js
150+
const paht = require('path')
75151

76152
module.exports = {
77-
// ...
78-
plugins: [
79-
alias({
80-
entries: {
81-
'vue-i18n': path.resolve(__dirname, './node_modules/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js')
82-
}
83-
})
84-
],
85-
// ...
153+
/* ... */
154+
resolve: {
155+
alias: {
156+
'vue-i18n': 'vue-i18n/dist/vue-i18n.runtime.esm-bundler.js'
157+
}
158+
},
159+
/* ... */
160+
module: {
161+
rules: [
162+
// ...
163+
{
164+
test: /\.(json5?|ya?ml)$/, // target json, json5, yaml and yml files
165+
type: 'javascript/auto',
166+
loader: '@intlify/vue-i18n-loader',
167+
include: [ // Use `Rule.include` to specify the files of locale messages to be pre-compiled
168+
path.resolve(__dirname, 'src/locales')
169+
]
170+
},
171+
// ...
172+
]
173+
}
86174
}
87175
```
88176
177+
#### More configuration
178+
179+
About optoins and features, see the deital [page](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
180+
89181
### Quasar CLI
90182
91183
No need to do anything. [Quasar CLI](https://quasar.dev) takes care of the optimizations for you.

docs/installation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ You will have to clone directly from GitHub and build `vue-i18n` yourself if you
7373
```sh
7474
git clone git@github.com:intlify/vue-i18n-next.git node_modules/vue-i18n
7575
cd node_modules/vue-i18n
76-
npm install # or `yarn`
77-
npm run build # or `yarn run build`
76+
npm install
77+
npm run build
7878
```
7979
8080
8181
## Explanation of Different Builds
82-
In the [dist/ directory of the npm package](https://cdn.jsdelivr.net/npm/[email protected].0/dist/) you will find many different builds of Vue I18n. Here is an overview of which dist file should be used depending on the use-case.
82+
In the [dist/ directory of the npm package](https://cdn.jsdelivr.net/npm/[email protected].10/dist/) you will find many different builds of Vue I18n. Here is an overview of which dist file should be used depending on the use-case.
8383
8484
### From CDN or without a Bundler
8585
@@ -115,9 +115,9 @@ Global builds are not [UMD](https://github.com/umdjs/umd) builds. They are built
115115
:::tip NOTE
116116
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.
117117
118-
- [`@intlify/vue-i18n-loader`](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
119-
- [`@intlify/rollup-plugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/rollup-plugin-vue-i18n)
118+
- [`@intlify/unplugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n)
120119
- [`@intlify/vite-plugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
120+
- [`@intlify/vue-i18n-loader`](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
121121
:::
122122
123123
### For Node.js (Server-Side)

examples/bridge/legacy/scope/local.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ <h1>Child</h1>
8787
)
8888

8989
Vue.use(i18n)
90-
90+
9191
const app = new Vue({ i18n, components: { Child } })
9292
app.$mount('#app')
9393
</script>

0 commit comments

Comments
 (0)