@@ -76,6 +76,7 @@ const { cleverMerge } = require("./util/cleverMerge");
7676
7777/** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction } WebpackPluginFunction */
7878/** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults } WebpackOptions */
79+ /** @typedef {import("./config/normalization").WebpackOptionsInterception } WebpackOptionsInterception */
7980/** @typedef {import("./Compiler") } Compiler */
8081/** @typedef {import("./util/fs").InputFileSystem } InputFileSystem */
8182/** @typedef {import("./util/fs").IntermediateFileSystem } IntermediateFileSystem */
@@ -90,9 +91,10 @@ class WebpackOptionsApply extends OptionsApply {
9091 /**
9192 * @param {WebpackOptions } options options object
9293 * @param {Compiler } compiler compiler object
94+ * @param {WebpackOptionsInterception= } interception intercepted options
9395 * @returns {WebpackOptions } options object
9496 */
95- process ( options , compiler ) {
97+ process ( options , compiler , interception ) {
9698 compiler . outputPath = options . output . path ;
9799 compiler . recordsInputPath = options . recordsInputPath || null ;
98100 compiler . recordsOutputPath = options . recordsOutputPath || null ;
@@ -315,37 +317,59 @@ class WebpackOptionsApply extends OptionsApply {
315317 ) . apply ( compiler ) ;
316318 }
317319
318- if ( options . devtool ) {
319- if ( options . devtool . includes ( "source-map" ) ) {
320- const hidden = options . devtool . includes ( "hidden" ) ;
321- const inline = options . devtool . includes ( "inline" ) ;
322- const evalWrapped = options . devtool . includes ( "eval" ) ;
323- const cheap = options . devtool . includes ( "cheap" ) ;
324- const moduleMaps = options . devtool . includes ( "module" ) ;
325- const noSources = options . devtool . includes ( "nosources" ) ;
326- const debugIds = options . devtool . includes ( "debugids" ) ;
327- const Plugin = evalWrapped
328- ? require ( "./EvalSourceMapDevToolPlugin" )
329- : require ( "./SourceMapDevToolPlugin" ) ;
330- new Plugin ( {
331- filename : inline ? null : options . output . sourceMapFilename ,
332- moduleFilenameTemplate : options . output . devtoolModuleFilenameTemplate ,
333- fallbackModuleFilenameTemplate :
334- options . output . devtoolFallbackModuleFilenameTemplate ,
335- append : hidden ? false : undefined ,
336- module : moduleMaps ? true : ! cheap ,
337- columns : ! cheap ,
338- noSources,
339- namespace : options . output . devtoolNamespace ,
340- debugIds
341- } ) . apply ( compiler ) ;
342- } else if ( options . devtool . includes ( "eval" ) ) {
343- const EvalDevToolModulePlugin = require ( "./EvalDevToolModulePlugin" ) ;
320+ let devtool =
321+ interception === undefined ? options . devtool : interception . devtool ;
322+ devtool = Array . isArray ( devtool )
323+ ? devtool
324+ : typeof devtool === "string"
325+ ? [ { type : "all" , use : devtool } ]
326+ : [ ] ;
327+
328+ for ( const item of devtool ) {
329+ const { type, use } = item ;
330+
331+ if ( use ) {
332+ if ( use . includes ( "source-map" ) ) {
333+ const hidden = use . includes ( "hidden" ) ;
334+ const inline = use . includes ( "inline" ) ;
335+ const evalWrapped = use . includes ( "eval" ) ;
336+ const cheap = use . includes ( "cheap" ) ;
337+ const moduleMaps = use . includes ( "module" ) ;
338+ const noSources = use . includes ( "nosources" ) ;
339+ const debugIds = use . includes ( "debugids" ) ;
340+ const Plugin = evalWrapped
341+ ? require ( "./EvalSourceMapDevToolPlugin" )
342+ : require ( "./SourceMapDevToolPlugin" ) ;
343+ const assetExt =
344+ type === "javascript"
345+ ? / \. ( ( c | m ) ? j s ) ( $ | \? ) / i
346+ : type === "css"
347+ ? / \. ( c s s ) ( $ | \? ) / i
348+ : / \. ( ( c | m ) ? j s | c s s ) ( $ | \? ) / i;
349+
350+ new Plugin ( {
351+ test : evalWrapped ? undefined : assetExt ,
352+ filename : inline ? null : options . output . sourceMapFilename ,
353+ moduleFilenameTemplate :
354+ options . output . devtoolModuleFilenameTemplate ,
355+ fallbackModuleFilenameTemplate :
356+ options . output . devtoolFallbackModuleFilenameTemplate ,
357+ append : hidden ? false : undefined ,
358+ module : moduleMaps ? true : ! cheap ,
359+ columns : ! cheap ,
360+ noSources,
361+ namespace : options . output . devtoolNamespace ,
362+ debugIds
363+ } ) . apply ( compiler ) ;
364+ } else if ( use . includes ( "eval" ) ) {
365+ const EvalDevToolModulePlugin = require ( "./EvalDevToolModulePlugin" ) ;
344366
345- new EvalDevToolModulePlugin ( {
346- moduleFilenameTemplate : options . output . devtoolModuleFilenameTemplate ,
347- namespace : options . output . devtoolNamespace
348- } ) . apply ( compiler ) ;
367+ new EvalDevToolModulePlugin ( {
368+ moduleFilenameTemplate :
369+ options . output . devtoolModuleFilenameTemplate ,
370+ namespace : options . output . devtoolNamespace
371+ } ) . apply ( compiler ) ;
372+ }
349373 }
350374 }
351375
0 commit comments