-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
98 lines (93 loc) · 2.71 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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
vendor: path.join(__dirname, 'app/vendor')
};
const common = {
entry: {
index: ['babel-polyfill', './app/app.jsx'],
vendor: [
'react',
'react-dom',
'react-router-dom',
'react-redux',
'react-intl',
'redux',
'redux-promise',
'redux-thunk',
'redux-logger'
],
custom_elements_vendor: [
`${PATHS.vendor}/custom-elements-es5-adapter.js`
]
},
resolve: {
extensions: ['.js', '.jsx']
},
output: {
path: PATHS.build,
filename: '[name].js'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
// TODO: for own project replace to /node_modules/
// Exclude app.jsx for npm as we use a module in node_modules that is JSX.
// babel-loader is excluding it so it doesn't read it,
// we make an exception for that package in that regex (whitelist or blacklist)
// For more details please see issues - https://github.com/babel/babel-loader/issues/530
exclude: /node_modules\/(?!(app)\/).*/,
include: PATHS.app
},
{
test: /\.jsx$/,
use: 'babel-loader',
exclude: /node_modules\/(?!(app)\/).*/,
include: PATHS.app
}
]
},
externals: {
'jquery': 'jQuery'
}
};
if (TARGET === 'dev' || TARGET === 'fast-start' || !TARGET) {
module.exports = common;
}
if (TARGET === 'prod' || TARGET === 'staging') {
module.exports = merge(common, {
optimization: {
minimize: true,
minimizer: [
new UglifyJsPlugin({
sourceMap: false
})
],
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: 'vendor',
test: 'vendor',
enforce: true
}
}
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
})
]
});
}