forked from notable/notable
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.js
50 lines (42 loc) · 1.2 KB
/
webpack.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
/* IMPORT */
const TerserPlugin = require ( 'terser-webpack-plugin' ),
TSConfigPathsPlugin = require ( 'tsconfig-paths-webpack-plugin' ),
webpack = require ( 'webpack' );
/* PLUGINS */
function PluginSkeletonOptimization ( compiler ) { // Loading heavy resources after the skeleton
compiler.plugin ( 'compilation', compilation => {
compilation.hooks.htmlWebpackPluginAfterHtmlProcessing = {
async promise ( data ) {
data.html = data.html.replace ( /<link(.*?)rel="stylesheet">(.*?)<body>(.*?)<script/, '$2<body>$3<link$1rel="stylesheet"><script' ); // Moving the main CSS to the bottom in order to make the skeleton load faster
return data;
}
};
});
}
/* CONFIG */
const config = {
resolve: {
plugins: [
new TSConfigPathsPlugin ()
]
},
plugins: [
new webpack.DefinePlugin ({
'Environment.isDevelopment': JSON.stringify ( process.env.NODE_ENV !== 'production' )
}),
PluginSkeletonOptimization
],
optimization: {
minimizer: [
new TerserPlugin ({
parallel: true,
sourceMap: true,
terserOptions: {
keep_fnames: true
}
})
]
}
};
/* EXPORT */
module.exports = config;