-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
92 lines (84 loc) · 2.59 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
const path = require('path'),
webpack = require('webpack'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
CleanWebpackPlugin = require('clean-webpack-plugin'),
NgAnnotatePlugin = require('ng-annotate-webpack-plugin');
//获取编译时设置的环境变量,去除变量字符串的前后空格,方便字符串比较
const BUILD_ENV = process.env.BUILD_ENV.replace(/(^\s*)|(\s*$)/g, "");
//判断当前执行命令设置的环境
const isDev = BUILD_ENV === "dev";
const isRelease = BUILD_ENV === "release";
//webpack配置对象
const config = {
entry: {
"vendor": ["angular", "angular-ui-router"],
"index": __dirname + "/src/scripts/bootstraps/indexBootstrap.js"
},
output: {
path: __dirname + "/build",
publicPath: '/',
filename: "[name].bundle.js",
chunkFilename: "[name].bundle.js"
}
};
//开发环境配置
if (isDev) {
//开发环境配置
config.devtool = "eval-source-map";
config.devServer = {
contentBase: "./build", //本地服务器所加载的页面所在的目录
historyApiFallback: true, //不跳转
inline: true,
hot: true,
//colors: true,
port: 7070
};
//loader配置
config.module = {
rules: [{
test: /(\.jsx|\.js)$/,
use: {
loader: "babel-loader"
},
exclude: /node_modules/
}, {
test: /\.css$/,
use: [{
loader: "style-loader"
}, {
loader: "css-loader"
}]
}]
};
//插件配置
config.plugins = [
new webpack.BannerPlugin('版权所有,翻版必究'),
new webpack.optimize.CommonsChunkPlugin({
name: 'commons.chunk',
chunks: ['index']
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.bundle.js'
}),
new HtmlWebpackPlugin({
template: __dirname + "/src/views/index.html",
chunks: ['commons.chunk', 'vendor', 'index'],
chunksSortMode: 'dependency'
}),
// new webpack.optimize.OccurrenceOrderPlugin(),
//new webpack.optimize.UglifyJsPlugin(),
//new ExtractTextPlugin("style.css"),
// new CleanWebpackPlugin('build/*.*', {
// root: __dirname,
// verbose: true,
// dry: false
// })
];
}
//发布环境配置
if (isRelease) {
}
//导出配置对象
module.exports = config;