-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
108 lines (101 loc) · 2.88 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
/* eslint-disable */
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
const lodash = require('lodash')
const path = require('path')
function getAppConfig(env) {
let data = require(`./src/configs/${env}`)
const defaultData = require('./src/configs/default')
data = lodash.assign(defaultData, data)
return data
}
module.exports = (env) => {
const NODE_ENV = (env && env.NODE_ENV) || 'development'
const IS_DEV = NODE_ENV === 'development' || NODE_ENV === 'local'
process.env.NODE_ENV = NODE_ENV
console.log('Node ENV: %s', NODE_ENV)
console.log('Configs: ', getAppConfig(NODE_ENV));
return {
devtool: IS_DEV ? 'source-map' : false,
entry: path.resolve(__dirname, IS_DEV ? 'src/index.dev.js' : 'src'),
output: {
filename: '[name][hash].js',
path: path.resolve(__dirname, 'build'),
publicPath: getAppConfig(NODE_ENV).PUBLIC_PATH
},
optimization: {
splitChunks: {
chunks: 'all'
}
},
resolve: {
alias: {
"@ant-design/icons/lib/dist$": path.resolve(__dirname, "src/overwrite/antd-icons"),
"@": path.resolve(__dirname, "src")
}
},
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: ['babel-loader']
}, {
test: /\.scss$/,
use: [
IS_DEV ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader'
]
}, {
test: /\.css$/,
use: [
IS_DEV ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader'
]
}, {
test: /\.html$/,
use: [{
loader: 'html-loader',
options: {
minimize: !IS_DEV,
root: path.resolve(__dirname, 'src')
}
}]
}, {
test: /\.(jpg|jpeg|png|svg|woff|eot|ttf|otf|pdf)$/,
use: ['file-loader']
}]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src/index.ejs'),
favicon: path.resolve(__dirname, 'src/resources/images/favicon.ico')
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new MiniCssExtractPlugin(),
new webpack.DefinePlugin({
'window._CONFIG': JSON.stringify(getAppConfig(NODE_ENV)),
}),
new webpack.HotModuleReplacementPlugin()
],
devServer: {
host: '0.0.0.0',
useLocalIp: true,
compress: true,
disableHostCheck: true,
hot: true,
hotOnly: true,
open: true,
overlay: true,
stats: 'minimal',
clientLogLevel: 'warning',
contentBase: path.join(__dirname, 'src'),
historyApiFallback: true
},
stats: 'minimal',
mode: IS_DEV ? 'development' : 'production'
}
}