-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·116 lines (100 loc) · 2.28 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
109
110
111
112
113
114
115
116
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const path = require('path');
const htmlWebpackPlugin = require('html-webpack-plugin');
const DEV_CONFIG = require('./webpack-config/webpack.dev');
const PRO_CONFIG = require('./webpack-config/webpack.prod');
const {
APP_PATH,
DIST_PATH,
NODE_MODULES_PATH
} = require('./webpack-config/paths');
const { cssLoader, sassLoader, postcssLoader } = require('./webpack-config/loaders');
const ENV = process.env.NODE_ENV;
const VALID_ENVS = ['test', 'development', 'production'];
if (!VALID_ENVS.includes(ENV)) {
throw new Error(`${ ENV } is not valid environment!`);
}
const config = {
development: DEV_CONFIG,
production: PRO_CONFIG
}[ENV];
const COMMON_CONFIG = {
entry: {
vendor: [
'react',
'react-dom',
'redux',
'react-redux',
'redux-thunk',
'react-router-dom',
'immutable'
]
},
output: {
path: DIST_PATH,
filename: '[name].js'
},
module: {
rules: [
{
test: /\.js$/,
include: APP_PATH,
use: [
'babel-loader',
'eslint-loader'
]
},
{
test: /\.(sass|scss)$/,
include: APP_PATH,
use: [
'style-loader',
cssLoader,
postcssLoader,
sassLoader
]
}
]
},
resolve: {
extensions: ['.js', '.sass'],
modules: [
NODE_MODULES_PATH,
APP_PATH
],
alias: {
components: path.resolve(APP_PATH, 'components'),
config: path.resolve(APP_PATH, 'config'),
reducers: path.resolve(APP_PATH, 'reducers')
}
},
performance: {
hints: false
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: 2
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENV)
}),
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
exclude: /vendor.*\.js$/
}),
new webpack.LoaderOptionsPlugin({
options: {
eslint: {
emitWarning: true
}
}
}),
new htmlWebpackPlugin({
title: 'react',
template: './webpack-config/index.ejs'
})
]
};
module.exports = webpackMerge.smart(COMMON_CONFIG, config);