I was compiling my asset pipeline for my production environment and it did for all my environments. How can I uncompile my asset pipeline for my development environment?
I have checked my config/development environment and cannot find a fix.
Thanks in advance for any help...
To remove precompiled assets use:
rake assets:clean
What this basically does is remove the public/assets directory. You may need to include the RAILS_ENV variable if you need to run it for a certain environment.
Try using
rake assets:clobber
worked for me in rails 4
When you run the compile task locally (on your development machine) the assets are compiled in the Rails production environment, but are written to the public folder.
This means that even when you run in development mode it'll use the compiled assets instead of sending requests to the pipeline. This is normal behavor - requests only go to the pipeline if the file does not exists in public/assets.
The compile task should generally only be used when deploying, and on the remote (production) machine.
If you have compiled locally, you can delete all the files in the public/assets folder and development will behave as before. If you checked these files into source control you'll need to remove them.
Once removed things should work fine.
s
One final tip: if this is an upgraded app check your config settings against those in the last section of the Rails asset pipeline guide.
For Rails 5:
$ RAILS_ENV=development bin/rake assets:clobber
Related
So this is just a question I've been wondering about lately, I seem to spend a significant amount of time when deploying waiting for assets to compile.
Why can we not compile the assets on our development machines and submit it in the git repo?
I am currently using ruby 2.5.x and rails 5.2.4.x using the assets pipeline with uglifier.
Is there a way to do this in development and thus disable all asset compilation during deployment?
many thanks,
Simon
The solution was pretty simple
1) disable asset compiling during deployment
I'm using elastic beanstalk so just had to set this in the environment variables
2) Either
Add the /public/assets folder to git
Or for elastic beanstalk create .ebignore file and copy over the .gitignore but remove the /public/assets entry
3) before deploying run
Linux -- RAILS_ENV=development bundle exec rake assets:precompile
Windows -- set RAILS_ENV=development && bundle exec rake assets:precompile
4) deploy code to server as normal
eb deploy
1st: Why can we not compile the assets on our development machines and submit it in the git repo?
The reason why we need to precompile are:
Compressed the assets resources then cached some static content like images, css and so on.
It's help us to generates two files (.css and .js) and compressed all our's css file event it's file from vendors:
<script src="/assets/application-908e25f4bf641868d8683022a5b62f54.js"></script>
<link href="/assets/application-4dd5b109ee3439da54f5bdfd78a80473.css" media="screen"
rel="stylesheet" />
It's very helpful but It's take time and `And the resource it not live reload when you modify some code. You have to re-compile to apply the code.
-> So, That's why you should not compile the assets in DEVELOPMENT evironment.
2nd: Is there a way to do this in development and thus disable all asset compilation during deployment?
You also use precompile on DEVELOPMENT by run this command:
RAILS_ENV=development bundle exec rake assets:precompile
You can precompile assets in development environment by default using
config/development.rb
config.assets.debug = false
Thanks. Hope it's help
In my case, I precompile before deployment, commit, and push it to Github, as you mentioned.
Then, I deploy to production with capistrano gem: https://github.com/capistrano/capistrano
This is the command to precompile:
rails assets:precompile
i am currently working for the javascript on the production , when i have done the assets clean , this problem has occurred.
The application works well with the development mode but doesn't work on production
please help.
Thanks
Atul Samage
rake assets:clean deletes these precompiled files.
run rake assets:precompile in your project folder
then you can commit these generated assets into the repository and proceed with deployment. No need to compile them on production machine.
Since precompilation is done in production mode only, no need to explicitly specify the environment.
I read the docs but can't seem to understand if you have to run rake assets:precompile locally each time you change scss file or any other assets? Isn't there an automatic way to do it? One of the things I have noticed is that I forget to run it sometimes and my heroku changes do not appear. There must be a way to set it up automatically in rails?
If I change
config.assets.compile = false
to true, will do that it? Is a disadvantage of doing that?
You don't have to precompile your assets for Heroku to serve them. Heroku will precompile your assets automatically if you have not already precompiled assets locally. Read this heroku doc regarding the asset pipeline in Rails 3 (even if you are already using Rails 4). Then read this doc regarding the asset pipeline in Rails 4 on heroku.
Pay particular attention to this part:
If a public/assets/manifest.yml is detected in your app, Heroku will
assume you are handling asset compilation yourself and will not
attempt to compile your assets. Rails 4 uses a file called
public/assets/manifest-.json instead. On both versions you
can generate this file by running $ rake assets:precompile locally and
checking the resultant files into Git.
rake assets:precompile must be run for production environment. Do not need to run the command for the development environment. The command is used to collect all files into one and so be lighter to serve in production. Under development the styles they are wanted in the assets folder. After running the command, the styles are placed in the public folder.
If you forget to run rake assets:precompile Heroku should do it automatically. One reason it may not be is if you have checked your public folder into git as then during slug compilation Heroku will assume you precompiled your assets and will not do it for you.
Setting config.assets.compile = true can slow down your application by a lot, which is why it is only used in development.
I precompiled assets on my dev environment (by mistake!) now any changes done on js/css files are not reflecting on browsing site locally.
I removed assets folder from public directory but then no css/js was available.
How do I get rid of this?
As a temporary solution I just cloned project into new directory and it works.
The question is: why do you need asset precompilation in the development environment? It's not meant to work like this.
The asset pipeline allows working in development with the uncompressed, unminified versions of your JS files. It also reloads them each time you refresh your browser, so you can develop your application with ease.
In production, though, the asset pipeline precompiles the JS files / assets you have into one single, minified file. This allows for better performance on the client as the files are smaller and are fetched in one single request.
So precompiling assets in development makes no sense at all.
In case if I understood you correctly, generally, when you precompile by default assets directory is being created inside public directory. To get your assets back, you can precompile again.
There is also a cache in tmp directory that you might consider removing.
Later you could use a $ (bundle exec) rake assets:precompile in combination with $ (bundle exec) rake assets:clean instead of $ rm -r public/assets so that new assets would be in effect rake way.
A one line command to look at new changes after your commits in environment would be
$ RAILS_ENV=(environment) rake assets:clean assets:precompile
but generally in development assets are not meant to be served as in production mode, so running previous with RAILS_ENV=production and starting a local server in production mode would be considered as a way to check (but not to make sure) if your assets would be served upon deployment in real production.
I went into the exact same problem and resolved it following #dashi's advice: 'remove directory assets in public, then start server in development mode.' everything is back to normal.
Could somebody explain to me what the command rake assets:clean really does? Unfortunately the Rails Guides dont mention it. There is also the command rake assets:cleanup. Whats the difference?
Furthermore could somebody tell me when do I have to run rake assets:precompile in production. Do I run it on the server console after I deployed all my application files to my production server? Or do I precompile on my local machine and then do a deploy of all files?
Thanks all
Note: This answer is rails 3 specific. For rails 4 and later, look at other answers here.
If you precompile on your local machine, then you can commit these generated assets into the repository and proceed with deployment. No need to compile them on production machine.
But it introduces a problem: now when you change source files (coffescript / scss), the app won't pick up the changes, because it will serve precompiled files instead. rake assets:clean deletes these precompiled files.
In my projects assets are precompiled as a part of deployment. Capistrano makes it very easy.
Also, I never heard of rake assets:cleanup.
Run rake assets:clobber to actually clean the assets.
http://www.dixis.com/?p=735
Sergio's answer was completely correct in Rails 3. rake assets:clean deleted all assets that had been previously precompiled into the public/assets directory.
In Rails 4, you run rake assets:clobber to do the same thing.
If you run rake assets:precompile with the following config (by default turned on in staging and production):
# config/environments/production.rb
config.assets.digest = true
You compiled assets get timestamped. This means you can compile your new assets while leaving the old assets in place. You usually want to do this in production so you website will still access the old files while your running precompile to create your new files (because you've added new css/javascript). You now want to get rid of the old files that are no longer in use. The clean it removes the old versions of the precompiled assets while leaving the new assets in place.
rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.
cap deploy:clean removes old releases, generally from a remote server. It is not rake assets:clean
rake != cap
rake assets:clean is now run by cap deploy:cleanup_assets. Add require 'capistrano/rails/assets' to your Capfile and you get this cap-task. My capistrano version is v3.2.1.
clean up those untracked files with git clean -f for files and git clean -f -d for directories