Skip to content

Commit 5d20ead

Browse files
committed
[docs][zh] translated migrating.md
1 parent 887a205 commit 5d20ead

File tree

2 files changed

+47
-47
lines changed

2 files changed

+47
-47
lines changed

docs/zh/guide/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Testing
1+
# 测试
22

33
- [Vue CLI](https://github.com/vuejs/vue-cli) 提供了预配置的单元测试和 e2e 测试安装。
44

docs/zh/migrating.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ sidebar: auto
33
sidebarDepth: 2
44
---
55

6-
# Migrating from v14
6+
# v14 迁移
77

8-
::: tip Heads Up
9-
We are in the process of upgrading Vue CLI 3 beta to use webpack 4 + Vue Loader 15, so you might want to wait if you are planning to upgrade to Vue CLI 3.
8+
::: tip 注意
9+
我们正在升级 Vue CLI 3 beta 的过程中,并使用了 webpack 4 + Vue Loader 15,所以如果你计划升级到 Vue CLI 3 的话,可能需要等待。
1010
:::
1111

12-
## Notable Breaking Changes
12+
## 值得注意的不兼容变更
1313

14-
### A Plugin is Now Required
14+
### 现在你需要一个插件
1515

16-
Vue Loader 15 now requires an accompanying webpack plugin to function properly:
16+
Vue Loader 15 现在需要伴随一个 webpack 插件才能正确使用:
1717

1818
``` js
1919
// webpack.config.js
@@ -27,19 +27,19 @@ module.exports = {
2727
}
2828
```
2929

30-
### Loader Inference
30+
### Loader 推导
3131

32-
Vue Loader 15 now uses a different strategy to infer loaders to use for language blocks.
32+
现在 Vue Loader 15 使用了一个不一样的策略来推导语言块使用的 loader。
3333

34-
Take `<style lang="less">` as an example: in v14 and below, it will attempt to load the block with `less-loader`, and implicitly chains `css-loader` and `vue-style-loader` after it, all using inline loader strings.
34+
`<style lang="less">` 举例:在 v14 或更低版本中,它会尝试使用 `less-loader` 加载这个块,并在其后面隐式地链上 `css-loader` `vue-style-loader`,这一切都使用内联的 loader 字符串。
3535

36-
In v15, `<style lang="less">` will behave as if it's an actual `*.less` file being loaded. So, in order to process it, you need to provide an explicit rule in your main webpack config:
36+
v15 中,`<style lang="less">` 会完成把它当作一个真实的 `*.less` 文件来加载。因此,为了这样处理它,你需要在你的主 webpack 配置中显式地提供一条规则:
3737

3838
``` js
3939
{
4040
module: {
4141
rules: [
42-
// ...other rules
42+
// ... 其它规则
4343
{
4444
test: /\.less$/,
4545
use: [
@@ -53,15 +53,15 @@ In v15, `<style lang="less">` will behave as if it's an actual `*.less` file bei
5353
}
5454
```
5555

56-
The benefit is that this same rule also applies to plain `*.less` imports from JavaScript, and you can configure options for these loaders anyway you want. In v14 and below, if you want to provide custom options to an inferred loader, you'd have to duplicate it under Vue Loader's own `loaders` option. In v15 it is no longer necessary.
56+
这样做的好处是这条规则同样应用在 JavaScript 里普通的 `*.less` 导入中,并且你可以为这些 loader 配置任何你想要的选项。在 v14 或更低版本中,如果你想为一个推导出来的 loader 定制选项,你不得不在 Vue Loader 自己的 `loaders` 选项中将它重复一遍。在 v15 中你再也没有必要这么做了。
5757

58-
v15 also allows using non-serializable options for loaders, which was not possible in previous versions.
58+
v15 也允许为 loader 使用非序列化的选项,这种选项在之前的版本中是无法使用的。
5959

60-
### Template Preprocessing
60+
### 模板预处理
6161

62-
v14 and below uses [consolidate](https://github.com/tj/consolidate.js/) to compile `<template lang="xxx">`. v15 now applies preprocessing for them using webpack loaders instead.
62+
v14 或更低版本使用 [consolidate](https://github.com/tj/consolidate.js/) 来编译 `<template lang="xxx">`v15 现在取而代之的是使用 webpack loader 为它们应用预处理器。
6363

64-
Note that some template loaders such as `pug-loader` exports a compiled templating function instead of plain HTML. In order to pass the correct content to Vue's template compiler, you must use a loader that outputs plain HTML instead. For example, to support `<template lang="pug">`, you can use [pug-plain-loader](https://github.com/yyx990803/pug-plain-loader):
64+
注意有些模板的 loader 会导出一个编译好的模板函数而不是普通的 HTML,诸如 `pug-loader`。为了向 Vue 的模板编译器传递正确的内容,你必须换用一个输出普通 HTMLloader。例如,为了支持 `<template lang="pug">`,你可以使用 [pug-plain-loader](https://github.com/yyx990803/pug-plain-loader)
6565

6666
``` js
6767
{
@@ -76,7 +76,7 @@ Note that some template loaders such as `pug-loader` exports a compiled templati
7676
}
7777
```
7878

79-
If you also intend to use it to import `.pug` files as HTML strings in JavaScript, you will need to chain `raw-loader` after the preprocessing loader. Note however adding `raw-loader` would break the usage in Vue components, so you need to have two rules, one of them targeting Vue files using a `resourceQuery`, the other one (fallback) targeting JavaScript imports:
79+
如果你还打算使用它在 JavaScript 中将 `.pug` 文件作为字符串导入,你需要在这个预处理 loader 之后链上 `raw-loader`。注意添加 `raw-loader` 会破坏 Vue 组件内的用法,所以你需要定义两条规则,其中一条指向使用了一个 `resourceQuery` 的 Vue 文件,另一条指向 (回退到) JavaScript 导入:
8080

8181
``` js
8282
{
@@ -85,12 +85,12 @@ If you also intend to use it to import `.pug` files as HTML strings in JavaScrip
8585
{
8686
test: /\.pug$/,
8787
oneOf: [
88-
// this applies to <template lang="pug"> in Vue components
88+
// 这条规则应用到 Vue 组件内的 `<template lang="pug">`
8989
{
9090
resourceQuery: /^\?vue/,
9191
use: ['pug-plain-loader']
9292
},
93-
// this applies to pug imports inside JavaScript
93+
// 这条规则应用到 JavaScript 内的 pug 导入
9494
{
9595
use: ['raw-loader', 'pug-plain-loader']
9696
}
@@ -101,21 +101,21 @@ If you also intend to use it to import `.pug` files as HTML strings in JavaScrip
101101
}
102102
```
103103

104-
### Style Injection
104+
### 样式注入
105105

106-
Client-side style injection now injects all styles upfront to ensure consistent behavior between development and extracted mode.
106+
现在客户端的样式注入会在最前面注入所有的样式以确保开发模式和提取模式下行为的一致性。
107107

108-
Note the injection order is still not guaranteed, so you should avoid writing CSS that relies on insertion order.
108+
注意它们注入的顺序仍然是不受担保的,所以你撰写的 CSS 应该避免依赖插入的顺序。
109109

110110
### PostCSS
111111

112-
Vue Loader no longer auto applies PostCSS transforms. To use PostCSS, configure `postcss-loader` the same way you would for normal CSS files.
112+
Vue Loader v15 不再默认应用 PostCSS 变换。想要使用 PostCSS,请像为普通 CSS 文件一样的方式配置 `postcss-loader`
113113

114114
### CSS Modules
115115

116-
CSS Modules now need to be explicitly configured via `css-loader` options. The `module` attribute on `<style>` tags is still needed for locals injection into the component.
116+
CSS Modules 现在需要通过 `css-loader` 选项显式地配置。`<style>` 标签上的 `module` 特性仍然需要用来局部注入到组件中。
117117

118-
The good news is that you can now configure `localIdentName` in one place:
118+
好消息是你现在可以在同一处配置 `localIdentName` 了:
119119

120120
``` js
121121
{
@@ -141,13 +141,13 @@ The good news is that you can now configure `localIdentName` in one place:
141141
}
142142
```
143143

144-
If you only want to use CSS Modules in some of your Vue components, you can use a `oneOf` rule and check for the `module` string in resourceQuery:
144+
如果你只想在某些 Vue 组件中使用 CSS Modules,你可以使用 `oneOf` 规则并在 `resourceQuery` 字符串中检查 `module` 字符串:
145145

146146
``` js
147147
{
148148
test: /\.css$/,
149149
oneOf: [
150-
// this matches <style module>
150+
// 这里匹配 `<style module>`
151151
{
152152
resourceQuery: /module/,
153153
use: [
@@ -161,7 +161,7 @@ If you only want to use CSS Modules in some of your Vue components, you can use
161161
}
162162
]
163163
},
164-
// this matches plain <style> or <style scoped>
164+
// 这里匹配普通的 `<style>` 或 `<style scoped>`
165165
{
166166
use: [
167167
'vue-style-loader',
@@ -172,9 +172,9 @@ If you only want to use CSS Modules in some of your Vue components, you can use
172172
}
173173
```
174174

175-
## CSS Extraction
175+
## CSS 提取
176176

177-
Works the same way as you'd configure it for normal CSS. Example usage with [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin):
177+
用法和你为普通 CSS 的配置一样。示例用法在 [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin)
178178

179179
``` js
180180
{
@@ -186,7 +186,7 @@ Works the same way as you'd configure it for normal CSS. Example usage with [min
186186
},
187187
{
188188
test: /\.css$/,
189-
// or ExtractTextWebpackPlugin.extract(...)
189+
// 或 `ExtractTextWebpackPlugin.extract(...)`
190190
use: [
191191
MiniCssExtractPlugin.loader,
192192
'css-loader'
@@ -202,28 +202,28 @@ Works the same way as you'd configure it for normal CSS. Example usage with [min
202202
}
203203
```
204204

205-
## SSR externals
205+
## 服务端渲染的外置
206206

207-
In SSR, we typically use `webpack-node-externals` to exclude npm dependencies from the server build. If you need to import CSS from an npm dependency, the previous solution was using a whitelist like this:
207+
在服务端渲染中,我们通常使用 `webpack-node-externals` 来从服务端构建中排除 npm 依赖。如果你需要从一个 npm 依赖导入 CSS,之前的方案是使用像这样的一个白名单:
208208

209209
``` js
210-
// webpack config
210+
// webpack 配置
211211
externals: nodeExternals({
212212
whitelist: /\.css$/
213213
})
214214
```
215215

216-
With v15, imports for `<style src="dep/foo.css">` now has resourceQuery strings appended at the end of the request, so you need to update the above to:
216+
使用 v15,导入 `<style src="dep/foo.css">` 现在会在请求的末尾追加 resourceQuery 字符串,所以你需要将上述内容更新为:
217217

218218
``` js
219219
externals: nodeExternals({
220220
whitelist: [/\.css$/, /\?vue&type=style/]
221221
})
222222
```
223223

224-
## Options Deprecation
224+
## 废弃的选项
225225

226-
The following options have been deprecated and should be configured using normal webpack module rules:
226+
下列选项已经被废弃了,它们应该使用普通的 webpack 模块的规则来配置:
227227

228228
- `loader`
229229
- `preLoaders`
@@ -234,20 +234,20 @@ The following options have been deprecated and should be configured using normal
234234
- `extractCSS`
235235
- `template`
236236

237-
The following options have been deprecated and should be configured using the new `compilerOptions` option:
237+
下列选项已经被废弃了,它们应该使用新的 `compilerOptions` 选项来配置:
238238

239-
- `preserveWhitespace` (use `compilerOptions.preserveWhitespace`)
240-
- `compilerModules` (use `compilerOptions.modules`)
241-
- `compilerDirectives` (use `compilerOptions.directives`)
239+
- `preserveWhitespace` (使用 `compilerOptions.preserveWhitespace`)
240+
- `compilerModules` (使用 `compilerOptions.modules`)
241+
- `compilerDirectives` (使用 `compilerOptions.directives`)
242242

243-
The following option has been renamed:
243+
下列选项已经被改名了:
244244

245-
- `transformToRequire` (now renamed to `transformAssetUrls`)
245+
- `transformToRequire` (现象改名为 `transformAssetUrls`)
246246

247-
The following option has been changed to resourceQuery:
247+
下列选项已经被改为 `resourceQuery`
248248

249-
- `shadowMode` (now use inline resource queries, e.g. `foo.vue?shadow`)
249+
- `shadowMode` (现在使用内联资源查询语句,例如 `foo.vue?shadow`)
250250

251251
:::tip
252-
For a complete list of new options, see [Options Reference](./options.md).
252+
想查阅新选项的完整列表,请移步[选项参考](./options.md)
253253
:::

0 commit comments

Comments
 (0)