【问题标题】:CSS and JS not showing up in my HEAD when deployed to heroku部署到 Heroku 时,CSS 和 JS 没有出现在我的 HEAD 中
【发布时间】:2014-04-14 21:41:41
【问题描述】:

在我所有的更改都被推送到 github 之后,我刚刚将一个项目部署到了​​ heroku。一切都很好,只是我注意到一些更新的新 CSS 没有通过。 css 文件肯定已提交并推送到 github,所以我知道这不是问题。

在 heroku 应用程序上查看源代码时,我注意到它缺少 head 部分中的大部分 .css 和 .js 文件。 Heroku上的头部与我本地的头部不同是否有原因。一切运行顺利,自从我上次推送到 heroku 后,我没有更改任何配置文件......

谢谢。

这里是github项目的链接:https://github.com/michaelnavarro/careerfoundry

application.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .

应用程序.css

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree .
 */

/*

 */

【问题讨论】:

  • 是的,它和这个原因被称为资产管道。在生产环境中,所有 JavaScript 和 CSS 文件都应该被压缩并包含在 application.jsapplication.css 文件中(默认情况下)。
  • @MarekLipka 这似乎是以前自动发生的?这是否意味着我需要添加在上次提交到应用程序 .css 文件之前添加的新 .css 文件?因为据我所知,没有其他 css 文件被直接调用到 applicaiton.css 文件中
  • @MarekLipka 据我所知,资产/样式表树中包含的所有内容都会自动添加到 application.css
  • 通常通过//= require_tree . (*= require_tree . for css) 指令自动包含新的 css/js 文件。请显示您的布局代码(即您如何在开发模式下包含这些文件)。
  • 这里是github项目的链接:github.com/michaelnavarro/careerfoundry

标签: ruby-on-rails git heroku


【解决方案1】:

您可能应该预编译您的资产:

RAILS_ENV=production bundle exec rake assets:precompile

然后将文件添加到 git

git add .
git commit -m "compiled assests"

然后推送到 Heroku。 Heroku 的资产编译器很挑剔,不能一直工作。您应该在本地完成并将所有内容推送到 Heroku。

【讨论】:

  • 有自动预编译的解决方案吗?还是我每次都必须手动操作?
  • 每次都要手动编译。只需在推送到 heroku 之前运行预编译语句。
【解决方案2】:

我注意到 CSS 文件具有 SCSS 扩展名。尝试将它们重命名为 .css。

此外,您的页面特定 javascript 文件是空的,因此不会包含任何内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-06
    • 1970-01-01
    • 2015-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多