what's the differences between rake assets:pre

2020-03-28 02:23发布

问题:

what's the differences between these two tasks, why i need to add RAILS_ENV=production when cap deploy?

thanks!

回答1:

You need to specify RAILS_ENV=production environment variable so that your config/environments/production.rb configuration file is used when precompiling assets. It usually contains production configuration for assets pipeline:

config.assets.js_compressor = :uglifier
config.assets.digest = true

If you omit RAILS_ENV=production then development configuration will be used (config/environments/development.rb).



回答2:

The first one will precompile your assets on your local dev box (development environment) and the other will precompile your assets on your production environment. Your settings in your config files are most likely different and so it will go of what is configured off what is in the environment config for whatever you set RAILS_ENV to.



回答3:

Was going to write as a comment but too long...

--

Production vs Local

Something you also need to consider with this, is if you're precompiling for the production environment, it essentially compiles & configures your files for that environment

Simply, this means if you have any special conditions / dependencies for production only, using RAILS_ENV=production will use these over your local setup. This is why you'll have this setup in your Gemfile:

#Gemfile
group :production do
   gem 'xxxx'
end

--

SHELL VARIABLES

Something else you need to appreciate is RAILS_ENV is a SHELL VARIABLE. This means that whenever you run a shell session (I.E load cmd), these variables can be set to provide specific functionality.

In relation to RAILS_ENV, it means you'll be able to tell Rails to run in production mode for the time being; as opposed to running in development, testing or staging modes