-
Notifications
You must be signed in to change notification settings - Fork 916
[docs] Chinese translation #1274
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
Changes from 18 commits
ca77b66
b6a067c
14f1336
6dcaf02
e2c5a5d
8b1cc80
1f5eef9
150ee0a
db78dbe
7ab0b4d
a8ae03e
ecbd57e
53174de
1d54dda
3905ea2
887a205
5d20ead
10f9ef2
8c4daf7
234c3b0
bf32823
1544a66
40d7e2f
bc30c08
b556598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,96 @@ | ||
module.exports = { | ||
title: 'Vue Loader', | ||
description: 'Webpack loader for single-file Vue components', | ||
locales: { | ||
'/': { | ||
lang: 'en-US', | ||
title: 'Vue Loader', | ||
description: 'Webpack loader for single-file Vue components' | ||
}, | ||
'/zh/': { | ||
lang: 'zh-CN', | ||
title: 'Vue Loader', | ||
description: '处理 Vue 单文件组件的 Webpack loader' | ||
} | ||
}, | ||
serviceWorker: true, | ||
theme: 'vue', | ||
themeConfig: { | ||
repo: 'vuejs/vue-loader', | ||
docsDir: 'docs', | ||
nav: [ | ||
{ | ||
text: 'Guide', | ||
link: '/guide/' | ||
locales: { | ||
'/': { | ||
label: 'English', | ||
selectText: 'Languages', | ||
editLinkText: 'Edit this page on GitHub', | ||
nav: [ | ||
{ | ||
text: 'Guide', | ||
link: '/guide/' | ||
}, | ||
{ | ||
text: 'SFC Spec', | ||
link: '/spec.html' | ||
}, | ||
{ | ||
text: 'Options Reference', | ||
link: '/options.html' | ||
}, | ||
{ | ||
text: 'Migrating from v14', | ||
link: '/migrating.md' | ||
} | ||
], | ||
sidebar: [ | ||
'/', | ||
'/guide/', | ||
'/guide/asset-url', | ||
'/guide/pre-processors', | ||
'/guide/scoped-css', | ||
'/guide/css-modules', | ||
'/guide/hot-reload', | ||
'/guide/functional', | ||
'/guide/custom-blocks', | ||
'/guide/extract-css', | ||
'/guide/linting', | ||
'/guide/testing' | ||
] | ||
}, | ||
{ | ||
text: 'SFC Spec', | ||
link: '/spec.html' | ||
}, | ||
{ | ||
text: 'Options Reference', | ||
link: '/options.html' | ||
}, | ||
{ | ||
text: 'Migrating from v14', | ||
link: '/migrating.md' | ||
'/zh/': { | ||
label: '简体中文', | ||
selectText: '选择语言', | ||
editLinkText: '在 GitHub 上编辑此页', | ||
nav: [ | ||
{ | ||
text: '指南', | ||
link: '/zh/guide/' | ||
}, | ||
{ | ||
text: '单文件组件规范', | ||
link: '/zh/spec.html' | ||
}, | ||
{ | ||
text: '选项参考', | ||
link: '/zh/options.html' | ||
}, | ||
{ | ||
text: '如何从 v14 迁移', | ||
link: '/zh/migrating.md' | ||
} | ||
], | ||
sidebar: [ | ||
'/zh/', | ||
'/zh/guide/', | ||
'/zh/guide/asset-url', | ||
'/zh/guide/pre-processors', | ||
'/zh/guide/scoped-css', | ||
'/zh/guide/css-modules', | ||
'/zh/guide/hot-reload', | ||
'/zh/guide/functional', | ||
'/zh/guide/custom-blocks', | ||
'/zh/guide/extract-css', | ||
'/zh/guide/linting', | ||
'/zh/guide/testing' | ||
] | ||
} | ||
], | ||
sidebar: [ | ||
'/', | ||
'/guide/', | ||
'/guide/asset-url', | ||
'/guide/pre-processors', | ||
'/guide/scoped-css', | ||
'/guide/css-modules', | ||
'/guide/hot-reload', | ||
'/guide/functional', | ||
'/guide/custom-blocks', | ||
'/guide/extract-css', | ||
'/guide/linting', | ||
'/guide/testing' | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 介绍 | ||
|
||
:::tip 版本注明 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 版本说明? |
||
这份文档是为 Vue Loader v15 及以上版本撰写的。如果你正在从 v14 或更早的版本往这里迁移,请查阅[迁移指南](../migrating.md)。如果你正在使用老版本,其对应的就文档[在此](https://vue-loader-v14.vuejs.org)。 | ||
::: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 其对应的文档在此 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个应该是「旧」误写成了「就」吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我也发现了,因为上一句已经说过了“老”,所以这里可以不用再重复一次。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 认同,我去掉了 |
||
|
||
## Vue Loader 是什么? | ||
|
||
Vue Loader 是一个 [webpack](https://webpack.js.org/) 的 loader,它允许你以一种名为[单文件组件 (SFCs)](./spec.md)的格式撰写 Vue 组件: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 「撰写」一般指的是文档吧?这里建议用「编写」 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. “撰写”相对书面一些,我已经在很多地方使用了撰写这个词 (loader 的文档中搜到了 7 次,其它文档可能更多)。如果不是特别必要的话,我就保留“撰写”了😅 |
||
|
||
``` vue | ||
<template> | ||
<div class="example">{{ msg }}</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data () { | ||
return { | ||
msg: 'Hello world!' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
.example { | ||
color: red; | ||
} | ||
</style> | ||
``` | ||
|
||
Vue Loader 还提供了很多酷炫的特性: | ||
|
||
- 允许为 Vue 组件的每个部分使用其它的 webpack loader,例如在 `<style>` 的部分使用 Sass 和在 `<template>` 的部分使用 Pug; | ||
- 允许在一个 `.vue` 文件中使用自定义块,并对其运用自定义的 loader 链; | ||
- 使用 webpack loader 将 `<style>` 和 `<template>` 中引用的资产当作模块依赖来处理; | ||
- 为每个组件模拟出带作用域的 CSS; | ||
- 在开发过程中可以保持状态的热重载。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在开发过程中使用热重载来保持状态。 |
||
|
||
简而言之,webpack 和 Vue Loader 的结合为你提供了一个撰写 Vue.js 应用的、现代的、灵活的和极致强大的前端工作流。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 编写/开发 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提供了一个现代、灵活且极其强大的前端工作流,来帮助编写 Vue.js 应用。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# 如何起步 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 一般好像就翻译成「起步」? |
||
|
||
## Vue CLI | ||
|
||
如果你没有手动设置 webpack 的兴趣,我们推荐使用 [Vue CLI](https://github.com/vuejs/vue-cli) 直接创建一个项目的脚手架。通过 Vue CLI 创建的项目会预配置好绝大多数的开发需求,它们开箱即用。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果你不想…… There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这样如何? 通过 Vue CLI 创建的项目会针对多数常见的开发需求进行预先配置,做到开箱即用。 |
||
|
||
如果 Vue CLI 提供的内建的配置没有满足你的需求,或者你乐于从零开始创建你自己的 webpack 配置,那么请跟随这份指南。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 提供的内建 那么请继续阅读这篇指南。 |
||
|
||
## 手动配置 | ||
|
||
Vue Loader 的配置和其它的 loader 不太一样。除了通过一条规则将 `vue-loader` 应用到所有扩展名为 `.vue` 的文件上之外,请确认在你的 webpack 配置中添加 Vue Loader 的插件: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 确认 → 确保 |
||
|
||
``` js | ||
// webpack.config.js | ||
const { VueLoaderPlugin } = require('vue-loader') | ||
|
||
module.exports = { | ||
module: { | ||
rules: [ | ||
// ... 其它规则 | ||
{ | ||
test: /\.vue$/, | ||
loader: 'vue-loader' | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
// 请确认引入这个插件! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
new VueLoaderPlugin() | ||
] | ||
} | ||
``` | ||
|
||
**这个插件是必须的!**它的职责是将你定义过的其它规则克隆并应用到 `.vue` 文件里相应语言的块。例如,如果你有一条匹配 `/\.js$` 的规则,那么它会应用到 `.vue` 文件里的 `<script>` 块。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 复制是不是比克隆好一点 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 正则少了结尾的 |
||
|
||
一个更完整的 webpack 配置示例看起来像是如下的样子: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 看起来像这样 |
||
|
||
``` js | ||
// webpack.config.js | ||
const path = require('path') | ||
const { VueLoaderPlugin } = require('vue-loader') | ||
|
||
module.exports = { | ||
mode: 'development', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.vue$/, | ||
loader: 'vue-loader' | ||
}, | ||
// 它会应用到普通的 `.js` 文件 | ||
// 以及 `.vue` 文件中的 `<script>` 块 | ||
{ | ||
test: /\.js$/, | ||
loader: 'babel-loader' | ||
}, | ||
// 它会应用到普通的 `.css` 文件 | ||
// 以及 `.vue` 文件中的 `<style>` 块 | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
'vue-style-loader', | ||
'css-loader' | ||
] | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
// 请确认引入这个插件来实现这些魔力 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 请确保引入这个插件来施展魔法? |
||
new VueLoaderPlugin() | ||
] | ||
} | ||
``` | ||
|
||
你也可以在[选项参考](../options.md)查阅所有可用的 loader 选项。 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 处理资产路径 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我觉得还是用 “资源” 比较好,static assets -> 静态资源 |
||
|
||
当 Vue Loader 编译单文件组件中的 `<template>` 块时,它也会将所有遇到的资产 URL URL 转换为 **webpack 模块请求**。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里的URL重复了 |
||
|
||
例如,下面的模板代码片段 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 例如,下面的模板代码片段:(少了一个冒号) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我确认了一下,英文版本身没有冒号。我两边都加一下好了 |
||
|
||
``` vue | ||
<img src="../image.png"> | ||
``` | ||
|
||
将会被编译成为: | ||
|
||
``` js | ||
createElement('img', { | ||
attrs: { | ||
src: require('../image.png') // 现在这不是一个模块请求 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is now a module request 现在这是一个模块的请求了 |
||
} | ||
}) | ||
``` | ||
|
||
默认下列标签/特性的组合会被转换,且这些组合时可以使用 [transformAssetUrls](../options.md#transformasseturls) 选项进行配置的。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个地方原文写得不太通,「下列」后面并没有列出,其实在链接里。感觉应该是改成「参考……来了解哪些标签/特性的组合会被默认转换,并且可以进行配置」之类的。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 英文版补上了一段 JSON https://github.com/vuejs/vue-loader/pull/1277/files |
||
|
||
额外的,如果你配置了为 `<style>` 块使用 [css-loader](https://github.com/webpack-contrib/css-loader),则你的 CSS 中的资产 URL 也会被同等处理。 | ||
|
||
## 转换规则 | ||
|
||
资产 URL 转换会遵循如下规则: | ||
|
||
- 如果路径是绝对路径 (例如 `/images/foo.png`),会原样保留。 | ||
|
||
- 如果路径以 `.` 开头,将会被看作相对的模块依赖,并按照你的本地文件系统上的目录结构进行解析。 | ||
|
||
- 如果路径以 `~` 开头,其后的部分将会被看作模块依赖。这意味着你可以用该特性来引用一个 node 依赖中的资源: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node |
||
|
||
``` html | ||
<img src="~some-npm-package/foo.png"> | ||
``` | ||
|
||
- 如果路径以 `@` 开头,也会被看作模块依赖。如果你的 webpack 配置中给 `@` 配置了 alias,这就很有用了。所有 `vue-cli` 创建的项目都默认配置了将 `@` 指向 `/src`。 | ||
|
||
## 相关的 Loader | ||
|
||
因为像 `.png` 这样的文件不是一个 JavaScript 模块,你需要配置 webpack 使用 [file-loader](https://github.com/webpack/file-loader) 或者 [url-loader](https://github.com/webpack/url-loader) 去合理的处理它们。通过 Vue CLI 创建的项目已经把这些预配置好了。 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 合理地处理它们(的 => 地) |
||
## 为什么 | ||
|
||
转换资产 URL 的好处是: | ||
|
||
1. `file-loader` 可以指定要复制和放置资源文件的位置,以及如何使用版本哈希命名以获得更好的缓存。此外,这意味着 **你可以就近管理图片文件,可以使用相对路径而不用担心布署时URL问题**。使用正确的配置,webpack 将会在打包输出中自动重写文件路径为正确的URL。 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以使用相对路径而不用担心部署时URL的问题 (布署 => 部署,漏了一个 “的”) |
||
2. `url-loader` 允许你有条件将文件转换为内联的 base-64 URL (当文件小于给定的阈值),这会减少小文件的 HTTP 请求。如果文件大于该阈值,会自动的交给 `file-loader` 处理。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 允许你有条件地 (漏了一个 “地”) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感谢校对,着篇文档其实是从 v14 照搬过来的,我稍后同步修改一下 v14 的文档同样的地方:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webpack → webpack 要统一处理一下么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和 Chris 讨论过这个问题了 vuejs/v2.vuejs.org#1568
中文翻译的部分我们可以保留 webpack,其余的以英文版为准吧
或者中文翻译也用回 Webpack 我的角度都可以接受
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实不光 webpack,还有 npm 也是小写的。在中文里其实没啥歧义,那我们就在中文版里面保留最精确的拼法吧。