1
1
const path = require ( 'path' ) ;
2
2
const CopyPlugin = require ( 'copy-webpack-plugin' ) ;
3
3
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
4
- const lodash = require ( 'lodash' ) ;
5
4
const TsconfigPathsPlugin = require ( 'tsconfig-paths-webpack-plugin' ) ;
5
+ const { merge } = require ( 'webpack-merge' ) ;
6
6
7
7
function srcPaths ( src ) {
8
8
return path . join ( __dirname , src ) ;
@@ -11,7 +11,6 @@ function srcPaths(src) {
11
11
const isEnvProduction = process . env . NODE_ENV === 'production' ;
12
12
const isEnvDevelopment = process . env . NODE_ENV === 'development' ;
13
13
14
- // #region Common settings
15
14
const commonConfig = {
16
15
devtool : isEnvDevelopment ? 'source-map' : false ,
17
16
mode : isEnvProduction ? 'production' : 'development' ,
@@ -45,51 +44,53 @@ const commonConfig = {
45
44
] ,
46
45
} ,
47
46
} ;
48
- // #endregion
49
47
50
- const mainConfig = lodash . cloneDeep ( commonConfig ) ;
51
- mainConfig . entry = './src/main/main.ts' ;
52
- mainConfig . target = 'electron-main' ;
53
- mainConfig . output . filename = 'main.bundle.js' ;
54
- mainConfig . plugins = [
55
- new CopyPlugin ( {
56
- patterns : [
57
- {
58
- from : 'package.json' ,
59
- to : 'package.json' ,
60
- transform : ( content , _path ) => {
61
- const jsonContent = JSON . parse ( content ) ;
62
- const electronVersion = jsonContent . devDependencies . electron ;
48
+ const mainConfig = merge ( commonConfig , {
49
+ entry : './src/main/main.ts' ,
50
+ target : 'electron-main' ,
51
+ output : { filename : 'main.bundle.js' } ,
52
+ plugins : [
53
+ new CopyPlugin ( {
54
+ patterns : [
55
+ {
56
+ from : 'package.json' ,
57
+ to : 'package.json' ,
58
+ transform : ( content , _path ) => {
59
+ const jsonContent = JSON . parse ( content ) ;
60
+ const electronVersion = jsonContent . devDependencies . electron ;
63
61
64
- delete jsonContent . devDependencies ;
65
- delete jsonContent . optionalDependencies ;
66
- delete jsonContent . scripts ;
67
- delete jsonContent . build ;
62
+ delete jsonContent . devDependencies ;
63
+ delete jsonContent . optionalDependencies ;
64
+ delete jsonContent . scripts ;
65
+ delete jsonContent . build ;
68
66
69
- jsonContent . main = './main.bundle.js' ;
70
- jsonContent . scripts = { start : 'electron ./main.bundle.js' } ;
71
- jsonContent . devDependencies = { electron : electronVersion } ;
67
+ jsonContent . main = './main.bundle.js' ;
68
+ jsonContent . scripts = { start : 'electron ./main.bundle.js' } ;
69
+ jsonContent . devDependencies = { electron : electronVersion } ;
72
70
73
- return JSON . stringify ( jsonContent , undefined , 2 ) ;
71
+ return JSON . stringify ( jsonContent , undefined , 2 ) ;
72
+ } ,
74
73
} ,
75
- } ,
76
- ] ,
77
- } ) ,
78
- ] ;
74
+ ] ,
75
+ } ) ,
76
+ ] ,
77
+ } ) ;
79
78
80
- const preloadConfig = lodash . cloneDeep ( commonConfig ) ;
81
- preloadConfig . entry = './src/preload/preload.ts' ;
82
- preloadConfig . target = 'electron-preload' ;
83
- preloadConfig . output . filename = 'preload.bundle.js' ;
79
+ const preloadConfig = merge ( commonConfig , {
80
+ entry : './src/preload/preload.ts' ,
81
+ target : 'electron-preload' ,
82
+ output : { filename : 'preload.bundle.js' } ,
83
+ } ) ;
84
84
85
- const rendererConfig = lodash . cloneDeep ( commonConfig ) ;
86
- rendererConfig . entry = './src/renderer/renderer.tsx' ;
87
- rendererConfig . target = 'electron-renderer' ;
88
- rendererConfig . output . filename = 'renderer.bundle.js' ;
89
- rendererConfig . plugins = [
90
- new HtmlWebpackPlugin ( {
91
- template : path . resolve ( __dirname , './public/index.html' ) ,
92
- } ) ,
93
- ] ;
85
+ const rendererConfig = merge ( commonConfig , {
86
+ entry : './src/renderer/renderer.tsx' ,
87
+ target : 'electron-renderer' ,
88
+ output : { filename : 'renderer.bundle.js' } ,
89
+ plugins : [
90
+ new HtmlWebpackPlugin ( {
91
+ template : path . resolve ( __dirname , './public/index.html' ) ,
92
+ } ) ,
93
+ ] ,
94
+ } ) ;
94
95
95
96
module . exports = [ mainConfig , preloadConfig , rendererConfig ] ;
0 commit comments