Rails在开发模式下缩小(编译)资产

时间:2023-01-16 16:06:31

How do I get my assets rendered in their minified (compiled) form in Rails development mode?

如何在Rails开发模式下以缩小(编译)形式呈现我的资产?

I have about few dozens of asset files, and because they are served one after another it all takes pretty long before the page loads in development. I believe if I keep them compiled and getting served from that would speed up my page load time(I know this is not ideal when I am specifically working on assets).

我有几十个资产文件,因为它们一个接一个地提供服务,所以在页面加载开发之前需要很长时间。我相信如果我保持编译并从中获得服务会加快我的页面加载时间(我知道当我专门处理资产时这并不理想)。

Here is my style and script tags in the layout

这是布局中的样式和脚本标记

<%= stylesheet_link_tag 'all'  %>
<%= javascript_include_tag 'all' %>

And I've also ran bundle exec rake assets:precompile:nondigest

我还运行了bundle exec rake资产:precompile:nondigest

But I still see the assets being rendered one after another. Please help!

但我仍然看到资产一个接一个地呈现。请帮忙!

2 个解决方案

#1


19  

That's quite simple.
You only need to add/change the following line in your config/environments/development.rb

这很简单。您只需在config / environments / development.rb中添加/更改以下行

config.assets.debug = false

And restart your rails server.

然后重启rails服务器。

#2


3  

On Rails 4.2.1 works with this configuration:

在Rails 4.2.1上使用此配置:

config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
# config.assets.debug = true

With this configuration, the precompile will make all JS and CSS files minified to me in the development environment.

使用此配置,预编译将使所有JS和CSS文件在开发环境中缩小为我。

#1


19  

That's quite simple.
You only need to add/change the following line in your config/environments/development.rb

这很简单。您只需在config / environments / development.rb中添加/更改以下行

config.assets.debug = false

And restart your rails server.

然后重启rails服务器。

#2


3  

On Rails 4.2.1 works with this configuration:

在Rails 4.2.1上使用此配置:

config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
# config.assets.debug = true

With this configuration, the precompile will make all JS and CSS files minified to me in the development environment.

使用此配置,预编译将使所有JS和CSS文件在开发环境中缩小为我。