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

Sourcemap doesn't work by default #783

Open
viraptor opened this issue Feb 23, 2023 · 5 comments
Open

Sourcemap doesn't work by default #783

viraptor opened this issue Feb 23, 2023 · 5 comments

Comments

@viraptor
Copy link

I was hoping to use the sourcemaps after upgrading to sprockets v4. Unfortunately they're not generated.
Originally I was using uglifier, but switched to the recommended :terser option.

I'm running sprockets through rails 6.1 with config:

config.assets.js_compressor = :terser
config.assets.gzip = false
config.assets.compile = false
config.assets.digest = true
config.assets.debug = false

and running the assets:precompile job to trigger sprockets.

System configuration

  • Sprockets version: sprockets 4.2.0, sprockets-rails 3.4.2
  • Ruby version 3.1.3

Example App (Reproduction) - THIS IS IMPORTANT YOUR ISSUE LIKELY WILL NOT BE RESOLVED WITHOUT THIS

https://github.com/viraptor/sprockets-no-map-example/commits/master

3 commits:

  • clean rails 6.1.3
  • add the terser gem
  • add a js file and add it to the compiled assets

After running RAILS_ENV=production bundle exec rails assets:precompile I get only these files - no maps generated:

$ find public/assets
public/assets
public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css
public/assets/application-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.css.gz
public/assets/index-cdc242f925b3a102342a9e8f026cb6617436f4f17eb368f77b5e28622e4fafa8.js.gz
public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js
public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js.gz
public/assets/index-cdc242f925b3a102342a9e8f026cb6617436f4f17eb368f77b5e28622e4fafa8.js
public/assets/.sprockets-manifest-57569ca90afe16dad20155602c4f4bb0.json
@ahorek
Copy link
Contributor

ahorek commented Feb 24, 2023

in development + config.assets.debug = true source maps should work, but they won't be exported.

autogeneration for production use was never implemented in sprockets. You have to use static sourcemaps or generate them on your own with some hackery like #410 (comment) (untested and outdated)...

@viraptor
Copy link
Author

Thanks. This is kinda surprising and I was totally expecting it to work given the current documentation. I know it suggests that it's for development workflow, but you may want to spell that one out :⁠-⁠)

I'll check out the custom uglifier and report back if that's still valid for rails 6+

@masciugo
Copy link

I can confirm this behaviour in development with 4.2.0. It works with 4.1.1

@viraptor
Copy link
Author

Back later, but the custom uglifier does not work OOTB in rails 6. It's beyond trivial changes so didn't spend too much time on it.

It would be nice if there was a simple way to do it in production automatically.

@javier-menendez
Copy link

Back later, but the custom uglifier does not work OOTB in rails 6. It's beyond trivial changes so didn't spend too much time on it.

It would be nice if there was a simple way to do it in production automatically.

In case it is still needed here is a gem to do that using terser sprockets_terser_with_source_maps

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

4 participants