11# 选项参考
22
3- ## webpack 1 和 2 之间的使用差异
4-
5- webpack 2:配置直接放到 loader rule 中。
3+ ## 选项放在哪里
64
75``` js
86module .exports = {
@@ -21,20 +19,9 @@ module.exports = {
2119}
2220```
2321
24- webpack 1.x:在 webpack 配置中添加根节点 ` vue ` 块。
25-
26- ``` js
27- module .exports = {
28- // ...
29- vue: {
30- // `vue-loader` options
31- }
32- }
33- ```
34-
3522### loaders
3623
37- - 类型:` { [lang: string]: string } `
24+ - 类型:` { [lang: string]: string | Object | Array } `
3825
3926 指定 webpack loader 对象覆盖用于 ` *.vue ` 文件内的语言块的默认 loader。如果指定,该键对应于语言块的 ` lang ` 属性。每种类型的默认 ` lang ` 是:
4027
@@ -45,7 +32,6 @@ module.exports = {
4532 例如,使用 ` babel-loader ` 和 ` eslint-loader ` 处理所有的 ` <script> ` 块:
4633
4734 ``` js
48- // webpack 2.x config
4935 module: {
5036 rules: [
5137 {
@@ -61,17 +47,36 @@ module.exports = {
6147 }
6248 ```
6349
50+ 你也可以使用对象或数组的语法 (注意这些选项必须是可序列化的):
51+
52+ ``` js
53+ module: {
54+ rules: [
55+ {
56+ test: / \. vue$ / ,
57+ loader: ' vue-loader' ,
58+ options: {
59+ loaders: {
60+ js: [
61+ { loader: ' cache-loader' },
62+ { loader: ' babel-loader' , options: { presets: [' env' ] } }
63+ ]
64+ }
65+ }
66+ }
67+ ]
68+ }
69+ ```
70+
6471### preLoaders
6572
6673- 类型:` { [lang: string]: string } `
67- - 仅在 10.3.0+ 版本中支持
6874
6975 配置格式和 ` loaders ` 相同,但是 ` preLoaders ` 会在默认 loaders 之前处理。你可以用来预处理语言块 - 一个常见用例是用来处理构建时的 i18n。
7076
7177### postLoaders
7278
7379- 类型:` { [lang: string]: string } `
74- - 仅在 10.3.0+ 版本中支持
7580
7681 配置格式和 ` loaders ` 相同,但是 ` postLoaders ` 会在默认 loaders 之后处理。你可以用来后处理语言块。注意这会有些复杂:
7782
@@ -81,11 +86,10 @@ module.exports = {
8186
8287### postcss
8388
84- > 注意:在 11.0.0+ 版本中,推荐使用 PostCSS 配置文件代替 。[ 用法和 ` postcss-loader ` 相同] ( https://github.com/postcss/postcss-loader#usage ) 。
89+ > 注意:这里推荐使用 PostCSS 配置文件代替,这样你的 ` .vue ` 文件中的样式和普通的 CSS 样式可以共享相同的配置 。[ 用法和 ` postcss-loader ` 相同] ( https://github.com/postcss/postcss-loader#usage ) 。
8590
8691- 类型:` Array ` or ` Function ` or ` Object `
8792
88-
8993 指定要应用于 ` .vue ` 文件中 CSS 的自定义 PostCSS 插件。如果使用函数,函数将使用相同的 loader 上下文调用,并返回一个插件数组。
9094
9195 ``` js
@@ -207,21 +211,6 @@ module.exports = {
207211 配置例子:
208212
209213 ` ` ` js
210- // webpack 1
211- vue: {
212- buble: {
213- // 启用对象扩展运算符
214- // 注意:你需要自己提供 Object.assign polyfill!
215- objectAssign: 'Object.assign',
216-
217- // turn off the ` with ` removal
218- transforms: {
219- stripWith: false
220- }
221- }
222- }
223-
224- // webpack 2
225214 module: {
226215 rules: [
227216 {
0 commit comments