-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (36 loc) · 1.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var cssLoader = require('./css-loader')
var toString = Object.prototype.toString
var isFunction = function (val) {
return toString.call(val) === '[object Function]'
}
/**
* @param {object} cooking - provide add, remove, config, _userConfig method
* @param {object} [options]
*/
module.exports = function (cooking) {
var SOURCE_MAP = cooking.config.devtool
cooking.config.vue = cooking.config.vue || {}
// add loader
cooking.add('loader.vue', {
test: /\.vue$/,
loaders: ['vue-loader']
})
// add extension
cooking.config.resolve.extensions.push('.vue')
var plugins = cooking.config.postcss
if (Array.isArray(plugins)) {
cooking.config.vue.postcss = function (webpack) {
return plugins.map(plugin => isFunction(plugin) ? plugin(webpack) : plugin)
}
} else if (plugins) {
cooking.config.vue.postcss = plugins
}
// add vue config
cooking.config.vue.loaders = Object.assign({},
{ js: 'babel-loader' },
cooking.config.vue.loaders,
cssLoader({
sourceMap: SOURCE_MAP ? '#source-map' : false,
extract: !!cooking.config.extractCSS
}))
}