-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
82 lines (80 loc) · 1.89 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
const path = require('path');
const webpack = require('webpack');
const htmlWebpackPlugin = require('html-webpack-plugin');
const cleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin');
const HappyPack = require('happypack');
const os = require('os');
const getIPAdress = () => {
var interfaces = os.networkInterfaces();
for(var devName in interfaces){
var iface = interfaces[devName];
for(var i=0;i<iface.length;i++){
var alias = iface[i];
if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
return alias.address;
}
}
}
}
module.exports = {
mode: "production",
entry: path.resolve(__dirname, 'src/index.js'),
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js'
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /react|react-dom/,
name:'vendor',
chunks:'initial'
}
}
}
},
devServer: {
contentBase: './build',
compress: true,
open: true,
hot: true,
host: getIPAdress()
},
module: {
rules: [
{
test: /\.css$/,
use: 'happypack/loader?id=css',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: 'happypack/loader?id=js',
}
]
},
plugins: [
new HappyPack({
id: 'js',
loaders: ['babel-loader']
}),
new HappyPack({
id: 'css',
loaders: ['style-loader', 'css-loader']
}),
// new ExtractTextWebpackPlugin({
// filename: 'index.css'
// }),
new cleanWebpackPlugin(['./build']),
new htmlWebpackPlugin({
template: './src/index.html',
minify: {
removeAttributeQuotes: true,
collapseWhitespace: true,
}
}),
new webpack.HotModuleReplacementPlugin(),
]
}