Repository navigation
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
151 lines (147 loc) · 4.39 KB
/
Copy pathwebpack.dev.js
File metadata and controls
151 lines (147 loc) · 4.39 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// 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 webpack = require('webpack');
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')",
'better-sqlite3': "require('better-sqlite3')",
// sharp ships native binaries that cannot be inlined. The main bundle now
// reaches it through the sidecar server (serve mode), so it must be
// require()'d at runtime from node_modules.
sharp: "require('sharp')",
},
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/'),
// Platform seam: resolves to the Electron implementation for the desktop
// bundle. The web SPA target (TASK-130) will override this alias to point
// at platform.web.ts. See INV-034 / TASK-126.
'src/frontend/platform': path.resolve(
__dirname,
'src/frontend/platform/platform.electron.ts',
),
},
},
externals: {
fsevents: "require('fsevents')",
'better-sqlite3': "require('better-sqlite3')",
// Deliberately NO `sharp` here: only the main bundle loads it (serve mode).
// Listing it in the renderer would turn a stray renderer-side `import sharp`
// into a runtime require() instead of a build-time failure.
},
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'),
}),
// IS_WEB_BUILD is false in the Electron renderer bundle; this lets the
// web-mode branch in renderer.tsx be dead-code-eliminated.
// The web SPA webpack config (TASK-130) sets this to true.
new webpack.DefinePlugin({ IS_WEB_BUILD: JSON.stringify(false) }),
],
};
module.exports = [mainConfig, rendererConfig];