This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 406
/
webpack.config.js
88 lines (71 loc) · 1.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
/* eslint-disable */
const { getConfig, dev } = require('./webpack.config.base');
const { spawn, execSync } = require('child_process');
const CopyPlugin = require('copy-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
let terser = require('terser');
/* eslint-enable */
let electronProcess;
const mainConfig = getConfig({
target: 'electron-main',
devtool: dev ? 'inline-source-map' : false,
watch: dev,
entry: {
main: './src/main',
},
plugins: [
new CopyPlugin({
patterns: [
{
from:
'node_modules/@cliqz/adblocker-electron-preload/dist/preload.cjs.js',
to: 'preload.js',
transform: async (fileContent, path) => {
return (
await terser.minify(fileContent.toString())
).code.toString();
},
},
],
}),
],
});
const preloadConfig = getConfig({
target: 'web',
devtool: false,
watch: dev,
entry: {
'view-preload': './src/preloads/view-preload',
},
plugins: [],
});
if (process.env.ENABLE_EXTENSIONS) {
preloadConfig.entry['popup-preload'] = './src/preloads/popup-preload';
preloadConfig.entry['extensions-preload'] =
'./src/preloads/extensions-preload';
}
if (process.env.START === '1') {
mainConfig.plugins.push({
apply: (compiler) => {
compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => {
if (electronProcess) {
try {
if (process.platform === 'win32') {
execSync(`taskkill /pid ${electronProcess.pid} /f /t`);
} else {
electronProcess.kill();
}
electronProcess = null;
} catch (e) {}
}
electronProcess = spawn('npm', ['start'], {
shell: true,
env: process.env,
stdio: 'inherit',
});
});
},
});
}
module.exports = [mainConfig, preloadConfig];