This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.config.js
102 lines (94 loc) · 2.98 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// bundle forked scripts with webpack
// as in production, with asar, node_modules are not accessible in forked scripts
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const getForkedScriptsConfig = () => {
const plugins = [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
];
// https://jlongster.com/Backend-Apps-with-Webpack--Part-I
return {
mode: 'production',
node: {
global: false,
__filename: false,
__dirname: false,
},
entry: {
'install-app-forked-lite-v2': path.join(__dirname, 'main-src', 'libs', 'app-management', 'install-app-async', 'install-app-forked-lite-v2.js'),
'install-app-forked-webkit': path.join(__dirname, 'main-src', 'libs', 'app-management', 'install-app-async', 'install-app-forked-webkit.js'),
'prepare-webkit-wrapper-forked': path.join(__dirname, 'main-src', 'libs', 'app-management', 'prepare-webkit-wrapper-async', 'prepare-webkit-wrapper-forked.js'),
'uninstall-app-forked': path.join(__dirname, 'main-src', 'libs', 'app-management', 'uninstall-app-async', 'uninstall-app-forked.js'),
},
target: 'node',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
},
devtool: 'source-map',
plugins,
};
};
const getPreloadScriptsConfig = () => {
const plugins = [];
return {
mode: 'production',
node: {
global: false,
__filename: false,
__dirname: false,
},
entry: {
'preload-main': path.join(__dirname, 'main-src', 'libs', 'windows', 'preload-main.js'),
'preload-menubar': path.join(__dirname, 'main-src', 'libs', 'windows', 'preload-menubar.js'),
},
target: 'electron-renderer',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
},
devtool: 'source-map',
plugins,
};
};
const getElectronMainConfig = () => {
const plugins = [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['libs'],
cleanAfterEveryBuildPatterns: [],
}),
];
const patterns = [
{
from: path.join(__dirname, 'main-src', 'images'),
to: path.join(__dirname, 'build', 'images'),
},
];
plugins.push(new CopyPlugin({ patterns }));
return {
mode: 'production',
node: {
global: false,
__filename: false,
__dirname: false,
},
entry: {
electron: path.join(__dirname, 'main-src', 'electron.js'),
},
target: 'electron-main',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
},
devtool: 'source-map',
plugins,
};
};
module.exports = [getForkedScriptsConfig(), getElectronMainConfig(), getPreloadScriptsConfig()];