@@ -63,6 +63,7 @@ const {
6363/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized } WebpackOptions */
6464/** @typedef {import("../Compiler") } Compiler */
6565/** @typedef {import("../Module") } Module */
66+ /** @typedef {import("./target").PlatformTargetProperties } PlatformTargetProperties */
6667/** @typedef {import("./target").TargetProperties } TargetProperties */
6768
6869const NODE_MODULES_REGEXP = / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / i;
@@ -147,9 +148,9 @@ const applyWebpackOptionsBaseDefaults = options => {
147148
148149/**
149150 * @param {WebpackOptions } options options to be modified
150- * @returns {void }
151+ * @returns {PlatformTargetProperties|false } platform target properties
151152 */
152- const applyWebpackOptionsDefaults = options => {
153+ const applyWebpackOptionsDefaultsAndResolveTargetProperties = options => {
153154 F ( options , "context" , ( ) => process . cwd ( ) ) ;
154155 F ( options , "target" , ( ) => {
155156 return getDefaultTarget ( /** @type {string } */ ( options . context ) ) ;
@@ -167,6 +168,15 @@ const applyWebpackOptionsDefaults = options => {
167168 /** @type {Context } */ ( options . context )
168169 ) ;
169170
171+ if ( targetProperties ) {
172+ D ( targetProperties , "web" , null ) ;
173+ D ( targetProperties , "browser" , null ) ;
174+ D ( targetProperties , "webworker" , null ) ;
175+ D ( targetProperties , "node" , null ) ;
176+ D ( targetProperties , "nwjs" , null ) ;
177+ D ( targetProperties , "electron" , null ) ;
178+ }
179+
170180 const development = mode === "development" ;
171181 const production = mode === "production" || ! mode ;
172182
@@ -315,6 +325,16 @@ const applyWebpackOptionsDefaults = options => {
315325 getResolveLoaderDefaults ( { cache } ) ,
316326 options . resolveLoader
317327 ) ;
328+
329+ if ( targetProperties === false ) return false ;
330+ return {
331+ web : targetProperties . web ,
332+ browser : targetProperties . browser ,
333+ webworker : targetProperties . webworker ,
334+ node : targetProperties . node ,
335+ nwjs : targetProperties . nwjs ,
336+ electron : targetProperties . electron
337+ } ;
318338} ;
319339
320340/**
@@ -1595,4 +1615,7 @@ const applyInfrastructureLoggingDefaults = infrastructureLogging => {
15951615} ;
15961616
15971617exports . applyWebpackOptionsBaseDefaults = applyWebpackOptionsBaseDefaults ;
1598- exports . applyWebpackOptionsDefaults = applyWebpackOptionsDefaults ;
1618+ exports . applyWebpackOptionsDefaults =
1619+ applyWebpackOptionsDefaultsAndResolveTargetProperties ;
1620+ exports . applyWebpackOptionsDefaultsAndResolvePlatformTargetProperties =
1621+ applyWebpackOptionsDefaultsAndResolveTargetProperties ;
0 commit comments