-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.dev.js
130 lines (126 loc) · 3.21 KB
/
webpack.dev.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This file contains the development configuration for Webpack.
// Webpack is used to bundle our source code, in order to optimize which
// scripts are loaded and all required files to run the application are
// neatly put into the build directory.
// Based on https://taraksharma.com/setting-up-electron-typescript-react-webpack/
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
let mainConfig = {
mode: 'development',
entry: './src/main.ts',
devtool: 'source-map',
target: ['electron-main', 'es2022'],
output: {
filename: 'main.bundle.js',
path: __dirname + '/build',
clean: true,
// keep filename ending the same: certain filename patterns required for certain Electron icon uses
assetModuleFilename: 'assets/[hash]_[name][ext][query]',
},
node: {
__dirname: false,
__filename: false,
},
resolve: {
extensions: ['.js', '.json', '.ts'],
},
externals: {
fsevents: "require('fsevents')",
},
module: {
rules: [
{
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
test: /\.(ts)$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
},
},
{
test: /\.(jpg|png|gif|ico|icns|eot|ttf|woff|woff2)$/,
type: 'asset/resource',
},
],
},
};
let rendererConfig = {
mode: 'development',
entry: './src/renderer.tsx',
devtool: 'source-map',
target: ['electron-renderer', 'es2022'],
output: {
filename: 'renderer.bundle.js',
path: __dirname + '/build',
},
node: {
__dirname: false,
__filename: false,
},
experiments: {
asyncWebAssembly: true,
},
resolve: {
extensions: ['.js', '.json', '.ts', '.tsx', '.svg', '.wasm'],
alias: {
common: path.resolve(__dirname, 'common/'),
widgets: path.resolve(__dirname, 'widgets/'),
resources: path.resolve(__dirname, 'resources/'),
src: path.resolve(__dirname, 'src/'),
wasm: path.resolve(__dirname, 'wasm/'),
},
},
externals: {
fsevents: "require('fsevents')",
},
module: {
rules: [
{
// All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
loader: 'ts-loader',
},
{
test: /\.(scss|css)$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } },
],
},
{
test: /\.(jpg|png|gif|ico|icns|eot|ttf|woff|woff2)$/,
type: 'asset/resource',
},
{
test: /\.wasm$/,
type: 'asset/resource',
},
{
test: /\.js$/,
resourceQuery: /file/,
type: 'asset/resource',
},
{
test: /\.svg$/,
oneOf: [
{
issuer: /\.scss$/,
type: 'asset/resource',
},
{
issuer: /.tsx?$/,
loader: '@svgr/webpack',
},
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/index.html'),
}),
],
};
module.exports = [mainConfig, rendererConfig];