requirejs-rails icon indicating copy to clipboard operation
requirejs-rails copied to clipboard

Add source map support

Open wuservices opened this issue 10 years ago • 10 comments

The recent versions of RequireJS support source maps, but some changes are needed to make them work well with the asset pipeline.

I started making some changes to such as adding adding generateSourceMaps to build_config_whitelist and then copying the source map files to the digest asset path:

        if requirejs.config.build_config['generateSourceMaps']
          FileUtils.cp "#{built_asset_path}.map", "#{digest_asset_path}.map"
        end

However, I then realized that the original files aren't available so there would have to be some way to automate the creation of original files and maybe handle some file renaming since the original files and the minified files have the same names in production mode and the original files aren't even available on production by default.

After realizing there was more work involved, I've decided to table this for now, but this would be a great thing for somebody to implement or for me to come back to when I have more time so I'm adding this issue to make sure it gets tracked.

wuservices avatar Jul 10 '14 18:07 wuservices

+1

rafaelrinaldi avatar Jul 31 '14 19:07 rafaelrinaldi

I got a little distracted and ended up getting this to work. It's not quite cleaned up or tested enough to create a PR and I'm not sure if I'll get to that, but doing something like this should make source maps work: https://github.com/paperculture/requirejs-rails/commit/f05f8fe888b594cb4ebf1ddb8a21169ca52f496c. That and adding generateSourceMaps to build_config_whitelist as I mentioned above.

Hopefully this is enough to inspire somebody to finish the job :)

wuservices avatar Sep 05 '14 01:09 wuservices

@wuservices Thanks! Looking to get some bugs fixed and features merged this weekend.

carsomyr avatar Sep 05 '14 01:09 carsomyr

Hi All,

I have what's probably a really silly question, but what exactly do you mean when you say to add the following?

generateSourceMaps to build_config_whitelist

I've tried this in various number of ways (both in application.rb of the app itself and in config.rb of requirejs-rails), but I feel like I must be missing something obvious.

The way that I thought it should definitely work was by putting the following in application.rb:

config.requirejs.build_config += %w(
  generateSourceMaps
)

... but I then get this error when trying to precompile:

NoMethodError: undefined method `slice!' for {"baseUrl"=>"/assets"}:Hash

edit: I have implemented the changes in that commit @wuservices linked to.

remybach avatar Jan 16 '15 16:01 remybach

Hi,

is it possible now to generate source maps?

I added in requirejs.yml the config:

optimize : 'uglify2'
generateSourceMaps : 'true'

but the generated rjs_driver only show the optimize:uglify2, without generateSourcemaps.

chenxeed avatar May 13 '15 04:05 chenxeed

@chenxeed Yeah, this is planned as part of my rewrite. People have asked for this in the past.

carsomyr avatar May 13 '15 23:05 carsomyr

@carsomyr Thanks a lot! :)

chenxeed avatar May 15 '15 03:05 chenxeed

Hi!

I tried to add : config.requirejs.build_config_whitelist << 'generateSourceMaps'

to config/application.rb, and adding :

generateSourceMaps : true
preserveLicenseComments : false

to requirejs.yml and on precompile, it generates sourcemaps perfectly! :)

The way I don't know is how to point that sourcemaps file from browser's devtools because the sourcemaps .map files is saved in tmp/requirejs/dst/ and I can't get it from browser.

Kindly ask for hints for this. Thanks! :+1: love to see sourcemaps works for debugging purpose!

chenxeed avatar Jun 26 '15 19:06 chenxeed

@wuservices @chenxeed Gonna look into this next as a major feature.

carsomyr avatar Jul 01 '15 21:07 carsomyr

@carsomyr awesome! I've had them on my branch for a while now from paperculture@f05f8fe so that should at least be on the right track. @chenxeed sorry I missed your last comment. I think the changes in paperculture@f05f8fe would fix what you were describing where we need to copy the source maps over so they are available to serve.

wuservices avatar Jul 01 '15 21:07 wuservices