66
65

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.

Asset Pipelineで生成されるjsを分割する

Posted at

背景

  • 特定のユーザにだけ必要なライブラリをapplication.jsとは別に読み込みたい

やりかた

application.rb
    # Precompile additional assets.
    config.assets.precompile += %w(foobar.js)

foobar.jsを出力する場合

app/assets/javascripts/foobar.js
//= require foo
//= require bar
//= require baz

foo.jsとかbar.jsvendor/assets/javascriptsに入っている想定

app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks

//= stub foobar

//= require_tree .

//= stub foobarfoobarが含まれるのを防ぐ。//= require_tree .を使わなければ不要

参考

66
65
1

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
66
65

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?