你应该在EmberJS中放置外部JS文件?

时间:2014-03-25 13:55:53

标签: javascript ruby-on-rails ember.js asset-pipeline

在Rails中,EmberJS劫持了您的app/assets/javascripts目录。它不必去那里,但这是惯例。

+ app
  + assets
    + javascripts
      + components
      + controllers
      + helpers
      + mixins
      + models
      + routes
      + templates
        + components
      + views
      - app.js
      - application.js
      - router.js
      - store.js

假设我想使用JavaScript MD5。我在哪里添加文件?什么目录?

要使用EmberJS gem,我们还必须删除require_tree指令。所以我们最终得到了这个:

# application.js.coffee
#= require jquery
#= require jquery_ujs
#= require handlebars
#= require ember
#= require ember-data
#= require_self
#= require app

# for more details see: http://emberjs.com/guides/application/
window.App = Ember.Application.create()

# app.js.coffee
#= require ./store
#= require_tree ./models
#= require_tree ./controllers
#= require_tree ./views
#= require_tree ./helpers
#= require_tree ./components
#= require_tree ./templates
#= require_tree ./routes
#= require ./router
#= require_self

1 个答案:

答案 0 :(得分:2)

Ember并没有真正劫持你的JS文件夹。只需将代码放在“ember”文件夹中,即可将其与您自己的JS或您正在使用的其他库分开。

它应该看起来像这样(不确定一些ember文件):

+ app
  + assets
    + javascripts
      + ember
        + components
        + controllers
        + helpers
        + mixins
        + models
        + routes
        + templates
          + components
        + views
      - app.js
      - router.js
      - store.js
    + jsmd5
      md5.js
    - application.js

您的application.js可能如下所示:

# for more details see: http://emberjs.com/guides/application/
window.App = Ember.Application.create()

@import "jsmd5/md5.js"