Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9908283

Browse files
committed
feat: consolidated sourceMap-related fields in devtool to enhance scalability and improve DX
1 parentea3ba3d commit9908283

File tree

8 files changed

+183
-21
lines changed

8 files changed

+183
-21
lines changed

‎declarations/WebpackOptions.d.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,31 @@ export type DevServer =
4646
/**
4747
* A developer tool to enhance debugging (false | eval | [inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map).
4848
*/
49-
exporttypeDevTool=(false|"eval")|string;
49+
exporttypeDevTool=
50+
|(false|"eval")
51+
|string
52+
|{
53+
/**
54+
* Similar to `devtool.moduleFilenameTemplate`, but used in the case of duplicate module identifiers.
55+
*/
56+
fallbackModuleFilenameTemplate?:string|((context:TODO)=>string);
57+
/**
58+
* Filename template string of function for the sources array in a generated SourceMap.
59+
*/
60+
moduleFilenameTemplate?:string|((context:TODO)=>string);
61+
/**
62+
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
63+
*/
64+
namespace?:string;
65+
/**
66+
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
67+
*/
68+
sourceMapFilename?:string;
69+
/**
70+
* Controls how source maps are generated.
71+
*/
72+
type:string;
73+
};
5074
/**
5175
* The entry point(s) of the compilation.
5276
*/

‎lib/WebpackOptionsApply.js‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,34 +275,48 @@ class WebpackOptionsApply extends OptionsApply {
275275
}
276276

