Skip to content

Commit

Permalink
[FIX] bundle/Builder: Remove sourceMappingURL from modules embedded a…
Browse files Browse the repository at this point in the history
…s string

Leaving the reference will cause browser development tools to create
unnecessary requests. The minify task will always add these references,
and we already remove them in all other bundling modes.

In the case I analyzed (internal ref 2380057784), the source map
requests even used incorrect URLs containing the string '<unknown>',
possibly because they are only created when the module es eval'ed.
  • Loading branch information
RandomByte committed Jun 5, 2023
1 parent d96d28c commit a2f410c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,20 @@ class BundleBuilder {
} else if ( /\.js$/.test(moduleName) /* implicitly: && info != null && info.requiresTopLevelScope */ ) {
log.warn(
`Module ${moduleName} requires top level scope and can only be embedded as a string (requires 'eval')`);
outW.write( makeStringLiteral( (await resource.buffer()).toString() ) );
let moduleContent = (await resource.buffer()).toString();
if (this.options.sourceMap) {
// We are actually not interested in the source map this module might contain,
// but we should make sure to remove any "sourceMappingURL" from the module content before
// writing it to the bundle. Otherwise browser dev-tools might create unnecessary (and likely incorrect)
// requests for any referenced .map files
({moduleContent} =
await this.getSourceMapForModule({
moduleName,
moduleContent,
resourcePath: resource.getPath()
}));
}
outW.write( makeStringLiteral(moduleContent) );
} else if ( /\.html$/.test(moduleName) ) {
const fileContent = (await resource.buffer()).toString();
outW.write( makeStringLiteral( fileContent ) );
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2f410c

Please sign in to comment.