Skip to content

Commit cdbf8a8

Browse files
Jinjiangyyx990803
authored andcommitted
[docs][zh-cn] synced updates (#1097)
* [zh-cn] Webpack -> webpack and refined testing.md * [docs][zh-cn] synced updates from #cda4973 to #ebd66fe * Update postcss.md * Update testing.md
1 parent aaf724d commit cdbf8a8

File tree

14 files changed

+83
-49
lines changed

14 files changed

+83
-49
lines changed

docs/zh-cn/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@
22

33
### `vue-loader` 是什么?
44

5-
`vue-loader` 是一个 Webpack 的 loader,可以将用下面这个格式编写的 Vue 组件转换为 JavaScript 模块:
5+
`vue-loader` 是一个 webpack 的 loader,可以将用下面这个格式编写的 Vue 组件转换为 JavaScript 模块:
66

77
![screenshot](http://blog.evanyou.me/images/vue-component.png)
88

99
这里有一些 `vue-loader` 提供的很酷的特性:
1010

1111
- 默认支持 ES2015;
12-
- 允许对 Vue 组件的组成部分使用其它 Webpack loader,比如对 `<style>` 使用 SASS 和对 `<template>` 使用 Jade;
12+
- 允许对 Vue 组件的组成部分使用其它 webpack loader,比如对 `<style>` 使用 SASS 和对 `<template>` 使用 Jade;
1313
- `.vue` 文件中允许自定义节点,然后使用自定义的 loader 进行处理;
14-
-`<style>``<template>` 中的静态资源当作模块来对待,并使用 Webpack loader 进行处理;
14+
-`<style>``<template>` 中的静态资源当作模块来对待,并使用 webpack loader 进行处理;
1515
- 对每个组件模拟出 CSS 作用域;
1616
- 支持开发期组件的热重载。
1717

18-
简而言之,编写 Vue.js 应用程序时,组合使用 Webpack`vue-loader` 能带来一个现代,灵活并且非常强大的前端工作流程。
18+
简而言之,编写 Vue.js 应用程序时,组合使用 webpack`vue-loader` 能带来一个现代,灵活并且非常强大的前端工作流程。
1919

20-
### Webpack 是什么?
20+
### webpack 是什么?
2121

22-
如果你已经熟悉了 Webpack,随时可以跳过下面的说明。如果你没有使用过 Webpack,下面是一个快速介绍:
22+
如果你已经熟悉了 webpack,随时可以跳过下面的说明。如果你没有使用过 webpack,下面是一个快速介绍:
2323

24-
[Webpack](https://webpack.github.io/) 是一个模块打包工具。它将一堆文件中的每个文件都作为一个模块,找出它们的依赖关系,将它们打包为可部署的静态资源。
24+
[webpack](https://webpack.github.io/) 是一个模块打包工具。它将一堆文件中的每个文件都作为一个模块,找出它们的依赖关系,将它们打包为可部署的静态资源。
2525

2626
![webpack](https://webpack.github.io/assets/what-is-webpack.png)
2727

28-
一个基本的例子,想像我们有一些 CommonJS 模块,它们不能直接在浏览器中运行,所以我们需要打包成一个文件,这样就可以通过 `<script>` 标签加载。Webpack 可以遵循 `require()` 调用的依赖关系,为我们完成这些工作。
28+
一个基本的例子,想像我们有一些 CommonJS 模块,它们不能直接在浏览器中运行,所以我们需要打包成一个文件,这样就可以通过 `<script>` 标签加载。webpack 可以遵循 `require()` 调用的依赖关系,为我们完成这些工作。
2929

30-
但是 Webpack 可以做的不止这些。通过“loader”,我们可以配置 Webpack 以任何方式去转换所有类型的文件。包括以下例子:
30+
但是 webpack 可以做的不止这些。通过“loader”,我们可以配置 webpack 以任何方式去转换所有类型的文件。包括以下例子:
3131

3232
- 转换 ES2015,CoffeeScript 或者 TypeScript 模块为普通的 ES5 CommonJS 模块;
3333
- 可以选择在编译之前检验你的源代码;
3434
- 将 Jade 模版转换为纯 HTML 并且嵌入 Javascript 字符串中;
3535
- 将 SASS 文件转换为纯 CSS,然后将其转换成 JavaScript 片段,将生成的 CSS 作为 `<style>` 标签插入页面;
3636
- 处理 HTML 或者 CSS 中引用的图片,移动到配置的路径中,并且使用 md5 hash 重命名。
3737

38-
当你理解 Webpack 原理后会感觉它是如此强大,它可以大大优化你的前端工作流程。它主要的缺点是配置复杂麻烦,但是使用本指南,应该可以帮助你找到 Vue.js 和 `vue-loader` 使用时的最常见问题的解决方案。
38+
当你理解 webpack 原理后会感觉它是如此强大,它可以大大优化你的前端工作流程。它主要的缺点是配置复杂麻烦,但是使用本指南,应该可以帮助你找到 Vue.js 和 `vue-loader` 使用时的最常见问题的解决方案。

docs/zh-cn/configurations/advanced.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
> 注意 `preLoaders``postLoaders` 只在 10.3.0+ 版本支持
1414
15-
### Webpack 2.x
15+
### webpack 2.x
1616

1717
``` js
1818
module.exports = {
@@ -54,7 +54,7 @@ module.exports = {
5454
}
5555
```
5656

57-
### Webpack 1.x
57+
### webpack 1.x
5858

5959
``` js
6060
// webpack.config.js

docs/zh-cn/configurations/asset-url.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
createElement('img', { attrs: { src: require('../image.png') }})
1515
```
1616

17-
因为 `.png` 不是一个 JavaScript 文件,你需要配置 Webpack 使用 [file-loader](https://github.com/webpack/file-loader) 或者 [url-loader](https://github.com/webpack/url-loader) 去处理它们。`vue-cli` 脚手器工具已经为你配置好了。
17+
因为 `.png` 不是一个 JavaScript 文件,你需要配置 webpack 使用 [file-loader](https://github.com/webpack/file-loader) 或者 [url-loader](https://github.com/webpack/url-loader) 去处理它们。`vue-cli` 脚手器工具已经为你配置好了。
1818

1919
使用它们的好处:
2020

21-
1. `file-loader` 可以指定要复制和放置资源文件的位置,以及如何使用版本哈希命名以获得更好的缓存。此外,这意味着 **你可以就近管理图片文件,可以使用相对路径而不用担心布署时URL问题**。使用正确的配置,Webpack 将会在打包输出中自动重写文件路径为正确的URL。
21+
1. `file-loader` 可以指定要复制和放置资源文件的位置,以及如何使用版本哈希命名以获得更好的缓存。此外,这意味着 **你可以就近管理图片文件,可以使用相对路径而不用担心布署时URL问题**。使用正确的配置,webpack 将会在打包输出中自动重写文件路径为正确的URL。
2222

2323
2. `url-loader` 允许你有条件将文件转换为内联的 base-64 URL (当文件小于给定的阈值),这会减少小文件的 HTTP 请求。如果文件大于该阈值,会自动的交给 `file-loader` 处理。

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ comp-a h2 {
4242
#### webpack.config.js
4343

4444
``` js
45-
// Webpack 2.x
45+
// webpack 2.x
4646
var ExtractTextPlugin = require("extract-text-webpack-plugin")
4747

4848
module.exports = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939

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

42-
### Webpack 2.x
42+
### webpack 2.x
4343

4444

4545
``` js
@@ -70,7 +70,7 @@ module.exports = {
7070
}
7171
```
7272

73-
### Webpack 1.x
73+
### webpack 1.x
7474

7575
``` bash
7676
npm install extract-text-webpack-plugin --save-dev

docs/zh-cn/configurations/pre-processors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 使用预处理器
22

3-
Webpack 中,所有的预处理器需要匹配对应的 loader。`vue-loader` 允许你使用其它 Webpack loader 处理 Vue 组件的某一部分。它会根据 `lang` 属性自动推断出要使用的 loader。
3+
webpack 中,所有的预处理器需要匹配对应的 loader。`vue-loader` 允许你使用其它 webpack loader 处理 Vue 组件的某一部分。它会根据 `lang` 属性自动推断出要使用的 loader。
44

55
### CSS
66

@@ -87,7 +87,7 @@ npm install coffee-loader --save-dev
8787

8888
### 模版
8989

90-
模版的处理方式略有不同,因为大多数 Webpack 模版处理器 (比如 `pug-loader`) 会返回模版处理函数,而不是编译的 HTML 字符串,我们使用原始的 `pug` 替代 `pug-loader`
90+
模版的处理方式略有不同,因为大多数 webpack 模版处理器 (比如 `pug-loader`) 会返回模版处理函数,而不是编译的 HTML 字符串,我们使用原始的 `pug` 替代 `pug-loader`
9191

9292
``` bash
9393
npm install pug --save-dev
@@ -104,12 +104,12 @@ div
104104
105105
### 行内 Loader Requests
106106

107-
你可以在 `lang` 属性中使用 [Webpack loader requests](https://webpack.github.io/docs/loaders.html#introduction)
107+
你可以在 `lang` 属性中使用 [webpack loader requests](https://webpack.github.io/docs/loaders.html#introduction)
108108

109109
``` html
110110
<style lang="sass?outputStyle=expanded">
111111
/* use sass here with expanded output */
112112
</style>
113113
```
114114

115-
但是,这使你的 Vue 组件只适用于 Webpack,不能与 Browserify 和 [vueify](https://github.com/vuejs/vueify) 一同使用。**如果你打算将你的 Vue 组件作为可重复使用的第三方组件,请避免使用这个语法。**
115+
但是,这使你的 Vue 组件只适用于 webpack,不能与 Browserify 和 [vueify](https://github.com/vuejs/vueify) 一同使用。**如果你打算将你的 Vue 组件作为可重复使用的第三方组件,请避免使用这个语法。**

docs/zh-cn/features/es2015.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export default {
5858

5959
### 转换普通 `.js` 文件
6060

61-
由于 `vue-loader` 只处理 `.vue` 文件,你需要告诉 Webpack 如何使用 `babel-loader` 或者 `buble-loader` 处理普通 `.js` 文件,在 Webpack 中配置 `babel-loader` 或者 `buble-loader`。脚手架工具 `vue-cli` 已经为你做了这些。
61+
由于 `vue-loader` 只处理 `.vue` 文件,你需要告诉 webpack 如何使用 `babel-loader` 或者 `buble-loader` 处理普通 `.js` 文件,在 webpack 中配置 `babel-loader` 或者 `buble-loader`。脚手架工具 `vue-cli` 已经为你做了这些。
6262

6363
### 使用 `.babelrc` 配置 Babel
6464

docs/zh-cn/features/postcss.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,43 @@
44

55
## 使用配置文件
66

7-
`vue-loader` 从 11.0 版本开始支持通过 [`postcss-loader`](https://github.com/postcss/postcss-loader#usage) 自动加载同一个配置文件:
7+
`vue-loader` 支持通过 [`postcss-loader`](https://github.com/postcss/postcss-loader#usage) 自动加载同一个配置文件:
88

99
- `postcss.config.js`
1010
- `.postcssrc`
1111
- `package.json` 中的 `postcss`
1212

1313
使用配置文件允许你在由 `postcss-loader` 处理的普通CSS文件和 `*.vue` 文件中的 CSS 之间共享相同的配置,这是推荐的做法。
1414

15+
## 配合 `postcss-loader` 使用
16+
17+
因为 `vue-loader` 内部通过 PostCSS 处理其样式,你只需要对标准的 CSS 文件应用 `postcss-loader` 即可。即便你的工程中存在 PostCSS 配置文件,也无需在样式块上指定 `lang="postcss"`
18+
19+
有时用户可能只是出于语法高亮的目的使用 `lang="postcss"`。从 13.6.0 开始,如果没有 loader (通过 `vue-loader` 自身的 `loaders` 选项) 显式配置下列 PostCSS 扩展,则它们只会简单的进行 `vue-loader` 的默认 PostCSS 转换:
20+
21+
- `postcss`
22+
- `pcss`
23+
- `sugarss`
24+
- `sss`
25+
1526
## 内联选项
1627

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

19-
Webpack 1.x 例子:
30+
webpack 1.x 例子:
2031

2132
``` js
2233
// webpack.config.js
2334
module.exports = {
2435
// 其它配置……
2536
vue: {
26-
// 使用自定义 postcss 插件
37+
// 使用自定义 PostCSS 插件
2738
postcss: [require('postcss-cssnext')()]
2839
}
2940
}
3041
```
3142

32-
Webpack 2.x 例子:
43+
webpack 2.x 例子:
3344

3445
``` js
3546
// webpack.config.js
@@ -66,3 +77,17 @@ module.exports = {
6677
}
6778
}
6879
```
80+
81+
### 禁止自动加载配置文件
82+
83+
在 13.6.0+ 版本中,自动加载 PostCSS 配置文件可以通过指定 `postcss.useConfigFile: false` 来禁用:
84+
85+
``` js
86+
postcss: {
87+
useConfigFile: false,
88+
plugins: [/* ... */],
89+
options: {/* ... */}
90+
}
91+
```
92+
93+
这样做会使得 `*.vue` 文件内部的 PostCSS 配置完全由内联配置所控制。

docs/zh-cn/options.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# 选项参考
22

3-
## Webpack 1 和 2 之间的使用差异
3+
## webpack 1 和 2 之间的使用差异
44

5-
Webpack 2:配置直接放到 loader rule 中。
5+
webpack 2:配置直接放到 loader rule 中。
66

77
``` js
88
module.exports = {
@@ -21,7 +21,7 @@ module.exports = {
2121
}
2222
```
2323

24-
Webpack 1.x:在 Webpack 配置中添加根节点 `vue` 块。
24+
webpack 1.x:在 webpack 配置中添加根节点 `vue` 块。
2525

2626
``` js
2727
module.exports = {
@@ -36,7 +36,7 @@ module.exports = {
3636

3737
- 类型:`{ [lang: string]: string }`
3838

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

4141
- `<template>`: `html`
4242
- `<script>`: `js`
@@ -45,7 +45,7 @@ module.exports = {
4545
例如,使用 `babel-loader``eslint-loader` 处理所有的 `<script>` 块:
4646

4747
``` js
48-
// Webpack 2.x config
48+
// webpack 2.x config
4949
module: {
5050
rules: [
5151
{
@@ -138,14 +138,23 @@ module.exports = {
138138

139139
向 PostCSS 插件提供上下文。详见 [postcss-loader 文档](https://github.com/postcss/postcss-loader#context-ctx)。
140140

141+
### postcss.useConfigFile
142+
143+
> 13.6.0 新增
144+
145+
- 类型:`boolean`
146+
- 默认值:`true`
147+
148+
设为 `false` 之后可以禁止自动加载 PostCSS 配置文件。
149+
141150
### cssSourceMap
142151

143152
- 类型: `Boolean`
144153
- 默认值: `true`
145154

146155
是否开启 CSS 的 source maps,关闭可以避免 `css-loader` 的 some relative path related bugs 同时可以加快构建速度。
147156

148-
注意,这个值会在 Webpack 配置中没有 `devtool` 的情况下自动设置为 `false`
157+
注意,这个值会在 webpack 配置中没有 `devtool` 的情况下自动设置为 `false`
149158

150159
### esModule
151160

@@ -182,7 +191,7 @@ module.exports = {
182191
- 类型: `{ [tag: string]: string | Array<string> }`
183192
- 默认值: `{ img: 'src', image: 'xlink:href' }`
184193

185-
在模版编译过程中,编译器可以将某些属性,如 `src` 路径,转换为 `require` 调用,以便目标资源可以由 Webpack 处理。默认配置会转换 `<img>` 标签上的 `src` 属性和 SVG`<image>` 标签上的 `xlink:href` 属性。
194+
在模版编译过程中,编译器可以将某些属性,如 `src` 路径,转换为 `require` 调用,以便目标资源可以由 webpack 处理。默认配置会转换 `<img>` 标签上的 `src` 属性和 SVG`<image>` 标签上的 `xlink:href` 属性。
186195

187196
### buble
188197

docs/zh-cn/start/spec.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default {
5656

5757
- 每个 `.vue` 文件最多包含一个 `<script>` 块。
5858

59-
- 该脚本在类 CommonJS 环境中执行 (就像通过 Webpack 打包的正常 js 模块),这意味这你可以 `require()` 其它依赖。在 ES2015 支持下,你也可以使用 `import``export` 语法。
59+
- 该脚本在类 CommonJS 环境中执行 (就像通过 webpack 打包的正常 js 模块),这意味这你可以 `require()` 其它依赖。在 ES2015 支持下,你也可以使用 `import``export` 语法。
6060

6161
- 脚本必须导出 Vue.js 组件对象。也可以导出由 `Vue.extend()` 创建的扩展对象,但是普通对象是更好的选择。
6262

@@ -68,13 +68,13 @@ export default {
6868

6969
- `<style>` 标签可以有 `scoped` 或者 `module` 属性 (查看 [CSS 作用域](../features/scoped-css.md)[CSS Modules](../features/css-modules.md)) 以帮助你将样式封装到当前组件。具有不同封装模式的多个 `<style>` 标签可以在同一个组件中混合使用。
7070

71-
- 默认情况下,将会使用 `style-loader` 提取内容,并通过 `<style>` 标签动态加入文档的 `<head>` 中,也可以[配置 Webpack 将所有 styles 提取到单个 CSS 文件中](../configurations/extract-css.md)
71+
- 默认情况下,将会使用 `style-loader` 提取内容,并通过 `<style>` 标签动态加入文档的 `<head>` 中,也可以[配置 webpack 将所有 styles 提取到单个 CSS 文件中](../configurations/extract-css.md)
7272

7373
### 自定义块
7474

7575
> 只在 vue-loader 10.2.0+ 中支持
7676
77-
可以在 `.vue` 文件中添加额外的自定义块来实现项目的特定需求,例如 `<docs>` 块。`vue-loader` 将会使用标签名来查找对应的 webpack loader 来应用在对应的块上。Webpack loader 需要在 `vue-loader` 的选项 `loaders` 中指定。
77+
可以在 `.vue` 文件中添加额外的自定义块来实现项目的特定需求,例如 `<docs>` 块。`vue-loader` 将会使用标签名来查找对应的 webpack loader 来应用在对应的块上。webpack loader 需要在 `vue-loader` 的选项 `loaders` 中指定。
7878

7979
更多细节,查看[自定义块](../configurations/custom-blocks.md)
8080

docs/zh-cn/workflow/linting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ module.exports = {
3838
}
3939
```
4040

41-
注意 Webpack loader 处理顺序是 **从右到左**。确保在 `vue` 之前应用 `eslint`,这样才能检验编译前的代码。
41+
注意 webpack loader 处理顺序是 **从右到左**。确保在 `vue` 之前应用 `eslint`,这样才能检验编译前的代码。
4242

43-
我们需要考虑使用的 NPM 包中的第三方 `.vue` 组件,实际使用中我们希望使用 `vue-loader` 去处理第三方组件,但是不想检验它们。我们需要把 lint 配置到 Webpack[preLoaders](https://webpack.github.io/docs/loaders.html#loader-order) 中:
43+
我们需要考虑使用的 NPM 包中的第三方 `.vue` 组件,实际使用中我们希望使用 `vue-loader` 去处理第三方组件,但是不想检验它们。我们需要把 lint 配置到 webpack[preLoaders](https://webpack.github.io/docs/loaders.html#loader-order) 中:
4444

4545
``` js
4646
// webpack.config.js
@@ -66,7 +66,7 @@ module.exports = {
6666
}
6767
```
6868

69-
For Webpack 2.x:
69+
For webpack 2.x:
7070

7171
``` js
7272
// webpack.config.js

docs/zh-cn/workflow/production.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ module.exports = {
3434

3535
1. 使用环境变量动态构建;
3636

37-
2. 或者,使用两个分开的 Webpack 配置文件,一个用于开发环境,一个用于生产环境。把可能共用的配置放到第三个文件中,如 [vue-hackernews-2.0](https://github.com/vuejs/vue-hackernews-2.0) 所示。
37+
2. 或者,使用两个分开的 webpack 配置文件,一个用于开发环境,一个用于生产环境。把可能共用的配置放到第三个文件中,如 [vue-hackernews-2.0](https://github.com/vuejs/vue-hackernews-2.0) 所示。
3838

3939
只要达到目标,怎么做取决于你。

docs/zh-cn/workflow/testing-with-mocks.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
`vue-loader` 提供了一个可以使用 [inject-loader](https://github.com/plasticine/inject-loader) 将任意依赖项注入到 `*.vue` 组件的特性。大体思路是:我们使用 `inject-loader` 为该模块创建一个 “模块工厂” 功能,而不是直接导入组件模块。当使用 mock 对象调用此函数时,它会返回模块的实例,并注入到 mock 中。
66

7+
> 注意:你必须在注入模式下禁用 `esModule` 选项,否则会报错。
8+
79
假设我们有一个这样的组件:
810

911
``` html
@@ -14,9 +16,9 @@
1416

1517
<script>
1618
// this dependency needs to be mocked
17-
import SomeService from '../service'
19+
const SomeService = require('../service')
1820
19-
export default {
21+
module.exports = {
2022
data () {
2123
return {
2224
msg: SomeService.msg
@@ -28,10 +30,8 @@ export default {
2830

2931
以下是使用 mock 导入的方法:
3032

31-
> 注意: [email protected] 当前是不稳定的。
32-
3333
``` bash
34-
npm install inject-loader@^2.0.0 --save-dev
34+
npm install inject-loader --save-dev
3535
```
3636

3737
``` js

0 commit comments

Comments
 (0)