I want to manually precompile some assets in my dev environment (to check the content of the compiled js and css files) from the command line.
I am running
RAILS_ENV=development bundle exec rake assets:precompile
but my js and css are not compiled in the public/assets folder, only the images are. Any idea why that may be happening?
Try adding this to your config/environments/production.rb :
config.assets.precompile += %w( *.css *.js )
Related
The bootstrap and CSS work perfectly in development for our rails 4.2 app.
Here is the login page in development:
After deploying (ubuntu 14.1), assets are precompiled with:
bundle exec rake assets:precompile RAILS_ENV=production
However the bootstrap and css are completely not showing any effect on production server. Here is the same login page in production:
The assets precompile seems not having any effect on production. What's could cause bootstrap and css not showing in production? Is there way to verify that the assets precompile is successful?
UPDATE: files under app/assets
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
You might have to uncomment the above lines and add the js and css files you are compiling. Above line should be present in /config/environments/production.rb
I have a custom application_admin.css.scss under app/assets/stylesheets
and I have this line in my config/environments/production.rb file
config.assets.precompile += [%w(application_admin.css)]
When I run bundle exec rake assets:precompile the custom stylesheet doesn't compile
I came across this post but I already have what they suggested.
Rails Assets custom manifests are not precompiling
What else should I check?
First, you don't need to use both [] and the %w(). Try just:
config.assets.precompile += %w( application_admin.css )
which is the equivalent of:
config.assets.precompile += ['application_admin.css']
Second, since you are precompiling for your production environment you want to run:
RAILS_ENV=production bundle exec rake assets:precompile
Just:
bundle exec rake assets:precompile
runs it for your development environment by default. You will want to run this in each environment you want to precomplie your assests in.
I know that in order to precompile your assets you do the following
bundle exec rake assets:precompile
which will take your application.css.sass in app/assets/styesheets and generate application-xxxxx.css in your public/assets directory
My question, what if you have a custom application_custom.css.scss How to precompile it to be used by production?
You can include that file in the application.css.scss manifest file.
Add the following line in your app/assets/stylesheets/application.css.scss:
*= require application_custom
You can also specify additional assets to precompile by adding them to config.assets.precompile += %w( ... ) in your environment configuration, e.g. config/environments/production.rb
It very clearly says in its documentation that it would do this if I don't precompile them locally.
And truthfully, I have no interest in precompiling these locally.
What I've had in production.rb, I've duplicated in application.rb
In my production.rb :
config.serve_static_assets = false
config.assets.compile = false
config.assets.precompile << 'application.js'
config.assets.precompile << 'application.css'
config.assets.precompile << 'screen.css'
Then I deploy, and that returns :
-----> Compiled slug size: 52.4MB
-----> Launching... done, v28
http://myapp.herokuapp.com deployed to Heroku
So it "compiled" something, right? Except no go, I go to the site and the .css and .js files are blank.
In order to precompile this locally, I am required to comment out in bootstraps_and_overrides.css the line :
#import "screen.css.scss";
Then it precompiles locally, and my local machine will not load the css correctly, but remotely it will actually work correctly.
So my method of deployment now is comment out that line of code,
bundle exec rake assets:precompile
git add .
git commit -m "Adding public/assets"
git push heroku development:master
Then ( unfortunately! ) :
bundle exec rake assets:clean
And then uncomment that line of code in my .css.
Some things to check
You're on Cedar, right? Heroku only supports this behavior on Cedar.
You're on Rails 3, right? Heroku doesn't support precompiling assets on Rails 4.
You have asset pipeline turned on, right? in config/application.rb you need the line config.assets.enabled = true
You have to not have a public/assets folder. On deployment Heroku decides whether or not to precompile based on whether this folder is present (even if it's empty).
If the pipeline is on and you don't have an assets folder, then pre-compilation must be failing.
Try changing to this. I hope this will help you.
In config/environments/production.rb
config.assets.compile = true
config.assets.digest = true
You might be on the wrong Heroku stack. Make sure you specify stack Cedar when you create apps that use the asset pipeline.
heroku create -stack cedar
The reason it would not deploy was because of Google fonts. Moving the file to your application.css such as :
*= require_self
*= require_tree .
*/
#import url(http://fonts.googleapis.com/css?family=Special+Elite);
Will allow the app to deploy, and for the fonts to work.
I have a board controller and I have made a board.css file for it.
When I push to heroku I'm getting an error saying board.css is not precompiled. Based on this question I have added
config.assets.precompile += %w( *.css *.js )
to my production.rb file.
This still has not fixed it. What am I missing here?
Open up config/environments/production.rb and make sure the following option is set to true:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
Then run:
rake assets:precompile --trace RAILS_ENV=production
Source
Do you have an assets manifest in your /assets folder?
Default manifest file are /assets/application.js and /assets/application.css.
A manifest file describes all the resources will be precompiled and looks like this:
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require_tree ./dir
*= require_tree .
*/
This CSS manifest precompiles itself, all css files in assets/dir and /assets folders.
So make sure you have a manifest file and it requires board.css with a matching path.
When you set config.assets.precompile += %w( *.css *.js )
in production.rb you are telling Rails that all files in /assets folder are manifest file.
IMHO this is not correct and you have to add only custom manifest files.
Default manifests are already included:
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
About others solutions there's something to say. If you set:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
It means that you are not forced to have precompiled assets.
The trick works because your app will not raise an error, but you still get an app without precompiled assets and you'll pay this in page load time. For this reason this option should always be disabled in production environment.
So when you enable it, calling rake assets:precompile will not guarantee you are going to use a precompiled assets.
Finally remember that Heroku always run rake assets:precompile when you deploy your app, so unless you are running your app locally with production environment you don't need to manually precompile your assets.