Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the Best way to use es6 with rails asset pipeline

What is the best way to use ES6 with rails asset pipeline?. I am trying to write some es6 syntax in my angular-rails application, which uses the rails asset pipeline. The code actually works in local but throws a syntax error when trying to deploy(digital ocean). Stack Trace

This is error I am getting while I am deploying. And the code I am trying to run is

class Hello {
 constructor() {
 alert('Hello!');
 }
}

new Hello();
like image 337
Pallavi Hegde Avatar asked Sep 22 '17 09:09

Pallavi Hegde


1 Answers

Current uglifier version doesn't support ES6, It is on experimental mode hence you will need to manually enable ES6 compiling.

You will need latest uglifier gem version.

ES6 support can be enabled with :harmony => true option while setting js_compressor in config/environments/production.rb:

config.assets.js_compressor = Uglifier.new(
    # ES6 support
    :harmony => true
)

Check here official docs

Hope it helps

like image 199
ShilpeshAgre Avatar answered Nov 15 '22 04:11

ShilpeshAgre