1+ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
12import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
23import fs from 'fs'
34import CopyWebpackPlugin from 'copy-webpack-plugin'
45import HtmlWebpackPlugin from 'html-webpack-plugin'
56import kebabCase from 'lodash/fp/kebabCase'
67import MiniCssExtractPlugin from 'mini-css-extract-plugin'
78import path from 'path'
9+ // eslint-disable-next-line node/no-unpublished-import
10+ import ReactRefreshTypeScript from 'react-refresh-typescript'
811import {
912 Configuration ,
1013 SourceMapDevToolPlugin ,
1114 WebpackPluginInstance ,
1215} from 'webpack'
16+ // eslint-disable-next-line node/no-unpublished-import
17+ import type { Configuration as DevServerConfiguration } from 'webpack-dev-server'
1318
1419const isProduction = process . env . NODE_ENV === 'production'
20+ const isDevelopment = ! isProduction
1521
1622const commonPlugins : WebpackPluginInstance [ ] = [
1723 new ForkTsCheckerWebpackPlugin ( ) ,
@@ -22,11 +28,20 @@ const commonPlugins: WebpackPluginInstance[] = [
2228if ( isProduction ) {
2329 commonPlugins . push ( new MiniCssExtractPlugin ( ) )
2430}
31+ if ( isDevelopment ) {
32+ commonPlugins . push ( new ReactRefreshWebpackPlugin ( ) )
33+ }
2534
2635const commonConfig : Pick <
2736 Configuration ,
2837 'devtool' | 'externals' | 'mode' | 'module' | 'resolve' | 'output'
29- > = {
38+ > & {
39+ devServer ?: DevServerConfiguration
40+ } = {
41+ devServer : {
42+ hot : isDevelopment ,
43+ port : 8081 ,
44+ } ,
3045 devtool : 'source-map' ,
3146 externals : [ 'utf-8-validate' , 'bufferutil' ] ,
3247 mode : isProduction ? 'production' : 'development' ,
@@ -39,9 +54,13 @@ const commonConfig: Pick<
3954 } ,
4055 {
4156 test : / \. t s x ? $ / ,
42- loader : 'ts-loader' ,
4357 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' ) ,
4460 options : {
61+ getCustomTransformers : ( ) => ( {
62+ before : [ isDevelopment && ReactRefreshTypeScript ( ) ] . filter ( Boolean ) ,
63+ } ) ,
4564 transpileOnly : true ,
4665 } ,
4766 } ,
@@ -96,6 +115,10 @@ const preloadEntries = windowData
96115
97116const preloadConfig : Configuration = {
98117 ...commonConfig ,
118+ devServer : {
119+ ...commonConfig . devServer ,
120+ port : 8083 ,
121+ } ,
99122 entry : Object . fromEntries ( preloadEntries ) ,
100123 plugins : commonPlugins ,
101124 target : 'electron-preload' ,
@@ -111,6 +134,10 @@ const rendererEntries = windowData
111134
112135const rendererConfig : Configuration = {
113136 ...commonConfig ,
137+ devServer : {
138+ ...commonConfig . devServer ,
139+ port : 8084 ,
140+ } ,
114141 entry : Object . fromEntries ( rendererEntries ) ,
115142 plugins : commonPlugins . concat (
116143 Object . values ( rendererEntries ) . map (
@@ -123,6 +150,10 @@ const rendererConfig: Configuration = {
123150
124151const playbackPreloadBidiConfig : Configuration = {
125152 ...commonConfig ,
153+ devServer : {
154+ ...commonConfig . devServer ,
155+ port : 8085 ,
156+ } ,
126157 entry : {
127158 'playback-window-bidi-preload' : path . join (
128159 __dirname ,
@@ -139,6 +170,10 @@ const playbackPreloadBidiConfig: Configuration = {
139170
140171const playbackRendererBidiConfig : Configuration = {
141172 ...commonConfig ,
173+ devServer : {
174+ ...commonConfig . devServer ,
175+ port : 8086 ,
176+ } ,
142177 entry : {
143178 'playback-window-bidi-renderer' : path . join (
144179 __dirname ,
@@ -149,23 +184,31 @@ const playbackRendererBidiConfig: Configuration = {
149184 'renderer.tsx'
150185 ) ,
151186 } ,
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+ ) ,
164203 target : 'web' ,
165204}
166205
167206const mainConfig : Configuration = {
168207 ...commonConfig ,
208+ devServer : {
209+ ...commonConfig . devServer ,
210+ port : 8087 ,
211+ } ,
169212 entry : {
170213 main : path . join ( __dirname , 'src' , 'main' , 'index.ts' ) ,
171214 } ,
0 commit comments