This repository was archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathwebpack.main.config.js
More file actions
96 lines (79 loc) · 2.24 KB
/
webpack.main.config.js
File metadata and controls
96 lines (79 loc) · 2.24 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const path = require('path');
const { spawn } = require('child_process');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const resolvepath = require('@gravitational/build/webpack/resolvepath');
const configFactory = require('@gravitational/build/webpack/webpack.base');
function onFirstBuildDonePlugin(env) {
let isInitialBuild = true;
return {
apply: compiler => {
compiler.hooks.done.tap('OnFirstBuildDonePlugin', (/*compilation*/) => {
if (!isInitialBuild) {
return;
}
isInitialBuild = false;
const child = spawn('yarn', ['start-electron', '--inspect'], {
shell: true,
env,
stdio: 'inherit',
detached: true, // detaching the process will allow restarting electron without terminating the dev server
});
child.unref();
});
},
};
}
const cfg = {
entry: {
main: './src/main.ts',
preload: './src/preload.ts',
sharedProcess: './src/sharedProcess/sharedProcess.ts',
},
output: {
path: resolvepath('build/app/dist/main'),
filename: '[name].js',
},
resolve: {
...configFactory.createDefaultConfig().resolve,
alias: {
...configFactory.createDefaultConfig().resolve.alias,
teleterm: path.join(__dirname, './src'),
},
},
devtool: false,
target: 'electron-main',
optimization: {
minimize: false,
},
module: {
strictExportPresence: true,
rules: [configFactory.rules.jsx()],
},
externals: {
'node-pty': 'commonjs2 node-pty',
},
plugins: [new CleanWebpackPlugin()],
/**
* Disables webpack processing of __dirname and __filename.
* If you run the bundle in node.js it falls back to these values of node.js.
* https://github.com/webpack/webpack/issues/2010
*/
node: {
__dirname: false,
__filename: false,
},
};
module.exports = (env, argv) => {
if (argv.mode === 'development') {
process.env.BABEL_ENV = 'development';
process.env.NODE_ENV = 'development';
cfg.mode = 'development';
cfg.plugins.push(onFirstBuildDonePlugin(process.env));
}
if (argv.mode === 'production') {
process.env.BABEL_ENV = 'production';
process.env.NODE_ENV = 'production';
cfg.mode = 'production';
}
return cfg;
};