forked from Rainmen-xia/wxpay-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
100 lines (91 loc) · 2.84 KB
/
webpack.config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var config;
const { VueLoaderPlugin } = require('vue-loader')
///npm install --save-dev extract-text-webpack-plugin@next
//会下载到+ [email protected]
var ExtractTextPlugin = require('extract-text-webpack-plugin');
//基础配置文件
config = {
mode:'production',
resolve:{
alias:{
'vue':'vue/dist/vue.esm.js'
},
},
entry:path.resolve('examples/entry.js'),
module: {
rules: [
// 转化ES6的语法
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
},{
test: /\.vue$/,
use: 'vue-loader'
},
// 图片转化,小于8K自动转化为base64的编码
{
test: /\.(png|jpg|gif)$/,
use:[{
loader:'url-loader',
options:{
limit:5*1024,
name:'[name].[ext]',
publicPath: "./images/",
outputPath: "images/"
}
}]
}, {// loader sass and css
test: /\.(scss|css)$/,
use: ExtractTextPlugin.extract({
use: [{
loader: "css-loader",
options: {// some options
sourceMap: true,
minimize: true
}
},{
loader: 'sass-loader'
},
{// fix the css3
loader: "postcss-loader",
options: {
sourceMap: true,
plugins: function() {
return [require('autoprefixer')]
}
}
}],
fallback: "style-loader"
})
}
]
},
optimization:{
//公共文件抽离(不加这个插件会出现模块重复加载的情况)
splitChunks:{
// 将公共模块提取,生成名为`vendors`的chunk
name: "vendor",
chunks: "initial",
minSize: 1
}
},
devServer:{
contentBase:'./',
open:true
},
plugins: [
new VueLoaderPlugin(),
new ExtractTextPlugin("styles.css"),
new HtmlWebpackPlugin({
filename:'index.html',
template:path.resolve('examples/index.tpl'),
inject: 'body'
})
],
devtool: 'eval-source-map'
}
module.exports = config;