Rails 3 & assets pipeline in development/production mode
-
27-10-2019 - |
سؤال
Precompiling assets on the production server is very slow. So I have decided to recompile them on the development machine and upload assets to the Amazon S3 by jammit
. Everything's done but I have some negative problems:
- I have to include
public/assets
directory togit
control. Because ifpublic/assets
directory is empty on the production server fails - If I precompile assets on the development machine
application.js
includes in the HTML as compressed and that way I have duplicated js code. Changing js doesn't make any effect because precompiledapplication.js
interrupts this code.
That way my development process includes following steps:
- Remove precompiled assets if I'm going to change js or css
- Do some changes
- Precompile assets
- Upload assets to S3 by
jammit-s3
- Do commit and push my changes including assets to the git server
- Deploy by capistrano
My questions are:
- Is it possible to configure development environment don't include compressed
application.js
if I have it inpublic/assets
directory? - Is it possible to configure production environment to work with empty
public/assets
directory? Assets will only be on the S3 server.
المحلول 2
I resolved this problem by including assets dir in gitignore and exclude only one file - public/assets/manifest.yml
and production server works correctly now, i.e. config.action_controller.asset_host = "http://assets.example.com"
works. It requires only manifest.yml
file
نصائح أخرى
For question one I don't know a permanent solution other than running:
bundle exec rake assets:clean
before you switch back to development mode. I'd be interested to see if you can just ignore the assets in development without turning the entire assets pipeline off.
In production.rb there is an option for your second question:
# Enable serving of images, stylesheets, and JavaScripts from an asset server
config.action_controller.asset_host = "http://assets.example.com"
It should then ignore your assets directory since it relies on the remote host. Hope that helps.