This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
70 lines (65 loc) · 1.76 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
const { DefinePlugin, optimize } = require('webpack');
const Dotenv = require('dotenv-webpack');
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CompressionPlugin = require('compression-webpack-plugin');
const env = process.env.NODE_ENV || 'local';
const analyze = process.env.ANALYZE_BUNDLE;
const plugins = [new Dotenv()];
plugins.push(new DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
GRAPH_API_URI: JSON.stringify(process.env.GRAPH_API_URI),
AUTH_API_URI: JSON.stringify(process.env.AUTH_API_URI),
STORAGE_API_URI: JSON.stringify(process.env.STORAGE_API_URI),
INSTAGRAM_API_URI: JSON.stringify(process.env.INSTAGRAM_API_URI),
},
}));
if (analyze) {
plugins.push(new BundleAnalyzerPlugin());
}
plugins.push(new CompressionPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 1024,
minRatio: 0.8,
}));
plugins.push(new optimize.AggressiveMergingPlugin());
module.exports = {
devtool: 'eval-source-map',
entry: {
app: [
path.resolve(__dirname, 'src/app/index.jsx'),
],
},
mode: env !== 'local' ? 'production' : 'development',
output: {
path: path.resolve(__dirname, 'public/build'),
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
publicPath: '/build/',
},
module: {
rules: [
{
test: /\.js(x)?$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
},
},
],
},
plugins,
optimization: {
minimizer: [
new TerserPlugin(),
],
},
watch: env === 'local',
resolve: {
extensions: ['.js', '.jsx'],
},
};