This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
webpack.config.js
79 lines (71 loc) · 1.93 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
/* 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 CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const packageJson = require('./package.json');
const externals = {};
Object.keys(packageJson.dependencies)
.forEach((name) => {
externals[name] = `commonjs ${name}`;
});
const getPreloadScriptsConfig = () => {
const plugins = [];
return {
mode: 'production',
node: {
global: false,
__filename: false,
__dirname: false,
},
externals,
entry: {
'preload-menubar': path.join(__dirname, 'main-src', 'preload', 'menubar.js'),
},
target: 'electron-renderer',
output: {
path: path.join(__dirname, 'build'),
filename: '[name].js',
},
devtool: false,
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,
},
externals,
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 = [getElectronMainConfig(), getPreloadScriptsConfig()];