本文介绍了rake资产:预编译不起作用(rails 3.1.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我读到我需要的做rake资源:首先在本地进行预编译,但是当我这样做时,我得到:

  C:\ project> bundle exec rake资产:预编译 - 跟踪

**调用资源:预编译(first_time)
**执行资源:预编译
rake中止!
undefined:意外的标记:操作符(<)
(位于C:/project/app/assets/javascripts/application.js)

任务:TOP =>资产:预编译
(通过使用--trace运行任务查看完整跟踪)

没有在application.js中,所以我不明白错误在哪里。



application.js是

  //这是一个清单文件,将被编译成包含下面列出的所有文件。 
//在此目录中的单独文件中添加新的JavaScript / Coffee代码,它们将自动为
//包含在可从http://example.com/assets/application.js访问的编译文件中
//不建议直接在这里添加代码,但如果你这样做,它会出现在
//编译文件的底部。
//
// =需要jquery
// =需要jquery_ujs
// = require_tree。

谢谢

更新



如果删除.js.erb文件,我会收到以下错误消息:

  C:\ project> bundle exec rake assets:预编译RAILS_ENV = production --trace 
**调用资源:预编译(first_time)
**执行资源:预编译
耙子中止了!
706:'C:\Users\me\AppData\Local\Temp\execjs20111021-6448-ei2nm3.js(2,3)的意外令牌Microsoft JScript运行时错误:内存不足

'
(在C:/project/app/assets/javascripts/application.js)

任务:TOP =>资产:预编译
(通过使用--trace运行任务来查看完整跟踪)

erb css和js文件不能编译的问题......

这似乎并没有结束..
谢谢

解决方案

我认为这是由一个外部JavaScript文件造成的,该文件没有很好的代码格式。例如

 函数say_hi(){
//注意那里没有分号!
name =Jim
alert(hi+ name)
}

在预编译时,你的代码会放在1行,因为没有必要的分号,你生成的js文件可能包含错误,比如
<$ p $ undefined:意外的标记:操作符(<)



所以,我的建议是:
$ b $ ol
don'如果它没有很好的代码格式,通过在你的配置文件中设置config.assets.compress = false来压缩js文件,@ Mike的答案。 使用coffeescript尽可能地,它会帮助你生成格式良好的代码。 (我不是coffeescript大师,所以如果我错了,请纠正我)


I am deploying to heroku yet I saw that the css files aren't being served (they also cannot be found on heroku).

I read that I need to do rake assets:precompile locally at first yet when I do it I get:

C:\project>bundle exec rake assets:precompile --trace

** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
undefined: Unexpected token: operator (<)
  (in C:/project/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

I have nothing in application.js so I don't understand where the error is..

application.js is

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

Thank you

Update

If removing a .js.erb file I get the following error

C:\project>bundle exec rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
706: unexpected token at 'C:\Users\me\AppData\Local\Temp\execjs20111021-6448-ei2nm3.js(2, 3) Microsoft JScript runtime error: Out of memory

'
  (in C:/project/app/assets/javascripts/application.js)

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Still have problems with erb css and js files not compiling...

This doesn't seem to end..Thanks

解决方案

I think it is caused by an external javascript file which is not well-code-formatted. e.g.

function say_hi(){
  // NOTICE that there's no semi-colon there!
  name = "Jim"
  alert("hi" + name )
}

when under the precompile, your code would put in 1 line, and since there's no necessary semicolon, your generated js file probably contains errors, like

"undefined: Unexpected token: operator (<)"

or something.

so, my suggestion is:

  1. don't compress the js file if it's not well code-formatted, by setting "config.assets.compress = false" in your config file, following @Mike's answer.

  2. use coffeescript as possible, it will help you generate very well formatted code. ( I am not a coffeescript guru, so please correct me if I am wrong )

这篇关于rake资产:预编译不起作用(rails 3.1.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:32