-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
executable file
·102 lines (96 loc) · 2.37 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
/**
* @file webpack.config.js
* @description Webpack config file.
* @author Duncan Grubbs <duncan.grubbs@gmail.com>
* @version 0.0.4
*/
require('dotenv').config();
const webpack = require('webpack');
const { resolve } = require('path');
const ImageminPlugin = require('imagemin-webpack-plugin').default;
const imageminMozjpeg = require('imagemin-mozjpeg');
const CompressionPlugin = require('compression-webpack-plugin');
module.exports = {
entry: {
// Dumps all code from our index.js.
app: [
'webpack-hot-middleware/client',
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
'./client/core/index.js',
],
// Dumps main required react stuff into vendor
// If you build, you will see app and vendor are massive js files
vendor: [
'react',
'react-dom',
],
},
mode: process.env.WEBPACK_MODE,
output: {
// Dumps the build into /dist
path: resolve(__dirname, 'dist/'),
filename: '[name].js',
publicPath: '/',
},
resolve: {
extensions: ['.js', '.jsx'],
modules: [
'client',
'node_modules',
],
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
}, {
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
}, {
// Webfont loading
test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
use: 'url-loader',
}, {
// Transpiles jsx
test: /\.jsx*$/,
exclude: [/node_modules/, /.+\.config.js/],
use: 'babel-loader',
}, {
test: /\.(jpe?g|gif|png|svg)$/i,
use: [
'file-loader',
],
},
],
},
plugins: [
// Compresses jpegs
// Does some other things...
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
}),
new CompressionPlugin({
filename: '[path]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
new ImageminPlugin({
plugins: [
imageminMozjpeg({
// We can adjust this to our liking
quality: 75,
progressive: true,
}),
],
}),
],
};