-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathwebpack.main.config.js
More file actions
77 lines (69 loc) · 2.44 KB
/
webpack.main.config.js
File metadata and controls
77 lines (69 loc) · 2.44 KB
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
// webpack.main.config.js
const path = require('path');
const { BytenodeWebpackPlugin } = require('@herberttn/bytenode-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const WebpackObfuscator = require('webpack-obfuscator');
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
mode: isProduction ? 'production' : 'development',
target: 'electron-main',
devtool: isProduction ? false : 'source-map',
entry: { main: './src/main/main.js' },
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'dist/out/main'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'package.json', to: path.resolve(__dirname, 'dist/out') },
{
from: path.resolve(__dirname, 'src/assets'),
to: path.resolve(__dirname, 'dist/out/assets'),
},
{
from: path.resolve(__dirname, 'src/assets_export'),
to: path.resolve(__dirname, 'dist/out/assets_export'),
},
{
from: path.resolve(__dirname, 'src/locale'),
to: path.resolve(__dirname, 'dist/out/locale'),
}
]
}),
isProduction && new WebpackObfuscator({
stringArray: true,
stringArrayThreshold: 1,
stringArrayEncoding: ['rc4'],
rotateStringArray: true,
selfDefending: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
}, []),
isProduction && new BytenodeWebpackPlugin({
compileForElectron: true,
}),
].filter(Boolean), // Filters out falsy values (like 'false' when not in production)
node: {
__dirname: false, // Important for paths in Electron main process
__filename: false,
},
};