-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
executable file
·114 lines (111 loc) · 3.25 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HappyPack = require('happypack');
var debug = true;
var src = 'build';
var publicPath = '';
var serverDomain = '';
module.exports = {
devServer: {//webpack 服务器配置信息
// historyApiFallback: true,//是否启动404页面跳转至index.html文件
host : '0.0.0.0',//服务器地址。0.0.0.0为所有ip地址都可以访问
port : '8010',//端口
contentBase: __dirname,//服务器跟目录地址
},
entry : {
'mis/index': __dirname + "/src/mis/routers/mis.app.js",//入口
},
output : {
publicPath: publicPath,//静态文件顶部相对位置
path : path.join(__dirname, src),//服务器目录相对路径
filename : "[name].js",//输出模块文件
// chunkFilename: 'app/chunk/[name].[chunkhash:8].chunk.js'//拆包配置
},
module : {
noParse: [/mis\/js/, /mis\/q/],//排除目录
loaders: [{
test : /\.js$/,
loader : 'babel-loader',
exclude: /node_modules/,
query : {
plugins: [
"transform-decorators-legacy",
[
"import",
{
libraryName: "antd",
style : "css"
}
]
],
presets: ['react', 'es2015', 'stage-0']
},
happy : { id: 'js1' },
}, {
test : /\.css$/,
loader: ExtractTextPlugin.extract("style", "css!autoprefixer"),
// happy : { id: 'css' },
}, {
test : /\.scss$/,
loader: ExtractTextPlugin.extract("style", "css!autoprefixer!sass"),
// happy : { id: 'css' },
}, {
test : /\.less$/,
loader: ExtractTextPlugin.extract("style", "css!autoprefixer!less")
}, {
test : /.(png)|(jpg)|(jpeg)$/,
loader: "url?limit=50000,name=img/[hash:8].[name].[ext]",
// happy : { id: 'img' },
}]
},
resolve : {
extensions: ['', '.js', '.json']
},
externals: {},//设置全局变量
plugins : [
new HappyPack({
id : 'js1',
threads: 4,
}),//多线程
new ExtractTextPlugin("css/[name].css"),//抽出CSS
new webpack.NoErrorsPlugin(),//不报错
new HtmlWebpackPlugin({//输出HTML配置
filename : 'index.html',
domain : serverDomain,
hash : true,
// chunks : ['mis/index'],
// excludeChunks: [],
template : __dirname + '/src/index.html',
inject : 'body' // Inject all scripts into the body (this is the default so you can skip it)
}),
].concat(!debug ? [
new webpack.optimize.UglifyJsPlugin({//压缩
compress: {
warnings : false,
drop_debugger: true,
drop_console : true
}
}),
function () {
var deleteFolderRecursive = function (path) {//清空目录
var files = [];
if (fs.existsSync(path)) {
files = fs.readdirSync(path);
files.forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.statSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
deleteFolderRecursive(path.join(__dirname, "build/"));
}
] : [])
};