Skip to content

Commit 19bfcc2

Browse files
Jinjiangkazupon
authored andcommittedFeb 26, 2018
[docs][zh-cn] synced recent updates (#1150)
* [docs][zh-cn] synced recent updates from #436ac94 to #46558ce * Update linting.md
1 parent 5c2ba0b commit 19bfcc2

File tree

12 files changed

+45
-362
lines changed

12 files changed

+45
-362
lines changed
 

‎docs/zh-cn/SUMMARY.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- [生产环境构建](workflow/production.md)
1919
- [代码检验](workflow/linting.md)
2020
- [测试](workflow/testing.md)
21-
- [使用 Mock 测试](workflow/testing-with-mocks.md)
2221
- [选项参考](options.md)
2322
- [loaders](options.md#loaders)
2423
- [preLoaders](options.md#preloaders)
@@ -33,4 +32,4 @@
3332
- [transformToRequire](options.md#transformtorequire)
3433
- [buble](options.md#buble)
3534
- [extractCSS](options.md#extractcss)
36-
- [optimizeSSR](options.md#optimizessr)
35+
- [optimizeSSR](options.md#optimizessr)

‎docs/zh-cn/configurations/advanced.md

-25
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
> 注意 `preLoaders``postLoaders` 只在 10.3.0+ 版本支持
1414
15-
### webpack 2.x
16-
1715
``` js
1816
module.exports = {
1917
// other options...
@@ -54,27 +52,4 @@ module.exports = {
5452
}
5553
```
5654

57-
### webpack 1.x
58-
59-
``` js
60-
// webpack.config.js
61-
module.exports = {
62-
// other options...
63-
module: {
64-
loaders: [
65-
{
66-
test: /\.vue$/,
67-
loader: 'vue'
68-
}
69-
]
70-
},
71-
// `vue-loader` configurations
72-
vue: {
73-
loaders: {
74-
// same configuration rules as above
75-
}
76-
}
77-
}
78-
```
79-
8055
进阶配置更实际的用法是[提取组件中的 CSS 到单个文件](./extract-css.md)

‎docs/zh-cn/configurations/custom-blocks.md

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ comp-a h2 {
4242
#### webpack.config.js
4343

4444
``` js
45-
// webpack 2.x
4645
var ExtractTextPlugin = require("extract-text-webpack-plugin")
4746

4847
module.exports = {

‎docs/zh-cn/configurations/extract-css.md

-36
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ module.exports = {
3939

4040
将所有 Vue 组件中的所有已处理的 CSS 提取为单个 CSS 文件配置示例:
4141

42-
### webpack 2.x
43-
44-
4542
``` js
4643
// webpack.config.js
4744
var ExtractTextPlugin = require("extract-text-webpack-plugin")
@@ -69,36 +66,3 @@ module.exports = {
6966
]
7067
}
7168
```
72-
73-
### webpack 1.x
74-
75-
``` bash
76-
npm install extract-text-webpack-plugin --save-dev
77-
```
78-
79-
``` js
80-
// webpack.config.js
81-
var ExtractTextPlugin = require("extract-text-webpack-plugin")
82-
83-
module.exports = {
84-
// other options...
85-
module: {
86-
loaders: [
87-
{
88-
test: /\.vue$/,
89-
loader: 'vue'
90-
},
91-
]
92-
},
93-
vue: {
94-
loaders: {
95-
css: ExtractTextPlugin.extract("css"),
96-
// 你还可以引入 <style lang="less"> 或其它语言
97-
less: ExtractTextPlugin.extract("css!less")
98-
}
99-
},
100-
plugins: [
101-
new ExtractTextPlugin("style.css")
102-
]
103-
}
104-
```

‎docs/zh-cn/features/css-modules.md

-11
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ CSS Modules 处理是通过 [css-loader](https://github.com/webpack/css-loader)
8989
你可以使用 `vue-loader``cssModules` 选项去为 `css-loader` 添加 query 配置:
9090

9191
``` js
92-
// webpack 1
93-
vue: {
94-
cssModules: {
95-
// overwrite local ident name
96-
localIdentName: '[path][name]---[local]---[hash:base64:5]',
97-
// enable camelCase
98-
camelCase: true
99-
}
100-
}
101-
102-
// webpack 2
10392
module: {
10493
rules: [
10594
{

‎docs/zh-cn/features/postcss.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,7 @@
2727

2828
或者,你可以使用 `vue-loader``postcss` 选项来为 `.vue` 文件指定配置。
2929

30-
webpack 1.x 例子:
31-
32-
``` js
33-
// webpack.config.js
34-
module.exports = {
35-
// 其它配置……
36-
vue: {
37-
// 使用自定义 PostCSS 插件
38-
postcss: [require('postcss-cssnext')()]
39-
}
40-
}
41-
```
42-
43-
webpack 2.x 例子:
30+
示例:
4431

4532
``` js
4633
// webpack.config.js

‎docs/zh-cn/options.md

+24-35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# 选项参考
22

3-
## webpack 1 和 2 之间的使用差异
4-
5-
webpack 2:配置直接放到 loader rule 中。
3+
## 选项放在哪里
64

75
``` js
86
module.exports = {
@@ -21,20 +19,9 @@ module.exports = {
2119
}
2220
```
2321

24-
webpack 1.x:在 webpack 配置中添加根节点 `vue` 块。
25-
26-
``` js
27-
module.exports = {
28-
// ...
29-
vue: {
30-
// `vue-loader` options
31-
}
32-
}
33-
```
34-
3522
### loaders
3623

37-
- 类型:`{ [lang: string]: string }`
24+
- 类型:`{ [lang: string]: string | Object | Array }`
3825

3926
指定 webpack loader 对象覆盖用于 `*.vue` 文件内的语言块的默认 loader。如果指定,该键对应于语言块的 `lang` 属性。每种类型的默认 `lang` 是:
4027

@@ -45,7 +32,6 @@ module.exports = {
4532
例如,使用 `babel-loader``eslint-loader` 处理所有的 `<script>` 块:
4633

4734
``` js
48-
// webpack 2.x config
4935
module: {
5036
rules: [
5137
{
@@ -61,17 +47,36 @@ module.exports = {
6147
}
6248
```
6349

50+
你也可以使用对象或数组的语法 (注意这些选项必须是可序列化的):
51+
52+
``` js
53+
module: {
54+
rules: [
55+
{
56+
test: /\.vue$/,
57+
loader: 'vue-loader',
58+
options: {
59+
loaders: {
60+
js: [
61+
{ loader: 'cache-loader' },
62+
{ loader: 'babel-loader', options: { presets: ['env'] } }
63+
]
64+
}
65+
}
66+
}
67+
]
68+
}
69+
```
70+
6471
### preLoaders
6572

6673
- 类型:`{ [lang: string]: string }`
67-
- 仅在 10.3.0+ 版本中支持
6874

6975
配置格式和 `loaders` 相同,但是 `preLoaders` 会在默认 loaders 之前处理。你可以用来预处理语言块 - 一个常见用例是用来处理构建时的 i18n。
7076

7177
### postLoaders
7278

7379
- 类型:`{ [lang: string]: string }`
74-
- 仅在 10.3.0+ 版本中支持
7580

7681
配置格式和 `loaders` 相同,但是 `postLoaders` 会在默认 loaders 之后处理。你可以用来后处理语言块。注意这会有些复杂:
7782

@@ -81,11 +86,10 @@ module.exports = {
8186

8287
### postcss
8388

84-
> 注意:在 11.0.0+ 版本中,推荐使用 PostCSS 配置文件代替[用法和 `postcss-loader` 相同](https://github.com/postcss/postcss-loader#usage)
89+
> 注意:这里推荐使用 PostCSS 配置文件代替,这样你的 `.vue` 文件中的样式和普通的 CSS 样式可以共享相同的配置[用法和 `postcss-loader` 相同](https://github.com/postcss/postcss-loader#usage)
8590
8691
- 类型:`Array` or `Function` or `Object`
8792

88-
8993
指定要应用于 `.vue` 文件中 CSS 的自定义 PostCSS 插件。如果使用函数,函数将使用相同的 loader 上下文调用,并返回一个插件数组。
9094

9195
``` js
@@ -207,21 +211,6 @@ module.exports = {
207211
配置例子:
208212

209213
``` js
210-
// webpack 1
211-
vue: {
212-
buble: {
213-
// 启用对象扩展运算符
214-
// 注意:你需要自己提供 Object.assign polyfill!
215-
objectAssign: 'Object.assign',
216-
217-
// turn off the `with` removal
218-
transforms: {
219-
stripWith: false
220-
}
221-
}
222-
}
223-
224-
// webpack 2
225214
module: {
226215
rules: [
227216
{

‎docs/zh-cn/start/setup.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# 创建项目
22

3-
### 使用 `vue-cli`
3+
### 使用 `@vue/cli`
44

5-
推荐用脚手架工具 `vue-cli` 来创建一个使用 `vue-loader` 的项目:
5+
推荐用脚手架工具 `@vue/cli` 来创建一个使用 `vue-loader` 的项目:
66

77
``` bash
8-
npm install -g vue-cli
9-
vue init webpack-simple hello-vue
8+
npm install -g @vue/cli
9+
vue create hello-vue
1010
cd hello-vue
11-
npm install
12-
npm run dev # ready to go!
11+
npm run serve # ready to go!
1312
```

‎docs/zh-cn/workflow/linting.md

+10-56
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
你可能有疑问,在 `.vue` 文件中你怎么检验你的代码,因为它不是 JavaScript。我们假设你使用 [ESLint](https://eslint.org/) (如果你没有使用话,你应该去使用!)。
44

5-
你还需要 [eslint-plugin-html](https://github.com/BenoitZugmeyer/eslint-plugin-html) 来支持提取并检验你的 `.vue` 文件中的 JavaScript。
5+
你还需要官方的 [eslint-plugin-vue](https://github.com/vuejs/eslint-plugin-vue),它支持同时检查你 `.vue` 文件中的模板和脚本。
6+
7+
请确保在你的 ESLint 配置中使用了该插件自身的配置:
68

7-
确保把下面的配置加入到你的 ESLint 配置中:
89
``` json
9-
"plugins": [
10-
"html"
11-
]
10+
{
11+
"extends": [
12+
"plugin:vue/essential"
13+
]
14+
}
1215
```
1316

1417
在命令行这样使用:
@@ -23,68 +26,19 @@ eslint --ext js,vue MyComponent.vue
2326
npm install eslint eslint-loader --save-dev
2427
```
2528

26-
``` js
27-
// webpack.config.js
28-
module.exports = {
29-
// ... other options
30-
module: {
31-
loaders: [
32-
{
33-
test: /\.vue$/,
34-
loader: 'vue!eslint'
35-
}
36-
]
37-
}
38-
}
39-
```
40-
41-
注意 webpack loader 处理顺序是 **从右到左**。确保在 `vue` 之前应用 `eslint`,这样才能检验编译前的代码。
42-
43-
我们需要考虑使用的 NPM 包中的第三方 `.vue` 组件,实际使用中我们希望使用 `vue-loader` 去处理第三方组件,但是不想检验它们。我们需要把 lint 配置到 webpack 的 [preLoaders](https://webpack.github.io/docs/loaders.html#loader-order) 中:
44-
45-
``` js
46-
// webpack.config.js
47-
module.exports = {
48-
// ... other options
49-
module: {
50-
// only lint local *.vue files
51-
preLoaders: [
52-
{
53-
test: /\.vue$/,
54-
loader: 'eslint',
55-
exclude: /node_modules/
56-
}
57-
],
58-
// but use vue-loader for all *.vue files
59-
loaders: [
60-
{
61-
test: /\.vue$/,
62-
loader: 'vue'
63-
}
64-
]
65-
}
66-
}
67-
```
68-
69-
For webpack 2.x:
29+
请确保它应用在了 pre-loader 上:
7030

7131
``` js
7232
// webpack.config.js
7333
module.exports = {
7434
// ... other options
7535
module: {
7636
rules: [
77-
// only lint local *.vue files
7837
{
7938
enforce: 'pre',
80-
test: /\.vue$/,
39+
test: /\.(js|vue)$/,
8140
loader: 'eslint-loader',
8241
exclude: /node_modules/
83-
},
84-
// but use vue-loader for all *.vue files
85-
{
86-
test: /\.vue$/,
87-
loader: 'vue-loader'
8842
}
8943
]
9044
}

‎docs/zh-cn/workflow/production.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@ module.exports = {
1818
NODE_ENV: '"production"'
1919
}
2020
}),
21-
// minify with dead-code elimination
22-
new webpack.optimize.UglifyJsPlugin({
23-
compress: {
24-
warnings: false
25-
}
26-
}),
27-
// optimize module ids by occurrence count
28-
new webpack.optimize.OccurrenceOrderPlugin()
21+
new webpack.optimize.UglifyJsPlugin()
2922
]
3023
}
3124
```
3225

33-
显然,我们不想在开发过程中使用这些配置,所以有几种方法可以解决这个问题:
26+
我们不想在开发过程中使用这些配置,所以有几种方法可以解决这个问题:
3427

3528
1. 使用环境变量动态构建;
3629

0 commit comments

Comments
 (0)
Please sign in to comment.