AlexanderPavlenko / sprockets_uglifier_with_source_maps

Create javascript source maps for your Rails applications
MIT License
35 stars 13 forks source link

Support input source maps #7

Open yinghaochan opened 7 years ago

yinghaochan commented 7 years ago

Context

We write ES6 and import npm modules using webpack and https://github.com/shakacode/react_on_rails

This means that we

  1. write code in es6, and import from node_modules/
  2. bundle the code using webpack, creating ES5 files (w/ sourcemaps) in app/assets/javascripts
  3. sprockets then fingerprints and uglifies these ES5 files during the compile step.

However, the initial source maps generated by webpack for the ES5 code don't get parsed and therefore the uglified version contains source maps only to the bundled ES5 code, not to the original ES6 code.

Suggestion

https://github.com/lautis/uglifier/blob/master/spec/source_map_spec.rb#L97 allows for an input source map file (but doesn't seem to support inlined source maps).

So would it be possible to create these ES5 and map files in app/assets/javascripts

image

And have this gem add the input source map if it detects the presence of a file with [name].js.map ?

AlexanderPavlenko commented 7 years ago

https://github.com/AlexanderPavlenko/sprockets_uglifier_with_source_maps/blob/master/lib/sprockets_uglifier_with_source_maps/compressor.rb#L20 Currently input source maps are not handled. Pull Request welcome.