This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
webpack.config.renderer.js
89 lines (75 loc) · 1.82 KB
/
webpack.config.renderer.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
/* eslint-disable */
const { getConfig, dev } = require('./webpack.config.base');
const { join } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
/* eslint-enable */
const PORT = 4444;
const INCLUDE = join(__dirname, 'src');
const getHtml = (scope, name) => {
return new HtmlWebpackPlugin({
title: 'Multrin',
template: 'static/pages/app.html',
filename: `${name}.html`,
chunks: [`vendor.${scope}`, name],
});
};
const applyEntries = (scope, config, entries) => {
for (const entry of entries) {
config.entry[entry] = [`./src/renderer/views/${entry}`];
config.plugins.push(getHtml(scope, entry));
if (dev) {
config.entry[entry].unshift('react-hot-loader/patch');
}
}
};
const getBaseConfig = name => {
const config = {
plugins: [],
output: {},
entry: {},
module: {
rules: [
{
test: /\.(png|gif|jpg|woff2|ttf|svg)$/,
include: INCLUDE,
use: [
{
loader: 'file-loader',
options: {
esModule: false,
},
},
],
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'initial',
name: `vendor.${name}`,
minChunks: 2,
},
},
},
},
};
if (dev) {
config.plugins.push(new HardSourceWebpackPlugin());
}
return config;
};
const appConfig = getConfig(getBaseConfig('app'), {
target: 'electron-renderer',
devServer: {
contentBase: join(__dirname, 'build'),
port: PORT,
hot: true,
inline: true,
disableHostCheck: true,
},
});
applyEntries('app', appConfig, ['app', 'menu']);
module.exports = [appConfig];