-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.conf.js
68 lines (66 loc) · 2.19 KB
/
webpack.base.conf.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
resolve: {
extensions: ['.js', '.vue'],
alias: {
macarons: 'echarts/theme/macarons.js',
'muse-ui-css': 'muse-ui/dist/muse-ui.css'
}
},
module: {
rules: [{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
css: ExtractTextPlugin.extract({
fallback: "style-loader",
use: generateCssLoaders(['css'])
}),
less: ExtractTextPlugin.extract({
fallback: "style-loader",
use: generateCssLoaders(['css', 'postcss', 'less'])
})
}
}
}, {
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: generateCssLoaders(['css'])
})
},{
test: /\.less$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: generateCssLoaders(['css', 'postcss', 'less'])
})
},{
//文件加载器,处理文件静态资源
test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=fonts/[name].[ext]'
}, {
//图片加载器,雷同file-loader,更适合图片,可以将较小的图片转成base64,减少http请求
//如下配置,将小于8192byte的图片转成base64码
test: /\.(png|jpg|gif)$/,
loader: 'url-loader?limit=8192&name=img/[name].[ext]'
}]
}
}
function generateCssLoaders(loaders){
return loaders.map((name) => {
var sourceMap = process.env.NODE_ENV === "production" ? false : true;
return {
loader: name + '-loader',
options: {
sourceMap
}
}
});
}