11import fs from 'fs' ;
2- import type { ResolveOptions , WebpackPluginInstance } from 'webpack' ;
2+ import type {
3+ ResolveOptions ,
4+ WebpackPluginInstance ,
5+ Configuration ,
6+ } from 'webpack' ;
37import { merge } from 'webpack-merge' ;
48import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin' ;
59// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -12,6 +16,7 @@ import { WebpackPluginStartElectron } from './webpack-plugin-start-electron';
1216import type { ConfigArgs , WebpackConfig , WebpackCLIArgs } from './args' ;
1317import { isServe , webpackArgsWithDefaults } from './args' ;
1418import {
19+ sourceMapLoader ,
1520 javascriptLoader ,
1621 nodeLoader ,
1722 sourceLoader ,
@@ -31,6 +36,17 @@ import { sharedExternals, pluginExternals } from './externals';
3136import { WebpackPluginMulticompilerProgress } from './webpack-plugin-multicompiler-progress' ;
3237import MiniCssExtractPlugin from 'mini-css-extract-plugin' ;
3338
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+
3450const sharedResolveOptions = (
3551 target : ConfigArgs [ 'target' ]
3652) : Pick <
@@ -96,6 +112,7 @@ export function createElectronMainConfig(
96112 target : opts . target ,
97113 module : {
98114 rules : [
115+ sourceMapLoader ( opts ) ,
99116 javascriptLoader ( opts ) ,
100117 nodeLoader ( opts ) ,
101118 resourceLoader ( opts ) ,
@@ -111,6 +128,7 @@ export function createElectronMainConfig(
111128 ...sharedResolveOptions ( opts . target ) ,
112129 } ,
113130 plugins : [ new WebpackPluginMulticompilerProgress ( ) ] ,
131+ ignoreWarnings : sharedIgnoreWarnings ,
114132 } ;
115133
116134 return merge < WebpackConfig > (
@@ -153,15 +171,17 @@ export function createElectronRendererConfig(
153171 path : opts . outputPath ,
154172 filename : opts . outputFilename ?? '[name].[contenthash].renderer.js' ,
155173 assetModuleFilename : 'assets/[name].[hash][ext]' ,
156- library : getLibraryNameFromCwd ( opts . cwd ) ,
174+ library : opts . library ?? getLibraryNameFromCwd ( opts . cwd ) ,
157175 libraryTarget : 'umd' ,
158176 strictModuleErrorHandling : true ,
159177 strictModuleExceptionHandling : true ,
178+ globalObject : 'globalThis' ,
160179 } ,
161180 mode : opts . mode ,
162181 target : opts . target ,
163182 module : {
164183 rules : [
184+ sourceMapLoader ( opts ) ,
165185 javascriptLoader ( opts ) ,
166186 nodeLoader ( opts ) ,
167187 cssLoader ( opts ) ,
@@ -182,6 +202,7 @@ export function createElectronRendererConfig(
182202 aliasFields : [ ] ,
183203 ...sharedResolveOptions ( opts . target ) ,
184204 } ,
205+ ignoreWarnings : sharedIgnoreWarnings ,
185206 } ;
186207
187208 return merge < WebpackConfig > (
@@ -263,7 +284,7 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
263284 path : opts . outputPath ,
264285 filename : opts . outputFilename ?? '[name].js' ,
265286 assetModuleFilename : 'assets/[name][ext]' ,
266- library : getLibraryNameFromCwd ( opts . cwd ) ,
287+ library : opts . library ?? getLibraryNameFromCwd ( opts . cwd ) ,
267288 libraryTarget : 'umd' ,
268289 // These two options are subtly different, and while
269290 // `strictModuleExceptionHandling` is deprecated, it is the only
@@ -274,11 +295,13 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
274295 // typical development mode that we work in.
275296 strictModuleErrorHandling : true ,
276297 strictModuleExceptionHandling : true ,
298+ globalObject : 'globalThis' ,
277299 } ,
278300 mode : opts . mode ,
279301 target : opts . target ,
280302 module : {
281303 rules : [
304+ sourceMapLoader ( opts ) ,
282305 javascriptLoader ( opts , true ) ,
283306 nodeLoader ( opts ) ,
284307 cssLoader ( opts , true ) ,
@@ -297,6 +320,7 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
297320 resolve : {
298321 ...sharedResolveOptions ( opts . target ) ,
299322 } ,
323+ ignoreWarnings : sharedIgnoreWarnings ,
300324 } ;
301325}
302326
0 commit comments