0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RailsでJavaScriptの依存関係

Posted at

JavaScriptで次のように複数のファイルに依存関係があるとき、

zzz.coffee
window.ZZZ =
  create: (name) ->
    # ....
aaa.coffee
AAA = ZZZ.create('aaa')

require_treeだとアルファベット順に読み込まれるのでうまく動かない。
application.jsで順番を一つづつ指定して読み込ませるというのも流石に面倒すぎる。

こんな時はaaa.coffeeにrequireを記述すればいい。

aaa.coffee
#= require 'zzz'
AAA = ZZZ.create('aaa')

よく考えたら当たり前かもしれないけど盲点でした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?