-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.test.config.js
84 lines (79 loc) · 1.68 KB
/
webpack.test.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
/*
* @Description: 一个配置文件测试开发和生产两种环境 webpack 配置
* @Author: Shie
* @Date: 2018-12-29
* @Last Modified by: Shie
* @Last Modified time: 2019-01-09 19:33:21
*/
const webpack = require('webpack'),
path = require('path'),
fs = require('fs');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const SRC = path.resolve(__dirname, "src"),
NODE_MODULES = path.resolve(__dirname, "node_modules")
const config = {
entry: [
'./src/index.js'
],
module: {
loaders: [
{
test: [
/\.png$/,
/\.jpg$/
],
loader: "url-loader"
},
{
test: /\.css$/,
include: [
NODE_MODULES,
SRC
],
loader: 'style-loader!css-loader',
}
]
},
resolve: {
root: SRC,
extensions: [
'',
'.js',
'.jsx'
]
},
output: {
path: path.resolve(__dirname, 'public', 'assets'),
publicPath: '/assets',
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}
}),
]
};
if (process.env.NODE_ENV === 'production') {
console.log('production process.env.NODE_ENV: ', process.env.NODE_ENV)
config.plugins.push(
new UglifyJSPlugin({
sourceMap: true
})
)
} else {
console.log('development process.env.NODE_ENV: ', process.env.NODE_ENV)
config.devtool = "#cheap-module-source-map"
config.devServer = {
contentBase: './public',
hot: true,
inline: true,
host: "0.0.0.0",
port: 2708
}
config.plugins.push(
new webpack.HotModuleReplacementPlugin()
);
}
module.exports = config