1
+ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
1
2
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
2
3
import fs from 'fs'
3
4
import CopyWebpackPlugin from 'copy-webpack-plugin'
4
5
import HtmlWebpackPlugin from 'html-webpack-plugin'
5
6
import kebabCase from 'lodash/fp/kebabCase'
6
7
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
7
8
import path from 'path'
9
+ // eslint-disable-next-line node/no-unpublished-import
10
+ import ReactRefreshTypeScript from 'react-refresh-typescript'
8
11
import {
9
12
Configuration ,
10
13
SourceMapDevToolPlugin ,
11
14
WebpackPluginInstance ,
12
15
} from 'webpack'
16
+ // eslint-disable-next-line node/no-unpublished-import
17
+ import type { Configuration as DevServerConfiguration } from 'webpack-dev-server'
13
18
14
19
const isProduction = process . env . NODE_ENV === 'production'
20
+ const isDevelopment = ! isProduction
15
21
16
22
const commonPlugins : WebpackPluginInstance [ ] = [
17
23
new ForkTsCheckerWebpackPlugin ( ) ,
@@ -22,11 +28,20 @@ const commonPlugins: WebpackPluginInstance[] = [
22
28
if ( isProduction ) {
23
29
commonPlugins . push ( new MiniCssExtractPlugin ( ) )
24
30
}
31
+ if ( isDevelopment ) {
32
+ commonPlugins . push ( new ReactRefreshWebpackPlugin ( ) )
33
+ }
25
34
26
35
const commonConfig : Pick <
27
36
Configuration ,
28
37
'devtool' | 'externals' | 'mode' | 'module' | 'resolve' | 'output'
29
- > = {
38
+ > & {
39
+ devServer ?: DevServerConfiguration
40
+ } = {
41
+ devServer : {
42
+ hot : isDevelopment ,
43
+ port : 8081 ,
44
+ } ,
30
45
devtool : 'source-map' ,
31
46
externals : [ 'utf-8-validate' , 'bufferutil' ] ,
32
47
mode : isProduction ? 'production' : 'development' ,
@@ -39,9 +54,13 @@ const commonConfig: Pick<
39
54
} ,
40
55
{
41
56
test : / \. t s x ? $ / ,
42
- loader : 'ts-loader' ,
43
57
exclude : / n o d e _ m o d u l e s / ,
58
+ // eslint-disable-next-line node/no-unpublished-require
59
+ loader : require . resolve ( 'ts-loader' ) ,
44
60
options : {
61
+ getCustomTransformers : ( ) => ( {
62
+ before : [ isDevelopment && ReactRefreshTypeScript ( ) ] . filter ( Boolean ) ,
63
+ } ) ,
45
64
transpileOnly : true ,
46
65
} ,
47
66
} ,
@@ -96,6 +115,10 @@ const preloadEntries = windowData
96
115
97
116
const preloadConfig : Configuration = {
98
117
...commonConfig ,
118
+ devServer : {
119
+ ...commonConfig . devServer ,
120
+ port : 8083 ,
121
+ } ,
99
122
entry : Object . fromEntries ( preloadEntries ) ,
100
123
plugins : commonPlugins ,
101
124
target : 'electron-preload' ,
@@ -111,6 +134,10 @@ const rendererEntries = windowData
111
134
112
135
const rendererConfig : Configuration = {
113
136
...commonConfig ,
137
+ devServer : {
138
+ ...commonConfig . devServer ,
139
+ port : 8084 ,
140
+ } ,
114
141
entry : Object . fromEntries ( rendererEntries ) ,
115
142
plugins : commonPlugins . concat (
116
143
Object . values ( rendererEntries ) . map (
@@ -123,6 +150,10 @@ const rendererConfig: Configuration = {
123
150
124
151
const playbackPreloadBidiConfig : Configuration = {
125
152
...commonConfig ,
153
+ devServer : {
154
+ ...commonConfig . devServer ,
155
+ port : 8085 ,
156
+ } ,
126
157
entry : {
127
158
'playback-window-bidi-preload' : path . join (
128
159
__dirname ,
@@ -139,6 +170,10 @@ const playbackPreloadBidiConfig: Configuration = {
139
170
140
171
const playbackRendererBidiConfig : Configuration = {
141
172
...commonConfig ,
173
+ devServer : {
174
+ ...commonConfig . devServer ,
175
+ port : 8086 ,
176
+ } ,
142
177
entry : {
143
178
'playback-window-bidi-renderer' : path . join (
144
179
__dirname ,
@@ -149,23 +184,31 @@ const playbackRendererBidiConfig: Configuration = {
149
184
'renderer.tsx'
150
185
) ,
151
186
} ,
152
- plugins : commonPlugins . concat (
153
- getBrowserPlugin ( 'playback-window-bidi' ) as unknown as WebpackPluginInstance
154
- ) . concat (
155
- new CopyWebpackPlugin ( {
156
- patterns : [
157
- {
158
- from : 'src/browser/*.css' ,
159
- to : '[name].css' ,
160
- } ,
161
- ] ,
162
- } )
163
- ) ,
187
+ plugins : commonPlugins
188
+ . concat (
189
+ getBrowserPlugin (
190
+ 'playback-window-bidi'
191
+ ) as unknown as WebpackPluginInstance
192
+ )
193
+ . concat (
194
+ new CopyWebpackPlugin ( {
195
+ patterns : [
196
+ {
197
+ from : 'src/browser/*.css' ,
198
+ to : '[name].css' ,
199
+ } ,
200
+ ] ,
201
+ } )
202
+ ) ,
164
203
target : 'web' ,
165
204
}
166
205
167
206
const mainConfig : Configuration = {
168
207
...commonConfig ,
208
+ devServer : {
209
+ ...commonConfig . devServer ,
210
+ port : 8087 ,
211
+ } ,
169
212
entry : {
170
213
main : path . join ( __dirname , 'src' , 'main' , 'index.ts' ) ,
171
214
} ,
0 commit comments