forked from notable/notable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.js
71 lines (61 loc) · 2.03 KB
/
webpack.base.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
/* IMPORT */
const {BundleAnalyzerPlugin} = require ( 'webpack-bundle-analyzer' ),
ExcludeAssetsPlugin = require ( 'webpack-exclude-assets-plugin' ),
TerserPlugin = require ( 'terser-webpack-plugin' ),
TSConfigPathsPlugin = require ( 'tsconfig-paths-webpack-plugin' ),
path = require ( 'path' ),
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;
}
};
});
}
/* BASE */
function base ( options ) { //TODO: Maybe we don't need to define multiple webpack configs //URL: https://github.com/electron-userland/electron-webpack/issues/290
return {
resolve: {
alias: {
'react-dom': process.env.NODE_ENV !== 'production' ? '@hot-loader/react-dom' : 'react-dom'
},
plugins: [
new TSConfigPathsPlugin ()
]
},
plugins: [
new ExcludeAssetsPlugin ({
path: [
'\.(eot|ttf|woff)$' // Unused font formats
]
}),
new webpack.DefinePlugin ({
'Environment.isDevelopment': JSON.stringify ( process.env.NODE_ENV !== 'production' )
}),
PluginSkeletonOptimization,
new BundleAnalyzerPlugin ({
analyzerMode: 'static',
reportFilename: path.join ( __dirname, `webpack.report.${options.target}.html` ),
openAnalyzer: false,
logLevel: 'silent'
})
],
optimization: {
minimizer: [
new TerserPlugin ({
parallel: true,
sourceMap: true,
terserOptions: {
keep_fnames: true
}
})
]
}
};
}
/* EXPORT */
module.exports = base;