/
webpack.config.js
85 lines (80 loc) · 2.19 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
const path = require('path');
const webpack = require('webpack');
const createElectronReloadWebpackPlugin = require('electron-reload-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
// Custom env variable so we could start webpack without electron-connect too
const useElectronConnect = process.env.ELECTRON_CONNECT === 'true';
const ElectronReloadWebpackPlugin = createElectronReloadWebpackPlugin({
path: path.join(__dirname, './build/backend.js'),
// Or
// path: './',
logLevel: 0
});
// You could also create some baseConfig and extend from it
const frontendConfig = {
mode: isProduction ? 'production' : 'development',
entry: {
frontend: './src/frontend/index.tsx'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
plugins: [useElectronConnect && ElectronReloadWebpackPlugin()].filter(
Boolean
),
module: {
rules: [
{
test: /\.tsx?$/,
use: [{ loader: 'ts-loader' }],
exclude: /node_modules/
},
{
test: /\.node$/,
use: [{ loader: 'node-loader' }]
}
]
},
target: 'electron-renderer',
node: {
__dirname: false
}
};
const backendConfig = {
mode: isProduction ? 'production' : 'development',
entry: {
backend: './src/backend/index.ts'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js'
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx']
},
plugins: [useElectronConnect && ElectronReloadWebpackPlugin()].filter(
Boolean
),
module: {
rules: [
{
test: /\.tsx?$/,
use: [{ loader: 'ts-loader' }],
exclude: /node_modules/
},
{
test: /\.node$/,
use: [{ loader: 'node-loader' }]
}
]
},
target: 'electron-main',
node: {
__dirname: false
}
};
module.exports = [frontendConfig, backendConfig];