-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (81 loc) · 2.23 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const devMode = (process.env.DEV_MODE === 'true' || process.env.DEV_MODE === true) || false;
const mode = devMode ? 'development' : 'production';
const targetPath = path.join(__dirname, './build');
let outputPath;
if (devMode) {
outputPath = path.join(targetPath, 'dev');
} else {
outputPath = path.join(targetPath, 'production');
}
module.exports = {
mode,
context: __dirname,
entry: './src/index.jsx',
output: {
path: outputPath,
filename: devMode ? '[name].bundle.js' : '[name].[chunkhash].bundle.js'
},
resolve: {
modules: ['node_modules'],
extensions: ['.jsx', '.js', '.html']
},
module: {
rules: [
{
test: /\.(jsx|js)$/,
include: path.resolve(__dirname, 'src'),
use: [
{
loader: 'babel-loader'
},
{
loader: 'eslint-loader',
options: {
configFile: path.join(__dirname, '/.eslintrc.js'),
failOnWarning: false,
failOnError: false,
cache: false
}
}
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.html',
inject: 'body'
}),
new webpack.DefinePlugin({
'process.env': {
ENV: JSON.stringify(mode)
}
}),
...([
// Development-only plugins.
new webpack.ProgressPlugin({
profile: true
})
])
],
devtool: devMode ? 'inline-source-map' : false,
cache: devMode,
watch: false,
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 3000
},
profile: true,
stats: {
errorDetails: true
},
devServer: {
contentBase: path.join(__dirname, 'build/dev'),
compress: true,
port: 9000
}
};