1
1
import fs from 'fs' ;
2
- import type { ResolveOptions , WebpackPluginInstance } from 'webpack' ;
2
+ import type {
3
+ ResolveOptions ,
4
+ WebpackPluginInstance ,
5
+ Configuration ,
6
+ } from 'webpack' ;
3
7
import { merge } from 'webpack-merge' ;
4
8
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin' ;
5
9
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -12,6 +16,7 @@ import { WebpackPluginStartElectron } from './webpack-plugin-start-electron';
12
16
import type { ConfigArgs , WebpackConfig , WebpackCLIArgs } from './args' ;
13
17
import { isServe , webpackArgsWithDefaults } from './args' ;
14
18
import {
19
+ sourceMapLoader ,
15
20
javascriptLoader ,
16
21
nodeLoader ,
17
22
sourceLoader ,
@@ -31,6 +36,17 @@ import { sharedExternals, pluginExternals } from './externals';
31
36
import { WebpackPluginMulticompilerProgress } from './webpack-plugin-multicompiler-progress' ;
32
37
import MiniCssExtractPlugin from 'mini-css-extract-plugin' ;
33
38
39
+ const sharedIgnoreWarnings : NonNullable < Configuration [ 'ignoreWarnings' ] > = [
40
+ // Usually caused by published d.ts files pointing to non-existent ts files in
41
+ // the ignored for publish source folder
42
+ / F a i l e d t o p a r s e s o u r c e m a p .+ ?E N O E N T / ,
43
+ // Expected in most cases for Compass
44
+ / r e q u i r e f u n c t i o n i s u s e d i n a w a y i n w h i c h d e p e n d e n c i e s c a n n o t b e s t a t i c a l l y e x t r a c t e d / ,
45
+ / t h e r e q u e s t o f a d e p e n d e n c y i s a n e x p r e s s i o n / ,
46
+ // Optional, platform-specific dependencies (mostly from driver)
47
+ / M o d u l e n o t f o u n d .+ ?( m o n g o _ c r y p t _ v 1 .( d l l | s o | d y l i b ) | @ m o n g o d b - j s \/ z s t d | a w s - c r t | g c p - m e t a d a t a ) / ,
48
+ ] ;
49
+
34
50
const sharedResolveOptions = (
35
51
target : ConfigArgs [ 'target' ]
36
52
) : Pick <
@@ -96,6 +112,7 @@ export function createElectronMainConfig(
96
112
target : opts . target ,
97
113
module : {
98
114
rules : [
115
+ sourceMapLoader ( opts ) ,
99
116
javascriptLoader ( opts ) ,
100
117
nodeLoader ( opts ) ,
101
118
resourceLoader ( opts ) ,
@@ -111,6 +128,7 @@ export function createElectronMainConfig(
111
128
...sharedResolveOptions ( opts . target ) ,
112
129
} ,
113
130
plugins : [ new WebpackPluginMulticompilerProgress ( ) ] ,
131
+ ignoreWarnings : sharedIgnoreWarnings ,
114
132
} ;
115
133
116
134
return merge < WebpackConfig > (
@@ -153,15 +171,17 @@ export function createElectronRendererConfig(
153
171
path : opts . outputPath ,
154
172
filename : opts . outputFilename ?? '[name].[contenthash].renderer.js' ,
155
173
assetModuleFilename : 'assets/[name].[hash][ext]' ,
156
- library : getLibraryNameFromCwd ( opts . cwd ) ,
174
+ library : opts . library ?? getLibraryNameFromCwd ( opts . cwd ) ,
157
175
libraryTarget : 'umd' ,
158
176
strictModuleErrorHandling : true ,
159
177
strictModuleExceptionHandling : true ,
178
+ globalObject : 'globalThis' ,
160
179
} ,
161
180
mode : opts . mode ,
162
181
target : opts . target ,
163
182
module : {
164
183
rules : [
184
+ sourceMapLoader ( opts ) ,
165
185
javascriptLoader ( opts ) ,
166
186
nodeLoader ( opts ) ,
167
187
cssLoader ( opts ) ,
@@ -182,6 +202,7 @@ export function createElectronRendererConfig(
182
202
aliasFields : [ ] ,
183
203
...sharedResolveOptions ( opts . target ) ,
184
204
} ,
205
+ ignoreWarnings : sharedIgnoreWarnings ,
185
206
} ;
186
207
187
208
return merge < WebpackConfig > (
@@ -263,7 +284,7 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
263
284
path : opts . outputPath ,
264
285
filename : opts . outputFilename ?? '[name].js' ,
265
286
assetModuleFilename : 'assets/[name][ext]' ,
266
- library : getLibraryNameFromCwd ( opts . cwd ) ,
287
+ library : opts . library ?? getLibraryNameFromCwd ( opts . cwd ) ,
267
288
libraryTarget : 'umd' ,
268
289
// These two options are subtly different, and while
269
290
// `strictModuleExceptionHandling` is deprecated, it is the only
@@ -274,11 +295,13 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
274
295
// typical development mode that we work in.
275
296
strictModuleErrorHandling : true ,
276
297
strictModuleExceptionHandling : true ,
298
+ globalObject : 'globalThis' ,
277
299
} ,
278
300
mode : opts . mode ,
279
301
target : opts . target ,
280
302
module : {
281
303
rules : [
304
+ sourceMapLoader ( opts ) ,
282
305
javascriptLoader ( opts , true ) ,
283
306
nodeLoader ( opts ) ,
284
307
cssLoader ( opts , true ) ,
@@ -297,6 +320,7 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
297
320
resolve : {
298
321
...sharedResolveOptions ( opts . target ) ,
299
322
} ,
323
+ ignoreWarnings : sharedIgnoreWarnings ,
300
324
} ;
301
325
}
302
326
0 commit comments