-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack.common.js
80 lines (76 loc) · 1.87 KB
/
webpack.common.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
const path = require('path');
const BundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const Visualizer = require('webpack-visualizer-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const prod = process.env.NODE_ENV === 'production';
// Configure style loaders according to environment.
const cssLoader = prod
? 'css-loader'
: `${require.resolve('css-loader')}?sourceMap&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]`;
const sassLoader = prod
? 'sass-loader'
: `${require.resolve('sass-loader')}?sourceMap`;
const styleLoader = [
'style-loader',
cssLoader,
sassLoader,
];
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.jsx$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.css$/,
use: [
'css-loader',
],
},
{
test: /\.s(a|c)ss$/,
include: path.resolve(__dirname, './lib'),
use: styleLoader,
},
{
test: /\.(woff|woff2)$/,
use: 'file-loader',
},
],
},
plugins: [
new BundleAnalyzer({
analyzerMode: 'static',
reportFilename: path.resolve(__dirname, 'stats/bundle_analyzer_stats.html'),
}),
new Visualizer({
filename: '../stats/visualizer_stats.html',
}),
],
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true,
}),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
},
}),
],
},
};