angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.54k stars 3k forks source link

Remove source mapping URL from non minified source code #3485

Closed adamreisnz closed 7 years ago

adamreisnz commented 7 years ago

This is a:

My version of UI-Router is: 1.0.3

Bug Report

Current Behavior:

The following line is included in the unminified source code of ui-router:

//# sourceMappingURL=angular-ui-router.js.map

This now causes an error in my chrome console:

DevTools failed to parse SourceMap: http://localhost:8080/lib/angular-ui-router.js.map

This is because I don't include (and don't want to include) the pre-rolled sourcemap for ui-router. I bundle the unminified source code into a vendor package and roll my own sourcemaps from that.

As such, this sourcemapping is redundant and problematic causing dev tools to look for non-existent source maps.

Expected Behavior:

Only include source map reference in the minified code and let developers handle it themselves if they want to use the non-minfied code. Don't include source map in the non-minified code.

Link to Plunker that reproduces the issue:

Cannot be demonstrated in a Plunkr because the source map is provided on the CDN.

adamreisnz commented 7 years ago

Not sure if this was caused by the request in https://github.com/angular-ui/ui-router/issues/2378

adamreisnz commented 7 years ago

Workaround is to strip all comments from the source codes in build process, but still I don't think it should be included by default for non minified source files. The whole point of source maps is to unmangle minified code and make it possible to debug it. Unminified source code is already possible to debug...

aeisenberg commented 7 years ago

Possible duplicate of https://github.com/angular-ui/ui-router/issues/3465

aeisenberg commented 7 years ago

And https://github.com/ui-router/core/pull/58 fixes the problem by including the proper files in the built package and allows you to debug with correct sources as well.

christopherthielen commented 7 years ago

We may take a different approach by embedding the sourcemaps inline into the es5 transpiled code. Please see https://github.com/ui-router/angular/pull/136 and comment

Note: The es5 files would have the sourcemaps embedded. However, when we generate bundles, the sourcemaps would be extracted to external .map files.

Let me know if you anyone has concerns with this approach. I think this should solve for most cases without packaging the source files.

aeisenberg commented 7 years ago

I'm not sure if this alone will fix the problem. Here are my thoughts:

  1. The problem exists in both ui-router/angular and ui-router/core. So, the same fix would need to be applied to both.
  2. The problem isn't the lack of source maps. The problem is that the source maps point to sources that don't exist. The sourcemaps include URLs to the original sources. If the sources don't exist, then that causes a 404 error and makes ui-router very difficult to debug. Additionally, some other tools seem to stop working as well. As far as I can tell, there is no way around including the original sources if you include source maps.

Can I ask why you are reticent to include the source files in the non-minified release?

aeisenberg commented 7 years ago

Oh, right. It looks like this option will inline the sources into the actual target file. If that's the case, then this solution will probably be fine. Though it still needs to be applied to both projects. Thanks for addressing this problem.