-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (72 loc) · 1.84 KB
/
webpack.config.js
File metadata and controls
78 lines (72 loc) · 1.84 KB
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
/* globals require, module, process, __dirname */
const dotenv = require('dotenv');
const _ = require('lodash');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const varNames = _.keys(dotenv.config({ path: '.env.sample' }).parsed);
// CircleCI needs this hack to update process.env via dotenv
Object.assign(process.env, dotenv.config().parsed);
const isProduction = (process.env.ENV === 'production');
const envVars = _.mapValues(_.pick(process.env, varNames), v => JSON.stringify(v));
const config = {
mode: process.env.ENV || 'development',
entry: './app/scripts/main',
output: {
path: __dirname,
filename: 'main.js',
},
devtool: isProduction ? 'source-map' : 'inline-source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['react'],
},
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': envVars,
}),
new webpack.ContextReplacementPlugin(
/moment[\/\\]locale$/, // eslint-disable-line no-useless-escape
/en/,
),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.ENV || 'development'),
}),
],
resolve: {
extensions: ['.js', '.jsx'],
},
};
if (isProduction) {
config.plugins.push(new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
safari10: true,
mangle: {
safari10: true,
},
},
}));
config.plugins.push(new webpack.LoaderOptionsPlugin({
context: __dirname,
debug: false,
minimize: true,
}));
} else {
config.plugins.push(new webpack.LoaderOptionsPlugin({
context: __dirname,
debug: true,
}));
}
module.exports = config;