Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
24
Help us understand the problem. What is going on with this article?
@Thort

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

24
Help us understand the problem. What is going on with this article?
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
Thort

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
24
Help us understand the problem. What is going on with this article?