Skip to content

update Chinese translation #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/zh-cn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

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

但是 Webpack 可以做的不止这些。使用 "loaders",我们可以配置 Webpack 以任何方式去转换所有类型的文件。一些例子包括
但是 Webpack 可以做的不止这些。使用 "loaders",我们可以配置 Webpack 以任何方式去转换所有类型的文件。包括以下例子

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

当你理解 Webpack 原理后会感觉它是如此强大,它可以大大优化你的前端工作流程。它主要的缺点是配置复杂麻烦,但是使用本指南, Vue.js 和 `vue-loader`使用时的常见问题,应该可以帮助你找到解决方案
当你理解 Webpack 原理后会感觉它是如此强大,它可以大大优化你的前端工作流程。它主要的缺点是配置复杂麻烦,但是使用本指南,应该可以帮助你找到 Vue.js 和 `vue-loader` 使用时的最常见问题的解决方案
4 changes: 2 additions & 2 deletions docs/zh-cn/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
- [热重载](features/hot-reload.md)
- 配置
- [预处理器](configurations/pre-processors.md)
- [处理资源路径](configurations/asset-url.md)
- [资源路径处理](configurations/asset-url.md)
- [进阶配置](configurations/advanced.md)
- [提取 CSS 文件](configurations/extract-css.md)
- [自定义块](configurations/custom-blocks.md)
- 工作流程
- [生产环境构建](workflow/production.md)
- [代码检验](workflow/linting.md)
- [测试](workflow/testing.md)
- [使用 Mocks 测试](workflow/testing-with-mocks.md)
- [使用 Mock 测试](workflow/testing-with-mocks.md)
- [选项参考](options.md)
16 changes: 7 additions & 9 deletions docs/zh-cn/configurations/advanced.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Loader 进阶配置

有些时候你想要这样
你有时可能想实现

1. 对语言应用自定义 loader string,而不是让 `vue-loader` 去推断;

2. 覆盖默认语言的内置配置
2. 覆盖默认语言的内置 loader 配置

3. 默认语言预处理或者后处理配置
3. 使用自定义 loader 预处理或后处理特定语言块

为了实现这些,详细说明 `vue-loader` 的 `loaders` 选项:
为此,请指定 `vue-loader` 的 `loaders` 选项:

> 注意 `preLoaders` 和 `postLoaders` 只在版本 >=10.3.0 支持

