-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
115 lines (107 loc) · 2.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const fs = require('fs');
const WebpackObfuscator = require('webpack-obfuscator');
const nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
function clearLibElectron() {
if (!fs.existsSync('./lib-electron')) {
fs.mkdirSync('./lib-electron');
return;
}
for (const item of fs.readdirSync('./lib-electron')) {
const path = `./lib-electron/${item}`;
const fd = fs.openSync(path);
const data = fs.fstatSync(fd);
fs.closeSync(fd);
if (data.isDirectory()) {
fs.rmSync(path, { recursive: true, force: true });
} else {
fs.unlinkSync(path);
}
}
}
clearLibElectron();
const plugins = [
new WebpackObfuscator({
optionsPreset: 'medium-obfuscation',
sourceMap: true,
disableConsoleOutput: false,
seed: 110611782,
// debugProtection: false,
// debugProtectionInterval: false,
}),
];
const rules = [
{
test: /\.ts$/,
include: /(electron|src)/,
exclude: /(node_modules|\.webpack)/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
configFile: 'tsconfig.electron.json',
},
},
],
},
{
test: /\.node$/,
use: 'node-loader',
},
{ test: /\.(sh|ps1|exe|apk|ttf|html|png|webm|webp|pub|pem)$/, use: 'raw-loader' },
];
const base = {
mode: 'production',
module: { rules },
devtool: 'source-map',
plugins,
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
externalsPresets: {
node: true, // in order to ignore built-in modules like path, fs, etc.
},
resolve: {
plugins: [new TsconfigPathsPlugin({ logLevel: 'info', configFile: './tsconfig.electron.json' })],
extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
},
};
module.exports = [
{
entry: './electron/main.ts',
target: 'electron-main',
output: {
path: __dirname + '/lib-electron',
filename: 'main.js',
},
...base,
},
{
entry: './electron/preload.ts',
target: 'electron-main',
output: {
path: __dirname + '/lib-electron',
filename: 'preload.js',
},
...base,
},
{
entry: './electron/TestWorker.ts',
target: 'electron-main',
devtool: 'source-map',
output: {
path: __dirname + '/lib-electron',
filename: 'TestWorker.js',
},
...base,
},
{
entry: './electron/test/TestWorker2.ts',
target: 'electron-main',
devtool: 'source-map',
output: {
path: __dirname + '/lib-electron',
filename: 'TestWorker2.js',
},
...base,
},
];