Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove sourceMappingURL if it doesn't have the same name with the js … #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ UglifyWriter.prototype.processFile = function(inFile, outFile, relativePath, out

if (srcURL.existsIn(src)) {
let url = srcURL.getFrom(src);
let lastUrl = null;
// Make sure vendor.map is being used because vendor.js can have multiple sourceMappingURL if modules also have it.
while (url && url.match(/.+?(?=\.map$)/)[0] !== relativePath.match(/(.*\/)?(.+)\.js/)[2]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a heads-up, tests will be required

lastUrl = url;
src = srcURL.removeFrom(src);
url = srcURL.getFrom(src);
}
// If there is no map url which has an identical name with the js file, use the last one.
// It's possible we should rather raise an error instead.
if (!url) {
url = lastUrl;
}
let sourceMapPath = path.join(path.dirname(inFile), url);
if (fs.existsSync(sourceMapPath)) {
sourceMap.content = JSON.parse(fs.readFileSync(sourceMapPath));
Expand Down