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

How to use without sprockets? #2322

Closed
henderea opened this issue Oct 9, 2019 · 8 comments
Closed

How to use without sprockets? #2322

henderea opened this issue Oct 9, 2019 · 8 comments
Labels
support Questions or unspecific problems

Comments

@henderea
Copy link

henderea commented Oct 9, 2019

With the release of Sprockets 4, it apparently requires me to have an app/assets/config/manifest.js, which I shouldn't need since I'm using webpacker. However, when I updated my application.rb to exclude the sprockets import, the rails webpacker:compile task no longer worked.

What is the recommended method to disable sprockets and use webpacker alone? I'm kind of confused on what I need to do, since excluding the sprockets require caused errors in the webpacker:compile task.

Also, is simply converting all of my JS and CSS assets to webpacker and removeing app/assets enough to no longer need sprockets, or is sprockets involved in the use of webpacker or of regular rails views?

As a note, this app was originally on sprockets, and I converted it to webpacker a while back. There is a chance I may not have properly converted fully away from sprockets, but things have been working fine so far. Is there a guide on fully converting from sprockets to webpacker and removing sprockets from the app?

@jakeNiemiec
Copy link
Member

the rails webpacker:compile task no longer worked.

In order to help debug, could you please post as much as you can of:

  • ./package.json
  • ./config/webpack/environment.js
  • ./config/webpacker.yml
  • ./app/javascript/packs/application.js
  • the full error message (even the parts you wouldn’t think of as relevant)

@henderea
Copy link
Author

henderea commented Oct 9, 2019

Hmm. After looking at the error again, it seems that it was because I had some lines in my rails config/environments/*.rb files setting elements in config.assets, which apparently isn't defined without sprockets pulled in.

I seem to have things working now. However, it would be good to know where I can find a guide on fully converting from sprockets to webpacker. This need to remove the config lines and update the require statements in application.rb was not something I was aware of until I started having these errors, and it might have been nice to have a proper guide on the conversion.

Maybe you could have a link or section in your documentation on how to do a full conversion of an existing app from sprockets to webpacker? Having something like that would probably have helped me avoid this issue in the first place. If you have a link or section for that in your documentation, I must have missed it somehow, but searching in your readme for "sprockets" didn't find any mentions of how to convert an app.

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Oct 9, 2019

I think https://github.com/rails/webpacker#usage has good content.

it would be good to know where I can find a guide on fully converting from sprockets to webpacker.

There are many detailed ones medium.com. When I switched, I just did config.assets.enabled = false.

Maybe you could have a link or section in your documentation on how to do a full conversion of an existing app from sprockets to webpacker?

If you find or create a good one, feel free to create a PR.

@jakeNiemiec jakeNiemiec added the support Questions or unspecific problems label Oct 9, 2019
@cmitz
Copy link

cmitz commented Nov 5, 2019

I struggled to find high quality content on removing Sprockets fully, too. What I did was rails new my-app --skip-sprockets and see what the differences were.

Your first hunch seemed right:

  • Move all files to a place webpack(er) can find (e.g. /javascripts/packs)
  • Remove require 'sprockets/engine' import in application.rb

So:

Also, is simply converting all of my JS and CSS assets to webpacker and removeing app/assets enough to no longer need sprockets

yes

@MutableLoss
Copy link

MutableLoss commented Dec 2, 2019

I just ran into this error with a new disabled-sprockets rails app, just because a style-library gem existed in the Gemfile (material-sass/bootstrap), even though the asset-pipeline was disabled.

This makes sense, since libraries should be added through npm/yarn versus the gemfile, but is the asset error considered normal behavior in this scenario? It feels a bit misleading because it's coming from a 3rd party asset source.

@DanGrewal1
Copy link

I created a new app with the --skip-sprockets flag and im still getting sprockets and sprockets-sass in my gemfile.lock. The only dependency is rails and i have removed the rails/all and replaced with each individual framework (not sprockets) any reason why im still getting sprockets?

@Sporky023
Copy link

Sporky023 commented Aug 13, 2020

I just tested @MutableLoss's angle and found that the presence of sassc-rails in my Gemfile was causing the issue. Apparently these gems kick off some sprockets activity of their own, in order to plug themselves in.

@guillaumebriday
Copy link
Member

Closing for now because it seems to be answered.

Feel free to reopen if needed! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions or unspecific problems
Projects
None yet
Development

No branches or pull requests

7 participants