在heroku上预编译,在本地工作 [英] Precompilation breaking on heroku, works locally

查看:170
本文介绍了在heroku上预编译,在本地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些我们较少文件的重组。一切工作在本地(例如 rake资产:预编译),但在Heroku上,我的推送失败,出现以下情况:

 运行:rake资产:预编译
添加占位符
rake中止!
Less :: ParseError:variable @ brand-primary is undefined
(在/tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/app/assets/stylesheets/lectures/lectures.less)
at /tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/vendor/bundle/ruby/2.1.0/gems/less-2.5.1/lib/less/js/lib/less/parser.js:604:31

经过大量讨论后,我决定删除违规文件的导入声明(lectures.less)看看接下来会发生什么。随着更改提交并推送到Github,我尝试再次推送到Heroku,并得到完全相同的错误 - 预编译现在打破了不应该再导入的文件。

详情粘贴在下方;任何人有任何提示?我已经尝试了 heroku运行rake资产:clean heroku run rake tmp:clear ,但我没有无论如何,他们期望他们工作。



我的application.css是准系统:

  ... 
*您可以自由地为该文件添加应用程序范围的样式,并且它们将出现在
*编译文件的顶部,但通常最好为每个样式范围创建一个新文件。
*
* =要求主
* /

以前我需要讲课文件和application.css中的其他一些文件,但将其移至main.less。


$ b 我的main.less具有其余的导入:

p>

  @importsettings; 
@importvariables;
...
@importlectures / lectures.less;
...

相关环境设置:

development.rb

  config.assets.precompile + =%w(admin.js admin.css)
config.less.dumpLineNumbers ='all'
config.assets.debug = true
config.serve_static_assets = true
config.assets.compile = true
config.assets .raise_runtime_errors = true

staging.rb

  config.assets.precompile + =%w(admin.js admin.css)
config.serve_static_assets = true
config.assets.compile = false
config.assets.digest = true
config.assets.version ='1.0'

相关宝石:

  ruby​​'2.1.2'
gem'rails','> = 4'
gem'less-rails',github:'metaskills / less-rails'


解决方

 <$ c我们似乎已经通过在config.assets.version中设置了config.assets.version来解决了这个问题。 $ c>  -  config.assets.version ='1.0'
+ config.assets.version ='1.1'

对我而言,并不清楚为什么heroku不承认这些变化以及为什么 heroku运行rake资产:clean 没有这样做,但你去了。

编辑#################
这已经有一段时间了,为了不让定期发布,我们最终将版本#绑定到我们的提交程序。像这样的东西:



whatever.rb



  heroku = Heroku: :API.new(api_key:ENV ['HEROKU_API_KEY'])
$ asset_version = heroku.get_releases(ENV [HEROKU_APP_NAME])。body [-1] [commit]



production.rb



  config .assets.version = $ asset_version 


I did some restructuring of our less files. Everything works locally (e.g. rake assets:precompile), but on Heroku my push fails with the following:

Running: rake assets:precompile
       adding placeholder
       rake aborted!
       Less::ParseError: variable @brand-primary is undefined
       (in /tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/app/assets/stylesheets/lectures/lectures.less)
       at /tmp/build_24298d78-579f-44a3-ae43-c4d82b9dde9d/vendor/bundle/ruby/2.1.0/gems/less-2.5.1/lib/less/js/lib/less/parser.js:604:31

After much poking around, I decided to remove the import statement for the offending file (lectures.less) to see what breaks next. With the change committed and pushed to Github, I tried pushing again to Heroku, and got the exact same error -- the precompilation is now breaking on a file that shouldn't be imported any more.

Details pasted below; anyone got any tips? I've tried both heroku run rake assets:clean and heroku run rake tmp:clear, but I didn't expect them to work anyway.

My application.css is barebones:

...
 * 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 main
 */

PREVIOUSLY I was requiring the lectures file and some others in application.css, but moved it into the main.less.

My main.less has the rest of the imports:

@import "settings";
@import "variables";
...
@import "lectures/lectures.less";
...

Relevant environment settings:

development.rb

config.assets.precompile                           += %w( admin.js admin.css )
config.less.dumpLineNumbers                        = 'all'
config.assets.debug                                = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.raise_runtime_errors                 = true

staging.rb

config.assets.precompile += %w( admin.js admin.css )
config.serve_static_assets = true
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'

relevant gems:

ruby '2.1.2'
gem 'rails', '>= 4'
gem 'less-rails', github: 'metaskills/less-rails'

解决方案

We appeared to have fixed the issue by bumping the config.assets.version setting in production.rb, e.g.

- config.assets.version = '1.0'
+ config.assets.version = '1.1'

It's not clear in the slightest to me why heroku didn't recognize the changes and why heroku run rake assets:clean didn't do it, but there you go.

EDIT ################# It's been a while since this, and to keep from having the issue on a regular basis, we wound up tying the version # to our commit sha. Something like this:

whatever.rb

heroku = Heroku::API.new(api_key: ENV['HEROKU_API_KEY'])
$asset_version = heroku.get_releases(ENV["HEROKU_APP_NAME"]).body[-1]["commit"]

production.rb

config.assets.version = $asset_version

这篇关于在heroku上预编译,在本地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