-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.prod.js
109 lines (95 loc) · 2.71 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
const { resolve } = require('path');
const webpack = require('webpack');
const findCacheDir = require('find-cache-dir');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'source-map',
context: resolve(__dirname, 'frontend'),
entry: [
'./index.jsx',
],
output: {
// the output bundle
filename: '[name]-[hash].min.js',
path: resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.jsx?$/,
use: [
{
loader: 'babel-loader',
options: {
// This is a feature of `babel-loader` for webpack (not Babel itself).
// It enables caching results in ./node_modules/.cache/react-scripts/
// directory for faster rebuilds. We use findCacheDir() because of:
// https://github.com/facebookincubator/create-react-app/issues/483
cacheDirectory: findCacheDir({
name: 'react-scripts',
}),
},
},
// Before running code through babel, check it for lint errors
{
loader: 'eslint-loader',
options: {
// emit all errors as warnings: this lets us see all issues in the
// dev console, but the presence of errors will not block rebuilds
emitWarning: true,
},
},
],
exclude: /node_modules/,
},
{
test: /\.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[path][name]--[local]--[hash:base64:5]',
},
},
'postcss-loader', // See postcss.config.js for options
'stylus-loader',
],
}),
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'url-loader?limit=10000',
],
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
// Inject generated scripts into the frontend/index.html template
new HtmlWebpackPlugin({
template: './index.html',
}),
// Set NODE_ENV to production so that Uglify can strip out dev-only code
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
// Extract css into bundle.css
new ExtractTextPlugin('[name]-[contenthash].css'),
// Minify with UglifyJS
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false,
},
}),
],
};