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

CLI doesn't add sourceMappingURL line to minified output #2284

Closed
garybernhardt opened this issue Aug 20, 2017 · 2 comments
Closed

CLI doesn't add sourceMappingURL line to minified output #2284

garybernhardt opened this issue Aug 20, 2017 · 2 comments

Comments

@garybernhardt
Copy link

Bug report or feature request?

Bug report

ES5 or ES6+ input?

ES6, but minimal repro shows that it doesn't make a difference.

Uglify version (uglifyjs -V)

$ uglifyjs -V
uglify-es 3.0.28

I tried release 3.0.28, the current HEAD of the harmony branch (067d52b), and also went back to the earliest published 3.x version (3.0.2). Same behavior in all three cases.

The uglifyjs CLI command executed or minify() options used.

Create two files:

$ echo "console.log(1)" > js/file1.js
$ echo "console.log(2)" > js/file2.js

Uglify them using exactly the command specified in the "CLI source map options" section of the docs:

$ uglifyjs js/file1.js js/file2.js \
         -o foo.min.js -c -m \
         --source-map root="http://foo.com/src",url=foo.min.js.map

The uglified output doesn't contain a sourceMappingURL line:

$ cat foo.min.js
console.log(1),console.log(2);

I expected it to contain a sourceMappingURL line. Otherwise, the source map isn't loaded by the browser.

To be sure that I wasn't missing something, I also tested with version 2.8.29 and the equivalent uglifyjs command from that version's docs. It does add the sourceMappingURL line correctly:

$ npm install -g uglify-js@2.8.29
/usr/local/bin/uglifyjs -> /usr/local/lib/node_modules/uglify-js/bin/uglifyjs
+ uglify-js@2.8.29
added 17 packages in 1.455s
$ uglifyjs js/file1.js \
         js/file2.js \
         -o foo.min.js \
         --source-map foo.min.js.map \
         --source-map-root http://foo.com/src \
         -p 5 -c -m
$ cat foo.min.js
console.log(1),console.log(2);
//# sourceMappingURL=foo.min.js.map
@kzc
Copy link
Contributor

kzc commented Aug 20, 2017

You're correct - the command as documented in the README does not work in bash.

It's a quoting issue. Please try the following:

$ uglifyjs -V
uglify-es 3.0.28

$ uglifyjs js/file1.js js/file2.js -o foo.min.js -c -m --source-map "root='http://foo.com/src',url='foo.min.js.map',filename='foo.min.js'"
$ cat foo.min.js && echo
console.log(1),console.log(2);
//# sourceMappingURL=foo.min.js.map
$ cat foo.min.js.map && echo
{"version":3,"sources":["js/file1.js","js/file2.js"],"names":["console","log"],"mappings":"AAAAA,QAAQC,IAAI,GCAZD,QAAQC,IAAI","file":"foo.min.js","sourceRoot":"http://foo.com/src"}

README pull request welcome.

Edit: changed source map argument to filename.

@alexlamsl
Copy link
Collaborator

@kzc thanks for looking into it.

The examples were tested on Command Prompt, so someone will need to test and update README.md for bash or what not if they so inclined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants