Help us understand the problem. What is going on with this article?

RailsでES6の機能を使うとプリコンパイルが通らない(Uglifierがエラーを吐く)問題

More than 1 year has passed since last update.

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とか使ったほうがいいのかと思いますが、初学者なのでひとまずの対応です。

Thort
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした