-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
105 lines (101 loc) · 2.45 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
99
100
101
102
103
104
105
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const DashboardPlugin = require('webpack-dashboard/plugin');
const WriteFilePlugin = require('write-file-webpack-plugin');
const dashboard = require('webpack-dashboard');
const getPlugins = () => {
const env = !process.env.NODE_ENV || process.env.NODE_ENV.trim() !== 'production' ? 'development' : 'production';
const plugins = [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
new HtmlWebpackPlugin({
template: path.join(process.cwd(), 'app/index.html'),
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
filename: 'index.html',
inject: 'body',
}),
];
if (env === 'production') {
return [
...plugins,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
sourceMap: false,
output: {
comments: false,
},
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
];
}
return [
...plugins,
new DashboardPlugin(dashboard.setData),
new WriteFilePlugin({
log: false,
}),
];
};
const buildDirectory = path.join(process.cwd(), 'build');
module.exports = {
entry: [
path.join(process.cwd(), 'app/app.js'),
],
output: {
path: buildDirectory,
filename: 'main.js',
publicPath: '/',
},
devtool: '#eval',
devServer: {
colors: true,
contentBase: buildDirectory,
outputPath: buildDirectory,
historyApiFallback: true,
inline: true,
progress: true,
quiet: true,
open: true,
stats: 'errors-only',
},
module: {
loaders: [
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['latest', 'react', 'stage-0'],
},
},
{
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
},
{
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: 'file-loader',
},
],
},
plugins: getPlugins(),
};