Rails在生产中预编译资产 - 与开发中的不同

时间:2021-08-08 22:55:15

I have in my application.css this:

我在我的application.css中这个:

 *= require_self
 *= require styles
 *= require custom
 *= require paggination
 *= require colorbox
 *= require registration
 *= require ../vendor/dark

On development everything is OK but when I move to production, also some other assets must be precompiled because site looks different in production.

在开发过程中一切正常,但是当我转向生产时,还必须预编译其他一些资产,因为网站在生产中看起来不同。

Does Rails precompile also other css files from assets folder, not only this required? I have many other css in assets folder.

Rails是否还会从资源文件夹中预编译其他css文件,这不仅仅是必需的吗?我在assets文件夹中有很多其他的css。

1 个解决方案

#1


0  

Rails by default only precompiles application.css If you need to add individual css files, maybe if you need specific styles on certain pages you need to add them like this.

Rails默认只预编译application.css如果你需要添加单独的css文件,也许如果你需要在某些页面上需要特定的样式,你需要像这样添加它们。

# in config/production.rb
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w(frontpage.css login.css)

Note: You list only the css ending even though it's a scss file you have. Then you can reference your stylesheets in your view files.

注意:您只列出了css结尾,即使它是您拥有的scss文件。然后,您可以在视图文件中引用样式表。

<%= stylesheet_link_tag "frontpage" %>

Edit: And of course don't forget to do

编辑:当然不要忘记做

bundle exec rake assets:precompile RAILS_ENV=production

#1


0  

Rails by default only precompiles application.css If you need to add individual css files, maybe if you need specific styles on certain pages you need to add them like this.

Rails默认只预编译application.css如果你需要添加单独的css文件,也许如果你需要在某些页面上需要特定的样式,你需要像这样添加它们。

# in config/production.rb
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w(frontpage.css login.css)

Note: You list only the css ending even though it's a scss file you have. Then you can reference your stylesheets in your view files.

注意:您只列出了css结尾,即使它是您拥有的scss文件。然后,您可以在视图文件中引用样式表。

<%= stylesheet_link_tag "frontpage" %>

Edit: And of course don't forget to do

编辑:当然不要忘记做

bundle exec rake assets:precompile RAILS_ENV=production