-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
docs(zh): update #2016
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
docs(zh): update #2016
Changes from all commits
a3e03ef
a297b01
082fb40
3759545
9db7786
71ff32f
913be90
35dbf51
77e0697
ae4318c
4083802
5e8b915
e5b45c2
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 |
---|---|---|
|
@@ -234,6 +234,33 @@ export default { | |
<%# END_REPLACE %> | ||
``` | ||
|
||
#### 文件名都极端情况 | ||
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. 文件名的 |
||
|
||
如果你想要渲染一个以点开头的模板文件 (例如 `.env`),则需要遵循一个特殊的命名约定,因为以点开头的文件会在插件发布到 npm 的时候被忽略: | ||
|
||
``` | ||
# 以点开头的模板需要使用下划线取代那个点: | ||
|
||
/generator/template/_env | ||
|
||
# 调用 api.render('./template') 会在项目目录中渲染成为: | ||
|
||
.env | ||
``` | ||
|
||
同时这也意味着当你想渲染以下划线开头的文件时,同样需要遵循一个特殊的命名约定: | ||
|
||
``` | ||
# 这种模板需要使用两个下划线来取代单个下划线: | ||
|
||
/generator/template/__variables.scss | ||
|
||
# 调用 api.render('./template') 会在项目目录中渲染成为: | ||
|
||
_variables.scss | ||
``` | ||
|
||
|
||
### 提示符 | ||
|
||
#### 内建插件的提示符 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# UI API | ||
# UI 插件 API | ||
|
||
这个 cli-ui 暴露一个 API,允许增强项目的配置和任务,也可以分享数据和在进程间进行通信。 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,13 @@ | |
|
||
## browserslist | ||
|
||
你会发现 `package.json` 文件里有一个 `browserlist` 字段,指定里项目的目标浏览器的范围。这个值会被 [@babel/preset-env][babel-preset-env] 和 [Autoprefixer][autoprefixer] 用来确定需要转译的 JavaScript 特性和需要添加的 CSS 浏览器前缀。 | ||
你会发现有 `package.json` 文件里的 `browserlist` 字段 (或一个单独的 `.browserslistrc` 文件),指定了项目的目标浏览器的范围。这个值会被 [@babel/preset-env][babel-preset-env] 和 [Autoprefixer][autoprefixer] 用来确定需要转译的 JavaScript 特性和需要添加的 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. 感觉之前的翻译才对吧,会发现……里有一个……字段 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. 怕歧义的话我觉得也可以意译一下,比如:你可以使用 |
||
|
||
现在查阅[这里][browserslist]了解如何指定浏览器范围。 | ||
|
||
## Polyfill | ||
|
||
一个默认的 Vue CLI 项目会使用 [@vue/babel-preset-app][babel-preset-env],它通过 `@babel/preset-env` 和 `browserslist` 配置来决定项目需要的 polyfill。 | ||
一个默认的 Vue CLI 项目会使用 [@vue/babel-preset-app][babel-preset-app],它通过 `@babel/preset-env` 和 `browserslist` 配置来决定项目需要的 polyfill。 | ||
|
||
默认情况下,它会把 [`useBuiltIns: 'usage'`](https://new.babeljs.io/docs/en/next/babel-preset-env.html#usebuiltins-usage) 传递给 `@babel/preset-env`,这样它会根据源代码中出现的语言特性自动检测需要的 polyfill。这确保了最终包里 polyfill 数量的最小化。然而,这也意味着**如果其中一个依赖需要特殊的 polyfill,默认情况下 Babel 无法将其检测出来。** | ||
|
||
|
@@ -62,6 +62,17 @@ Vue CLI 会产生两个应用的版本:一个现代版的包,面向支持 [E | |
|
||
对于一个 Hello World 应用来说,现代版的包已经小了 16%。在生产环境下,现代版的包通常都会表现出显著的解析速度和运算速度,从而改善应用的加载性能。 | ||
|
||
::: tip 提示 | ||
`<script type="module">` [需要配合始终开启的 CORS 进行加载](https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors)。这意味着你的服务器必须返回诸如 `Access-Control-Allow-Origin: *` 的有效的 CORS 头。如果你想要通过认证来获取脚本,可使用 [corsUseCredentials](../config/#corsusecredentials) 选项。 | ||
|
||
同时,现代浏览器使用一段内联脚本来避免 Safari 10 重复加载脚本包,所以如果你在使用一套严格的 CSP,你需要这样显性地允许内联脚本: | ||
|
||
``` | ||
Content-Security-Policy: script-src 'self' 'sha256-4RS22DYeB7U14dra4KcQYxmwt5HkOInieXK1NUMBmQI=' | ||
``` | ||
::: | ||
|
||
[autoprefixer]: https://github.com/postcss/autoprefixer | ||
[babel-preset-env]: https://new.babeljs.io/docs/en/next/babel-preset-env.html | ||
[babel-preset-app]: https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/babel-preset-app | ||
[browserslist]: https://github.com/ai/browserslist |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,13 +70,15 @@ Web Components 模式不支持 IE11 及更低版本。[更多细节](https://git | |
在 Web Components 模式中,Vue 是*外置的*。这意味着包中不会有 Vue,即便你在代码中导入了 Vue。这里的包会假设在页面中已经有一个可用的全局变量 `Vue`。 | ||
::: | ||
|
||
你可以通过下面的命令将一个单独的入口构建为一个库: | ||
你可以通过下面的命令将一个单独的入口构建为一个 Web Components 组件: | ||
|
||
``` | ||
vue-cli-service build --target wc --name my-element [entry] | ||
``` | ||
|
||
这将会产生一个单独的 JavaScript 文件 (及其压缩后的版本) 将所有的东西都内联起来。当这个脚本被引入网页时,会注册自定义组件 `<my-element>`,其使用 `@vue/web-component-wrapper` 包裹了目标的 Vue 组件。这个包裹器会自动代理属性、特性、事件和插槽。请查阅 [`@vue/web-component-wrapper` 的文档](https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-web-component-wrapper/README.md)了解更多细节。 | ||
注意这里的入口应该是一个 `*.vue` 文件。Vue CLI 将会把这个组件自动包裹并注册为 Web Components 组件,无需在 `main.js` 里做这件事。你也完全可以在开发时以一个 demo app 使用 `main.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. 也可以在开发时把 |
||
|
||
该构建将会产生一个单独的 JavaScript 文件 (及其压缩后的版本) 将所有的东西都内联起来。当这个脚本被引入网页时,会注册自定义组件 `<my-element>`,其使用 `@vue/web-component-wrapper` 包裹了目标的 Vue 组件。这个包裹器会自动代理属性、特性、事件和插槽。请查阅 [`@vue/web-component-wrapper` 的文档](https://github.com/vuejs/vue-docs-zh-cn/blob/master/vue-web-component-wrapper/README.md)了解更多细节。 | ||
|
||
**注意这个包依赖了在页面上全局可用的 `Vue`。** | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,10 +29,18 @@ yarn serve | |
npx vue-cli-service serve | ||
``` | ||
|
||
::: tip 提示 | ||
你可以通过 `vue ui` 命令使用 GUI 运行更多的特性脚本。 | ||
::: | ||
|
||
这里有一个 GUI 的 Webpack Analyzer: | ||
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-cli-service serve | ||
|
||
``` | ||
用法:vue-cli-service serve [options] | ||
用法:vue-cli-service serve [options] [entry] | ||
|
||
选项: | ||
|
||
|
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.
我感觉这里应该写成
`'error'`
,否则会以为是个类型