Ruby-on-rails 关于 rake 资产的困惑:在 rails 中的资产管道上清理/清理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9335803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 02:51:03  来源:igfitidea点击:

Confusion about rake assets:clean / cleanup on the asset pipeline in rails

ruby-on-railsruby-on-rails-3asset-pipeline

提问by daniel

Could somebody explain to me what the command rake assets:cleanreally does? Unfortunately the Rails Guides dont mention it. There is also the command rake assets:cleanup. Whats the difference?

有人可以向我解释该命令的rake assets:clean真正作用吗?不幸的是,Rails 指南没有提到它。还有命令rake assets:cleanup。有什么不同?

Furthermore could somebody tell me when do I have to run rake assets:precompilein production. Do I run it on the server console after I deployed all my application files to my production server? Or do I precompileon my local machine and then do a deploy of all files?

此外,有人可以告诉我什么时候必须rake assets:precompile在生产中运行。将所有应用程序文件部署到生产服务器后,是否在服务器控制台上运行它?或者我precompile在我的本地机器上然后部署所有文件?

Thanks all

谢谢大家

回答by Sergio Tulentsev

Note: This answer is rails 3 specific. For rails 4 and later, look at other answers here.

注意:这个答案是特定于 rails 3 的。对于 rails 4 及更高版本,请在此处查看其他答案。

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:cleandeletes these precompiled files.

但它引入了一个问题:现在当您更改源文件 (coffescript / scss) 时,应用程序不会接受更改,因为它将改为提供预编译文件。rake assets:clean删除这些预编译文件。

In my projects assets are precompiled as a part of deployment. Capistrano makes it very easy.

在我的项目中,资产被预编译为部署的一部分。Capistrano 使它变得非常容易。

Also, I never heard of rake assets:cleanup.

另外,我从来没有听说过rake assets:cleanup

回答by Fahim Babar Patel

Run rake assets:clobberto actually clean the assets. http://www.dixis.com/?p=735

运行rake assets:clobber以实际清理资产。 http://www.dixis.com/?p=735

回答by grouchomc

Sergio's answer was completely correct in Rails 3. rake assets:cleandeleted all assets that had been previously precompiled into the public/assetsdirectory.

Sergio 的回答在 Rails 3 中完全正确。 rake assets:clean删除了之前预编译到public/assets目录中的所有资产。

In Rails 4, you run rake assets:clobberto do the same thing.

在 Rails 4 中,你跑来rake assets:clobber做同样的事情。

If you run rake assets:precompilewith the following config (by default turned on in staging and production):

如果您rake assets:precompile使用以下配置运行(默认情况下在登台和生产中打开):

# 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 precompileto 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 cleanit removes the old versions of the precompiled assets while leaving the new assets in place.

您编译的资产带有时间戳。这意味着您可以编译新资产,同时保留旧资产。您通常希望在生产中执行此操作,以便您的网站在运行precompile以创建新文件时仍将访问旧文件(因为您已添加新的 css/javascript)。您现在想要删除不再使用的旧文件。在clean这同时使新资产代替删除预编译的资产的旧版本。

回答by paul.belt

rake assets:cleanremoves compiled assets. It is run by cap deploy:assets:cleanto remove compiled assets, generally from a remote server.

rake assets:clean删除编译的资产。它运行cap deploy:assets:clean以删除编译的资产,通常从远程服务器中删除。

cap deploy:cleanremoves old releases, generally from a remote server. It is not rake assets:clean

cap deploy:clean通常从远程服务器中删除旧版本。它不是rake assets:clean

rake != cap

耙子 != 上限

回答by dduft

rake assets:cleanis 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.

rake assets:clean现在由cap deploy:cleanup_assets. 添加require 'capistrano/rails/assets'到您的 Capfile 中,您将获得此上限任务。我的 capistrano 版本是 v3.2.1。

回答by jaca

clean up those untracked files with git clean -ffor files and git clean -f -dfor directories

使用git clean -ffor 文件和git clean -f -d目录清理那些未跟踪的文件