277277
if(options.devtool){
278-
if(options.devtool.includes("source-map")){
279-
consthidden=options.devtool.includes("hidden");
280-
constinline=options.devtool.includes("inline");
281-
constevalWrapped=options.devtool.includes("eval");
282-
constcheap=options.devtool.includes("cheap");
283-
constmoduleMaps=options.devtool.includes("module");
284-
constnoSources=options.devtool.includes("nosources");
285-
constdebugIds=options.devtool.includes("debugids");
278+
constdevtool=
279+
typeofoptions.devtool==="object"
280+
?options.devtool
281+
:{type:options.devtool};
282+
283+
constnamespace=devtool.namespace||options.output.devtoolNamespace;
284+
constsourceMapFilename=
285+
devtool.sourceMapFilename||options.output.sourceMapFilename;
286+
constmoduleFilenameTemplate=
287+
devtool.moduleFilenameTemplate||
288+
options.output.devtoolModuleFilenameTemplate;
289+
constfallbackModuleFilenameTemplate=
290+
devtool.fallbackModuleFilenameTemplate||
291+
options.output.devtoolFallbackModuleFilenameTemplate;
292+
293+
if(devtool.type.includes("source-map")){
294+
consthidden=devtool.type.includes("hidden");
295+
constinline=devtool.type.includes("inline");
296+
constevalWrapped=devtool.type.includes("eval");
297+
constcheap=devtool.type.includes("cheap");
298+
constmoduleMaps=devtool.type.includes("module");
299+
constnoSources=devtool.type.includes("nosources");
300+
constdebugIds=devtool.type.includes("debugids");
286301
constPlugin=evalWrapped
287302
?require("./EvalSourceMapDevToolPlugin")
288303
:require("./SourceMapDevToolPlugin");
289304
newPlugin({
290-
filename:inline ?null :options.output.sourceMapFilename,
291-
moduleFilenameTemplate:options.output.devtoolModuleFilenameTemplate,
292-
fallbackModuleFilenameTemplate:
293-
options.output.devtoolFallbackModuleFilenameTemplate,
305+
filename:inline ?null :sourceMapFilename,
306+
moduleFilenameTemplate,
307+
fallbackModuleFilenameTemplate,
294308
append:hidden ?false :undefined,
295309
module:moduleMaps ?true :!cheap,
296310
columns:!cheap,
297311
noSources,
298-
namespace:options.output.devtoolNamespace,
312+
namespace,
299313
debugIds
300314
}).apply(compiler);
301-
}elseif(options.devtool.includes("eval")){
315+
}elseif(devtool.type.includes("eval")){
302316
constEvalDevToolModulePlugin=require("./EvalDevToolModulePlugin");
303317
newEvalDevToolModulePlugin({
304-
moduleFilenameTemplate:options.output.devtoolModuleFilenameTemplate,
305-
namespace:options.output.devtoolNamespace
318+
moduleFilenameTemplate,
319+
namespace
306320
}).apply(compiler);
307321
}
308322
}

‎lib/config/defaults.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
/**@typedef {import("../../declarations/WebpackOptions").Context} Context */
3636
/**@typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
3737
/**@typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
38+
/**@typedef {import("../../declarations/WebpackOptions").DevTool} DevTool */
3839
/**@typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
3940
/**@typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
4041
/**@typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
@@ -200,7 +201,6 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
200201
}
201202
}
202203

203-
F(options,"devtool",()=>(development ?"eval" :false));
204204
D(options,"watch",false);
205205
D(options,"profile",false);
206206
D(options,"parallelism",100);
@@ -254,6 +254,11 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
254254
(options.experiments.asyncWebAssembly)
255255
});
256256

257+
F(options,"devtool",()=>(development ?"eval" :false));
258+
applyDevtoolDefaults(/**@type {NonNullable<DevTool>} */(options.devtool),{
259+
output:options.output
260+
});
261+
257262
applyModuleDefaults(options.module,{
258263
cache,
259264
syncWebAssembly:
@@ -1734,6 +1739,18 @@ const applyInfrastructureLoggingDefaults = infrastructureLogging => {
17341739
D(infrastructureLogging,"appendOnly",!tty);
17351740
};
17361741

1742+
/**
1743+
*@param {DevTool} devtool devtool options
1744+
*@param {object} options options
1745+
*@param {Output} options.output output options
1746+
*@returns {void}
1747+
*/
1748+
constapplyDevtoolDefaults=(devtool,{ output})=>{
1749+
if(typeofdevtool!=="object")return;
1750+
F(devtool,"namespace",()=>output.uniqueName);
1751+
D(devtool,"sourceMapFilename","[file].map[query]");
1752+
};
1753+
17371754
module.exports.applyWebpackOptionsBaseDefaults=
17381755
applyWebpackOptionsBaseDefaults;
17391756
module.exports.applyWebpackOptionsDefaults=applyWebpackOptionsDefaults;

‎lib/config/normalization.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,12 @@ const getNormalizedWebpackOptions = config => ({
324324
clean:output.clean,
325325
compareBeforeEmit:output.compareBeforeEmit,
326326
crossOriginLoading:output.crossOriginLoading,
327+
// TODO webpack 6 remove `output.devtoolFallbackModuleFilenameTemplate` in favor of `devtool.fallbackModuleFilenameTemplate`
327328
devtoolFallbackModuleFilenameTemplate:
328329
output.devtoolFallbackModuleFilenameTemplate,
330+
// TODO webpack 6 remove `output.devtoolModuleFilenameTemplate` in favor of `devtool.moduleFilenameTemplate`
329331
devtoolModuleFilenameTemplate:output.devtoolModuleFilenameTemplate,
332+
// TODO webpack 6 remove `output.devtoolNamespace` in favor of `devtool.namespace`
330333
devtoolNamespace:output.devtoolNamespace,
331334
environment:cloneObject(output.environment),
332335
enabledChunkLoadingTypes:output.enabledChunkLoadingTypes
@@ -380,6 +383,7 @@ const getNormalizedWebpackOptions = config => ({
380383
path:output.path,
381384
pathinfo:output.pathinfo,
382385
publicPath:output.publicPath,
386+
// TODO webpack 6 remove `output.sourceMapFilename` in favor of `devtool.sourceMapFilename`
383387
sourceMapFilename:output.sourceMapFilename,
384388
sourcePrefix:output.sourcePrefix,
385389
strictModuleErrorHandling:output.strictModuleErrorHandling,

‎schemas/WebpackOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎schemas/WebpackOptions.json‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,51 @@
593593
{
594594
"type":"string",
595595
"pattern":"^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map(-debugids)?$"
596+
},
597+
{
598+
"type":"object",
599+
"additionalProperties":false,
600+
"properties": {
601+
"fallbackModuleFilenameTemplate": {
602+
"description":"Similar to `devtool.moduleFilenameTemplate`, but used in the case of duplicate module identifiers.",
603+
"anyOf": [
604+
{
605+
"type":"string"
606+
},
607+
{
608+
"instanceof":"Function",
609+
"tsType":"((context: TODO) => string)"
610+
}
611+
]
612+
},
613+
"moduleFilenameTemplate": {
614+
"description":"Filename template string of function for the sources array in a generated SourceMap.",
615+
"anyOf": [
616+
{
617+
"type":"string"
618+
},
619+
{
620+
"instanceof":"Function",
621+
"tsType":"((context: TODO) => string)"
622+
}
623+
]
624+
},
625+
"namespace": {
626+
"description":"Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.",
627+
"type":"string"
628+
},
629+
"sourceMapFilename": {
630+
"description":"The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.",
631+
"type":"string",
632+
"absolutePath":false
633+
},
634+
"type": {
635+
"description":"Controls how source maps are generated.",
636+
"type":"string",
637+
"pattern":"^(inline-|hidden-|eval-)?(nosources-)?(cheap-(module-)?)?source-map(-debugids)?$"
638+
}
639+
},
640+
"required": ["type"]
596641
}
597642
]
598643
},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const{ describeCases}=require("./TestCases.template");
2+
3+
describe("TestCases",()=>{
4+
describeCases({
5+
name:"devtool-object-notation-cheap-source-map",
6+
devtool:{
7+
type:"cheap-source-map"
8+
}
9+
});
10+
});

‎types.d.ts‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,31 @@ declare interface Configuration {
26162616
/**
26172617
* A developer tool to enhance debugging (false | eval | [inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map).
26182618
*/
2619-
devtool?:string|false;
2619+
devtool?:
2620+
|string
2621+
|false
2622+
|{
2623+
/**
2624+
* Similar to `devtool.moduleFilenameTemplate`, but used in the case of duplicate module identifiers.
2625+
*/
2626+
fallbackModuleFilenameTemplate?:string|((context?:any)=>string);
2627+
/**
2628+
* Filename template string of function for the sources array in a generated SourceMap.
2629+
*/
2630+
moduleFilenameTemplate?:string|((context?:any)=>string);
2631+
/**
2632+
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
2633+
*/
2634+
namespace?:string;
2635+
/**
2636+
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
2637+
*/
2638+
sourceMapFilename?:string;
2639+
/**
2640+
* Controls how source maps are generated.
2641+
*/
2642+
type:string;
2643+
};
26202644

26212645
/**
26222646
* The entry point(s) of the compilation.
@@ -15989,7 +16013,31 @@ declare interface WebpackOptionsNormalized {
1598916013
/**
1599016014
* A developer tool to enhance debugging (false | eval | [inline-|hidden-|eval-][nosources-][cheap-[module-]]source-map).
1599116015
*/
15992-
devtool?:string|false;
16016+
devtool?:
16017+
|string
16018+
|false
16019+
|{
16020+
/**
16021+
* Similar to `devtool.moduleFilenameTemplate`, but used in the case of duplicate module identifiers.
16022+
*/
16023+
fallbackModuleFilenameTemplate?:string|((context?:any)=>string);
16024+
/**
16025+
* Filename template string of function for the sources array in a generated SourceMap.
16026+
*/
16027+
moduleFilenameTemplate?:string|((context?:any)=>string);
16028+
/**
16029+
* Module namespace to use when interpolating filename template string for the sources array in a generated SourceMap. Defaults to `output.library` if not set. It's useful for avoiding runtime collisions in sourcemaps from multiple webpack projects built as libraries.
16030+
*/
16031+
namespace?:string;
16032+
/**
16033+
* The filename of the SourceMaps for the JavaScript files. They are inside the 'output.path' directory.
16034+
*/
16035+
sourceMapFilename?:string;
16036+
/**
16037+
* Controls how source maps are generated.
16038+
*/
16039+
type:string;
16040+
};
1599316041

1599416042
/**
1599516043
* The entry point(s) of the compilation.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp