-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.production.config.js
executable file
·179 lines (176 loc) · 5.68 KB
/
webpack.production.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
'use strict';
const autoprefixer = require('autoprefixer');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
function getConfig() {
const plugins = [
new HtmlWebpackPlugin({
template: 'app/index.tpl.html',
inject: 'body',
filename: 'index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
}
}),
new FaviconsWebpackPlugin({
// Your source logo
logo: 'resources/img/favicon.png',
// The prefix for all image files (might be a folder or a name)
prefix: 'icons-[hash]/',
// Emit all stats of the generated icons
emitStats: false,
// The name of the json containing all favicon information
statsFilename: 'iconstats-[hash].json',
// Generate a cache file with control hashes and
// don't rebuild the favicons until those hashes change
persistentCache: true,
// Inject the html into the html-webpack-plugin
inject: true,
// favicon background color (see https://github.com/haydenbleasel/favicons#usage)
background: '#fff',
// favicon app title (see https://github.com/haydenbleasel/favicons#usage)
title: 'Network Statistics',
// which icons should be generated (see https://github.com/haydenbleasel/favicons#usage)
icons: {
android: true,
appleIcon: true,
appleStartup: true,
coast: false,
favicons: true,
firefox: true,
opengraph: false,
twitter: false,
yandex: false,
windows: false
}
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new ExtractTextPlugin({
filename: 'resources/css/[name].[[md5:contenthash:hex:20].css',
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
];
return {
mode: 'production',
devtool: 'source-map',
entry: [
path.join(__dirname, 'app/index.js')
],
plugins: plugins,
output: {
path: path.join(__dirname, '/dist/'),
filename: '[name]-[hash].js',
publicPath: '/'
},
optimization: {
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: {
safari10: true
}
},
sourceMap: true
})
]
},
resolve: {
modules: [__dirname, 'app', 'node_modules'],
},
externals: {
config: 'config'
},
module: {
rules: [
// rules for modules (configure loaders, parser options, etc.)
{
// The file-loader handles all assets unless explicitly excluded. It makes sure
// those assets get served by WebpackDevServer.
exclude: [/\.html$/, /\.(js|jsx)$/, /\.css$/, /\.less$/, /\.scss$/, /\.json$/, /\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('file-loader'),
options: {
name: 'resources/media/[name].[hash:8].[ext]',
},
},
{
// url-loader works like file-loader except that it embeds assets smaller than specified
// limit in bytes as data URLs to avoid requests.
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
loader: require.resolve('url-loader'),
options: {
limit: 10000,
name: 'resources/media/[name].[hash:8].[ext]',
},
},
{
// Process JS with Babel.
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: /app/,
loader: require.resolve('babel-loader'),
},
{
// Resolves styles, turns CSS into JS modules that inject style tags, compiles less or sass
test: [/\.css$/, /\.less$/, /\.scss$/],
loader: ExtractTextPlugin.extract(
{
fallback: require.resolve('style-loader'),
use: [
{
loader: require.resolve('css-loader'),
options: {
url: true,
importLoaders: 2,
minimize: true,
sourceMap: true,
},
},
{
loader: require.resolve('postcss-loader'),
options: {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
require('postcss-flexbugs-fixes'),
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9', // React doesn't support IE8 anyway
],
flexbox: 'no-2009',
}),
],
},
},
// require.resolve('less-loader'),
require.resolve('sass-loader'),
],
}
),
},
]
}
};
}
module.exports = getConfig();