38
22

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でES6の機能を使うとプリコンパイルが通らない(Uglifierがエラーを吐く)問題

Last updated at Posted at 2018-06-19

TL;DR

  • uglifier(Railsデフォルト搭載のJS軽量化gem)はES5までしか対応していない。
  • そのため、ES6の機能(テンプレートリテラルとか)を使うと怒られる。
  • production.rbの設定変更で対応可能。

変更箇所

  • 変更前
config/environments/production.rb
config.assets.js_compressor = :uglifier
  • 変更後
config/environments/production.rb
config.assets.js_compressor = Uglifier.new(harmony: true)

参考情報

https://hackbaka.hatenablog.com/entry/2018/02/14/175948
https://github.com/lautis/uglifier#es6--es2015--harmony-mode

備考

本来はBabelとか使ったほうがいいのかと思いますが、初学者なのでひとまずの対応です。

38
22
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
38
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?