Description
Hello there,
I've got a problem with Chrome Google Dev Tools not being able to point to a correct line in minified js source. This is hard to explain so I've prepared a zip file, which allows me to reproduce the problem.
- Download and unzip the file.
- Cd to the extracted directory.
- Run
npm install
. - Run
grunt
-> will compile typescript files - Run
grunt build
-> will run r.js to concatenate & minify relevant .js files - Run
php -S localhost:8080
-> will serve the directory over http (requires php 5.4). - Open Google Chrome. Go to
localhost:8080
-> a blank page should open - Open Developers Tools.
- Go to to the Console tab. -> You should see, that an error occurred in
page1.ts
file. The link should take you to the.ts
file which contains the error. This shows, thattypescript
source maps works correctly. - Edit
index.html
. Comment linebaseUrl: "/js/ts-compiled",
. Uncomment linebaseUrl: "/js/ts-compiled-optimized",
. Save the file. - Refresh the page in Google Chrome. -> You should see, that an error occurred in
page1.js:1
file. The link should take you to the.js
file which contains the error. If you beautify the.js
file using the Google Chrome dev tools feature, you can see, that Google Chrome points to the correct place in the file. So everything's still working. - Edit
Gruntfile
. Uncomment lines:generateSourceMaps: true,
andpreserveLicenseComments: false,
. Save the file. - Run
grunt build
. - Refresh the page in Google Chrome. -> You should see, that an error occurred in
widget1.js
file. The link should take you to the unminified version ofwidget1.js
.
So, two things about the step 14.:
- Google Chrome points to a unminified file, which is good.
- Google Chrome doesn't point to the file, where the error occurred. (i.e. to the
page.js
file).
Did I mess up something with my r.js configuration? I tried different things, but I couldn't make it work correctly.
The other thing is: is it possible to configure r.js/uglify2 to create source maps in such a way, that they point to the original .ts
files after the minification? I read this post: link, but:
- It uses
uglify
grunt task to do the job. It's ok, but I would rather not over-complicate my build procedure with yet another moving part. I would rather user.js
itself for talking with theuglifyjs2
. - It assumes, that there is only one file, that is produced. I would like to provide a directory of source maps, that needs to be included in the final source maps generation, because I would like to use requirejs, to implement a multipage-require solution (1 common file and a bunch of page*.js files) (see the provided
.zip
file; I didn't exactly follow this solution, because I need to support a legacy code).
So far I'm very happy with the requirejs and r.js. The source maps issue is the last thing that currently bothers me (although it is an issue only for the production environment, because in dev I don't minify those files which is faster and which allows me to use .ts source maps). I'd appreciate a hand here.
Thanks.