且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Rails / Bundler预编译与延迟编译

更新时间:2023-09-18 10:05:04

这些行实际上并不会改变资产的使用方式。

These lines don't actually change how your assets are used.

第一行,

Bundler.require *Rails.groups(:assets => %w(development test))

仅在开发和测试环境中从资产组中加载宝石。这意味着 sass-rails uglifier 之类的产品将无法在生产中使用,这意味着您赢得了如果您正在使用这些宝石,就无法正确地在生产中即时编译/最小化/无论您使用什么资产。

only loads gems from the assets group in your development and test environment. This means that things like sass-rails and uglifier won't be available in production, which then means that you won't be able to properly compile/minify/whatever your assets on the fly in production if you're making use of those gems.

另一方面,

Bundler.require(:default, :assets, Rails.env)

将在任何环境中加载资产组,使这些宝石可用于生产中以进行资产编译/缩小/

will load the assets group in any environment, making those gems available in production to do asset compilation/minification/whatever on the fly.

因此,如上所述,这些行实际上并没有改变资产管道的行为-它只是意味着您应该使用第一个if您将要对资产进行预编译以进行生产,或者如果您要在生产中懒散地进行编译,则使用第二个资产。

So, as stated above, these lines don't actually change the behaviour of your asset pipeline - it simply means that you should use the first if you're going to precompile your assets for production, or use the second if you're going to lazily compile in production.