0

刚开始运行Guard,我遇到了一个奇怪的问题。一旦我添加了多个文件来连接和 uglify --- uglifier 就会继续触发。我必须按 ^C 让它停止,这会引发以下错误:

 ERROR - Guard::Uglify failed to achieve its <run_on_change>, exception was:
 ExecJS::RuntimeError: 
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:142:in `exec_runtime'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:28:in `block in exec'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/execjs-1.4.0/lib/execjs/external_runtime.rb:27:in `exec'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/uglifier-1.3.0/lib/uglifier.rb:100:in `compile'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-uglify-0.1.0/lib/guard/uglify.rb:23:in `run_on_change'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:99:in `block in run_supervised_task'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:97:in `catch'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:97:in `run_supervised_task'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:146:in `block in run_first_task_found'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:144:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:144:in `run_first_task_found'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:79:in `block in run_on_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:175:in `block (3 levels) in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:174:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:174:in `block (2 levels) in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:173:in `catch'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:173:in `block in scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:172:in `each'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:172:in `scoped_guards'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard/runner.rb:72:in `run_on_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:141:in `block (2 levels) in setup_listener'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:365:in `block in within_preserved_state'
 <internal:prelude>:10:in `synchronize'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:362:in `within_preserved_state'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/guard-1.7.0/lib/guard.rb:140:in `block in setup_listener'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:212:in `call'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:212:in `on_change'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/listener.rb:221:in `block in initialize_adapter'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:198:in `call'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:198:in `report_changes'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapter.rb:210:in `poll_changed_dirs'
 /Users/joe/.rvm/gems/ruby-1.9.3-p194/gems/listen-0.7.3/lib/listen/adapters/darwin.rb:38:in `block in start'

请注意,代码仍然被正确挖掘并且一切正常......但是一旦我点击 ^C uglify 就不会再次触发。就像我说的,我是 Guard 的新手,所以我不知道我是否做错了什么,这是 Guard-uglify 的错误还是 Ruby 的错误,或者只是 Guard 本身的错误。

几点注意事项:

  1. 是的,所有宝石都是最新的
  2. 红宝石 1.9.3
  3. Mac OSX 10.8.3

另外,这是我的 Guardfile:

guard :concat, type: "js", files: %w(vendor/jquery-1.9.1.min vendor/handlebars vendor/jquery.iosslider.min app), input_dir: "js", output: "js/s.min"

guard 'uglify', :destination_file => "js/s.min.js" do
  watch (%r{js/s.min.js})
end

非常感谢任何帮助

4

1 回答 1

3

uglifier 插件被配置为写入它正在监视更改的同一文件,从而创建一个无限循环。您需要使用不同的文件:

guard :concat, {
  type: 'js',
  files: %w(vendor/jquery-1.9.1.min vendor/handlebars vendor/jquery.iosslider.min app),
  input_dir: 'js',
  output: 'js/s'
}

guard 'uglify', :destination_file => 'js/s.min.js' do
  watch (%r{js/s.js})
end

编辑

由于后来报错了,我看了一下插件,发现已经更新了,但是没有新的gem推送到RubyGems。所以看起来创作者对插件失去了兴趣。您可以通过更改以下内容直接从 GitHub 获取最新插件Gemfile

gem 'guard-uglify', github: 'pferdefleisch/guard-uglify'

这使它在我的机器上工作。老实说,我的工具链中没有那个未完成和未维护的插件。您可以通过使用guard-jammitguard-process来达到同样的效果。

于 2013-04-10T20:59:44.087 回答