diff --git a/docs/zh-cn/README.md b/docs/zh-cn/README.md new file mode 100644 index 000000000..6af9d30bb --- /dev/null +++ b/docs/zh-cn/README.md @@ -0,0 +1,38 @@ +# 介绍 + +### `vue-loader` 是什么? + +`vue-loader` 是一个 Webpack 的 loader,可以将用下面这个格式编写的 Vue 组件转换为 JavaScript 模块: + +![screenshot](http://blog.evanyou.me/images/vue-component.png) + +这里有一些 `vue-loader` 提供的很酷的特性: + +- ES2015 默认支持; +- 允许对 Vue 组件的组成部分使用其它 Webpack loaders,比如对 ` +``` + +#### webpack.config.js + +``` js +// Webpack 2.x +var ExtractTextPlugin = require("extract-text-webpack-plugin") + +module.exports = { + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue', + options: { + loaders: { + // 提取 中的内容为原始文本 + 'docs': ExtractTextPlugin.extract('raw-loader'), + } + } + } + ] + }, + plugins: [ + // 输出 docs 到当个文件中 + new ExtractTextPlugin('docs.md') + ] +} +``` diff --git a/docs/zh-cn/configurations/extract-css.md b/docs/zh-cn/configurations/extract-css.md new file mode 100644 index 000000000..796dfcfba --- /dev/null +++ b/docs/zh-cn/configurations/extract-css.md @@ -0,0 +1,70 @@ +# 提取 CSS 到单个文件 + +提取所有 Vue 组件中的 CSS 到单个文件的例子: + +### Webpack 2.x + +``` bash +npm install extract-text-webpack-plugin@2.x --save-dev +``` + +``` js +// webpack.config.js +var ExtractTextPlugin = require("extract-text-webpack-plugin") + +module.exports = { + // other options... + module: { + rules: [ + { + test: /\.vue$/, + loader: 'vue-loader', + options: { + 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 + }) + } + } + } + ] + }, + plugins: [ + new ExtractTextPlugin("style.css") + ] +} +``` + +### Webpack 1.x + +``` bash +npm install extract-text-webpack-plugin --save-dev +``` + +``` js +// webpack.config.js +var ExtractTextPlugin = require("extract-text-webpack-plugin") + +module.exports = { + // other options... + module: { + loaders: [ + { + test: /\.vue$/, + loader: 'vue' + }, + ] + }, + vue: { + loaders: { + css: ExtractTextPlugin.extract("css"), + // you can also include +``` + +在内部,` +``` + +但是,这使你的 Vue 组件只适用于 Webpack,不能与 Browserify and [vueify](https://github.com/vuejs/vueify) 一同使用。**如果你打算将你的 Vue 组件作为可重复使用的第三方组件,请避免使用这个语法。** diff --git a/docs/zh-cn/features/css-modules.md b/docs/zh-cn/features/css-modules.md new file mode 100644 index 000000000..043213e44 --- /dev/null +++ b/docs/zh-cn/features/css-modules.md @@ -0,0 +1,117 @@ +# CSS 模块 + +> 需要 ^9.8.0 + +[CSS 模块](https://github.com/css-modules/css-modules) 是一个用于模块化和组合 CSS的流行系统。`vue-loader` 提供了与 CSS 模块的一流集成,可以作为模拟 CSS 作用域的替代方案。 + +### 使用 + +在你的 ` +``` + +这将为 `css-loader` 打开 CSS 模块模式,生成的 CSS 对象将为组件注入一个名叫 `$style` 的计算属性,你可以在你的模块中使用动态绑定: + +``` html + +``` + +由于它是一个计算属性,它也与 `:class` 的 object/array 语法一起使用: + +``` html + +``` + +你也可以在 JavaScript 访问它: + +``` html + +``` + +请参考 [CSS Modules spec](https://github.com/css-modules/css-modules) 了解更多详细信息 [global exceptions](https://github.com/css-modules/css-modules#exceptions) 和 [composition](https://github.com/css-modules/css-modules#composition). + +### 自定义注入名称 + +在 `.vue` 中你可以定义不止一个 ` + + +``` + +### 配置 `css-loader` Query + +CSS 模块处理是通过 [css-loader](https://github.com/webpack/css-loader)。默认 query 如下: + +``` js +{ + modules: true, + importLoaders: true, + localIdentName: '[hash:base64]' +} +``` + +你可以使用 `vue-loader` 的 `cssModules` 选项去为 `css-loader` 添加 query 配置: + +``` js +// webpack 1 +vue: { + cssModules: { + // overwrite local ident name + localIdentName: '[path][name]---[local]---[hash:base64:5]', + // enable camelCase + camelCase: true + } +} + +// webpack 2 +module: { + rules: [ + { + test: '\.vue$', + loader: 'vue-loader', + options: { + cssModules: { + localIdentName: '[path][name]---[local]---[hash:base64:5]', + camelCase: true + } + } + } + ] +} +``` diff --git a/docs/zh-cn/features/es2015.md b/docs/zh-cn/features/es2015.md new file mode 100644 index 000000000..16f54345a --- /dev/null +++ b/docs/zh-cn/features/es2015.md @@ -0,0 +1,65 @@ +# ES2015 + +当项目中配置了 `babel-loader` 或者 `buble-loader`,`vue-loader` 会使用他们处理所有 `.vue` 文件中的 ` +``` + +我们使用 ES2015 的属性的简洁表示法去定义子组件,`{ ComponentA }` 是 `{ ComponentA: ComponentA }` 的简写,Vue 会自动的将 key 转换为`component-a`,所以你可以在 template 中使用 ``. + +### 在 Templates 中使用 ES2015 + +`.vue` 中的 `