Expand All @@ -18,7 +18,7 @@
module.exports = {
// other options...
module: {
// module.rules is the same as module.loaders in 1.x
// module.rules 与 1.x中的 module.loaders 相同
rules: [
{
test: /\.vue$/,
Expand All @@ -45,10 +45,8 @@ module.exports = {
postLoaders: {
html: 'babel-loader'
}

         // `excludedPreLoaders` 的内容是正则表达式
         // 你可以用来从 Loader chain 上剔除那些你不需要 vue-loader 处理的 preloader
         // 最常用的就是各种 lint

         // `excludedPreLoaders` 应是正则表达式
         excludedPreLoaders: /(eslint-loader)/
}
}
Expand Down
10 changes: 5 additions & 5 deletions docs/zh-cn/configurations/asset-url.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 处理资源路径
# 资源路径处理

默认情况下,`vue-loader` 使用 [css-loader](https://github.com/webpack/css-loader) 和 Vue 模版编译器自动处理你的样式和模版文件。在处理过程中,所有的资源路径例如 `<img src="...">`, `background: url(...)` 和 `@import` **会作为模块依赖**。
默认情况下,`vue-loader` 使用 [css-loader](https://github.com/webpack/css-loader) 和 Vue 模版编译器自动处理你的样式和模版文件。在编译过程中,所有的资源路径例如 `<img src="...">`, `background: url(...)` 和 `@import` **会作为模块依赖**。

例如,`url(./image.png)` 会被转换为 `require('./image.png')`,

Expand All @@ -14,10 +14,10 @@
createElement('img', { attrs: { src: require('../image.png') }})
```

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

使用它们的好处:

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

2. `url-loader` 允许你设置转换为内联 base64 的文件最小值,这会减少小文件的 HTTP 请求。如果文件大于设置值,会自动的交给 `file-loader` 处理。
2. `url-loader` 允许你有条件将文件转换为内联的 base-64 URL(当文件小于给定的阈值),这会减少小文件的 HTTP 请求。如果文件大于该阈值,会自动的交给 `file-loader` 处理。
7 changes: 4 additions & 3 deletions docs/zh-cn/configurations/custom-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

> 在大于 10.2.0 中支持

在 `.vue` 文件中,你可以自定义语言块。自定义块将会被 `vue-loader` 选项 `loaders` 中指定的 loaders 处理,然后被组件模块依赖。配置类似 [Loader 进阶配置](../configurations/advanced.md),除了匹配使用的是标签名称,而不是 `lang` 属性。
在 `.vue` 文件中,你可以自定义语言块。自定义块的内容将由 `vue-loader` 的 options 中的 `loader` 对象中指定的 loader 处理,然后被组件模块依赖。类似 [Loader 进阶配置](../configurations/advanced.md)中的配置,但使用的是标签名匹配,而不是 `lang` 属性。

如果 loader 匹配到自定义块,它会被处理;其它情况会被忽略。
如果找到一个自定义块的 matching loader,该自定义块将被处理; 否则自定义块将被忽略。
另外,如果找到的 loader 返回一个函数,该函数将以 `* .vue` 文件的组件作为参数来调用。

## 例子

这个例子是提取自定义块 `<docs>` 的内容到单个 docs 文件中
这是提取自定义块 `<docs>` 的内容到单个 docs 文件中的例子

#### component.vue

Expand Down
46 changes: 40 additions & 6 deletions docs/zh-cn/configurations/extract-css.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
# 提取 CSS 到单个文件

提取所有 Vue 组件中的 CSS 到单个文件的例子:

### Webpack 2.x

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

## 简单的方法

> requires vue-loader@^12.0.0 and webpack@^2.0.0

``` js
// webpack.config.js
var ExtractTextPlugin = require("extract-text-webpack-plugin")

module.exports = {
// other options...
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: true
}
}
]
},
plugins: [
new ExtractTextPlugin("style.css")
]
}
```

上述内容将自动处理 `*.vue` 文件内的 `<style>` 提取,并与大多数预处理器一样开箱即用。

注意这只是提取 `*.vue` 文件 - 但在 JavaScript 中导入的 CSS 仍然需要单独配置。

## 手动配置

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

### Webpack 2.x


``` js
// webpack.config.js
var ExtractTextPlugin = require("extract-text-webpack-plugin")
Expand All @@ -23,7 +57,7 @@ module.exports = {
loaders: {
css: ExtractTextPlugin.extract({
use: 'css-loader',
fallback: 'vue-style-loader' // <- this is a dep of vue-loader, so no need to explicitly install if using npm3
fallback: 'vue-style-loader' // <- 这是vue-loader的依赖,所以如果使用npm3,则不需要显式安装
})
}
}
Expand Down Expand Up @@ -59,7 +93,7 @@ module.exports = {
vue: {
loaders: {
css: ExtractTextPlugin.extract("css"),
// you can also include <style lang="less"> or other langauges
// 你还可以引入 <style lang="less"> 或其它语言
less: ExtractTextPlugin.extract("css!less")
}
},
Expand Down
4 changes: 2 additions & 2 deletions docs/zh-cn/features/css-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</style>
```

这将为 `css-loader` 打开 CSS 模块模式,生成的 CSS 对象将为组件注入一个名叫 `$style` 的计算属性,你可以在你的模块中使用动态绑定
这将为 `css-loader` 打开 CSS 模块模式,生成的 CSS 对象将为组件注入一个名叫 `$style` 的计算属性,你可以在你的模块中使用动态 class 绑定

``` html
<template>
Expand All @@ -29,7 +29,7 @@
</template>
```

由于它是一个计算属性,它也与 `:class` 的 object/array 语法一起使用
由于它是一个计算属性,它也适用于 `:class` 的 object/array 语法

``` html
<template>
Expand Down
8 changes: 4 additions & 4 deletions docs/zh-cn/features/es2015.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ES2015

当项目中配置了 `babel-loader` 或者 `buble-loader`,`vue-loader` 会使用他们处理所有 `.vue` 文件中的 `<script>` 部分,允许我们在 Vue 组件中使用 ES2015,如果你还没有使用 ES2015,你应该使用它,下面是一些好的学习资源
当项目中配置了 `babel-loader` 或者 `buble-loader`,`vue-loader` 会使用他们处理所有 `.vue` 文件中的 `<script>` 部分,允许我们在 Vue 组件中使用 ES2015,如果你还没有使用 ES2015,你应该使用它,这有一些不错的学习资源

- [Babel - Learn ES2015](https://babeljs.io/docs/learn-es2015/)
- [ES6 Features](https://github.com/lukehoban/es6features)
Expand Down Expand Up @@ -54,12 +54,12 @@ export default {
</my-component>
```

你还可以使用[`buble` 选项]../ options.mdbuble自定义模板中支持的功能。
你还可以使用 [`buble` 选项](../options.md#buble) 自定义模板中支持的功能。

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

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

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

`babel-loader` 遵守 [`.babelrc`](https://babeljs.io/docs/usage/babelrc/),因此这是推荐配置 Babel presets 和插件的方法
`babel-loader` 遵守 [`.babelrc`](https://babeljs.io/docs/usage/babelrc/),因此这是配置 Babel presets 和插件推荐的方法
4 changes: 2 additions & 2 deletions docs/zh-cn/features/hot-reload.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 热重载

"热重载"不是当你修改文件的时候简单重新加载页面。启用热重载后,当你修改 `.vue` 文件时,所有该组件的实例会被替换,**并且不需要刷新页面**。它甚至保持应用程序和修改组件的当前状态!当你调整模版或者修改样式时,这极大的提高了开发体验。
"热重载"不是当你修改文件的时候简单重新加载页面。启用热重载后,当你修改 `.vue` 文件时,所有该组件的实例会被替换,**并且不需要刷新页面**。它甚至保持应用程序和被替换组件的当前状态!当你调整模版或者修改样式时,这极大的提高了开发体验。

![hot-reload](http://blog.evanyou.me/images/vue-hot.gif)

当使用脚手架工具 `vue-cli` 时,热重载是开箱即用的。
当使用脚手架工具 `vue-cli` 时,热重载是开箱即用的。
6 changes: 3 additions & 3 deletions docs/zh-cn/features/postcss.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- `.postcssrc`
- `package.json` 中的 `postcss`

使用配置文件允许一份配置用于处理普通 CSS 文件(通过`postcss-loader`),和 `.vue` 文件内的 CSS,这是推荐做法
使用配置文件允许你在由 `postcss-loader` 处理的普通CSS文件和 `*.vue` 文件中的 CSS 之间共享相同的配置,这是推荐的做法

## 内联选项

Expand Down Expand Up @@ -54,9 +54,9 @@ module.exports = {

除了插件数组之外,`postcss` 配置选项也接受:

- 一个返回插件数组的函数
- 返回插件数组的函数

- 一个对象包含配置选项,传递给 PostCSS 处理器。这在使用自定义 parser/stringifiers 时非常有用:
- 要传递给 PostCSS 处理器的包含 options 的对象。当你使用的 PostCSS 项目依赖自定义 `parser/stringifiers`时,这很有用:

``` js
postcss: {
Expand Down
7 changes: 3 additions & 4 deletions docs/zh-cn/features/scoped-css.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
</style>
```

2. 子组件的根节点将同时受父组件作用域和子组件作用域的影响
2. 子组件的根节点将同时受父组件和子组件作用域 CSS 的影响

3. 部分元素不受作用域影响部分
3. Partials 不受作用域样式影响

4. **CSS 作用域不能代C替 classes**。考虑到浏览器渲染各种 CSS 选择器的方式,`p { color: red }` 在作用域中会慢很多(即转换为属性选择器)。如果你使用 classes 或者 ids 代替,比如 `.example { color: red }`,这样几乎没有性能影响。[Here's a playground](http://stevesouders.com/efws/css-selectors/csscreate.php) 你可以测试它们的不同。
4. **CSS 作用域不能代替 classes**。考虑到浏览器渲染各种 CSS 选择器的方式,当使用 scoped 时,`p { color: red }` 在作用域中会慢很多倍(即当与属性选择器组合时)。如果你使用 classes 或者 ids 代替,比如 `.example { color: red }`,这样几乎没有性能影响。[Here's a playground](http://stevesouders.com/efws/css-selectors/csscreate.php) 你可以测试它们的不同。

5. **在递归组件中小心使用后代选择器!** 对于带有选择器 `.a .b` 的CSS 规则,如果元素 `.a` 包含递归子组件,所有的子组件中的 `.b` 会被匹配。

Loading