Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are public/packs and public/packs-test for?

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.

  • What are these directories for?
  • What is the difference between the two?
  • Should they be tracked by version control?
like image 425
ybakos Avatar asked Mar 09 '23 06:03

ybakos


1 Answers

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.

like image 126
Zachary Espiritu Avatar answered Mar 16 '23 19:03

Zachary Espiritu