When using webpack, the webpacker gem and Rails 5.1, I notice that running rspec for the first time generates public/packs and public/packs-test.
The /public
folder in Rails is where precompiled assets go for static distribution (aka compiled once on server start so they're not compiled on every page load). This is a feature of the Rails asset pipeline to help speed up asset distribution so Rails doesn't have to serve them itself.
Note how webpacker
assets are placed in packs
folders in your /app/assets
directory. These packs will be precompiled and placed into the /public/packs
folder from which these precompiled packs will go and be served from during page requests.
The /public/packs-test
folder is where test environment packs will be precompiled to. You can configure the location of precompiled packs per environment in the config/webpacker.yml file.
As to whether to track these files by version control, that's up to you—and it's usually a logistical question on what you need to do when you deploy to production. From the official Ruby on Rails Guide:
There are several reasons why you might want to precompile your assets locally. Among them are:
- You may not have write access to your production file system.
- You may be deploying to more than one server, and want to avoid duplication of work.
- You may be doing frequent deploys that do not include asset changes.
Local compilation allows you to commit the compiled files into source control, and deploy as normal.
See the official Ruby on Rails Guide section 4.2 on Local Precompilation for more reasons why (or why not) you'd want to precompile and commit the generated files into version control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With