-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.prod.js
117 lines (115 loc) · 3.37 KB
/
webpack.config.prod.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
117
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const { execSync } = require('child_process');
const __gitSHA__ = execSync('git rev-parse --short HEAD').toString();
module.exports = {
entry: {
Main: './app/js/app.jsx',
Vendor1: [
'yup',
'redux',
'moment',
'formik',
'react-redux',
'react-popper',
],
Vendor2: [
'react',
'react-dom',
'react-router',
'react-router-dom',
'connected-react-router',
],
},
output: {
path: path.join(__dirname, 'dist', 'assets'),
filename: '[name].[chunkhash].js',
publicPath: '/assets/',
},
resolve: {
extensions: ['.js', '.jsx'],
modules: [
path.resolve('./app'),
path.resolve('./app/js'),
'node_modules',
],
},
plugins: [
new webpack.NamedChunksPlugin(),
new FaviconsWebpackPlugin(path.resolve('./app/img/icon.png')),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
API_ROOT: JSON.stringify(process.env.API_ROOT || '/api/v2/'),
'__gitSHA__': JSON.stringify(__gitSHA__),
},
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({ name: ['Vendor1', 'Vendor2'], minChunks: Infinity }),
new webpack.optimize.CommonsChunkPlugin({ name: 'Main', async: 'Async4', minChunks: 4 }),
new webpack.optimize.CommonsChunkPlugin({ name: 'Main', async: 'Async3', minChunks: 3 }),
new webpack.optimize.CommonsChunkPlugin({ name: 'Main', async: 'Async2', minChunks: 2 }),
new webpack.optimize.MinChunkSizePlugin({ minChunkSize: 8192 }),
new HtmlWebpackPlugin({
chunksSortMode: 'dependency',
title: 'Society of Software Engineers',
filename: '../index.html',
template: './app/index.ejs',
urlRoot: 'https://sse.rit.edu',
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new UglifyJSPlugin({
parallel: true,
sourceMap: false,
uglifyOptions: {
compress: {
warnings: false,
},
output: {
comments: false,
},
},
}),
new ExtractTextPlugin({
filename: '[name].[chunkhash].css',
allChunks: true,
}),
...process.env.DEBUG ? [new BundleAnalyzerPlugin({
analyzerMode: 'server',
})] : [],
],
module: {
rules: [
{
test: /\.jsx?$/,
loaders: ['babel-loader'],
exclude: /node_modules/,
},
{
test: /\.md$/,
loaders: ['html-loader', 'markdown-loader'],
},
{
test: /\.s?css$/,
loader: ExtractTextPlugin.extract(['css-loader', 'resolve-url-loader', 'sass-loader']),
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
},
{
test: /\.(gif|png|jpg|jpeg)(\?[a-z0-9]+)?$/,
loader: 'url-loader?limit=8192',
},
],
},
};