为什么Rails不会通过webpacker将ES6转换为ES5?

时间:2019-04-03 08:57:52

标签: ruby-on-rails webpack ecmascript-6 babel ecmascript-5

将ES6 JavaScript添加到我的Rails项目中之后:

class SpinnerWindow {
  static show() {
    //...
  }

  static autoHideShow(timeout=1500) {
    //...
  }

  static hide() {
    //...
  }
}

并部署到Heroku,它仍然包含已编译的ES6(不是ES5!)

...</div>  </div></div>';class SpinnerWindow{static show(){...

我已将所有需要的配置添加到.babelrc

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "browsers": "> 1%",
        "uglify": true
      },
      "useBuiltIns": true
    }]
  ],

  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    "transform-es2015-arrow-functions",
    "transform-es2015-block-scoped-functions",
    "transform-es2015-block-scoping",
    "transform-es2015-classes",
    "transform-es2015-computed-properties",
    "transform-es2015-destructuring",
    "transform-es2015-for-of",
    "transform-es2015-function-name",
    "transform-es2015-literals",
    "transform-es2015-modules-commonjs",
    "transform-es2015-object-super",
    "transform-es2015-parameters",
    "transform-es2015-shorthand-properties",
    "transform-es2015-spread",
    "transform-es2015-sticky-regex",
    "transform-es2015-template-literals",
    "transform-es2015-typeof-symbol",
    "transform-es2015-unicode-regex",
    "transform-regenerator",
    "transform-async-to-generator",
    ["transform-class-properties", { "spec": true }],
    // Reference assets directly from app/assets/**
    // https://github.com/rails/webpacker/blob/master/docs/assets.md#using-babel-module-resolver
    ["module-resolver", { "root": ["./app"], "alias": { "assets": "./app/assets" } }]
  ]
}

我还添加到了'production.rb'

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = Uglifier.new(harmony: true)

这里提到的
How do I use ES6 (ES2015) in a ruby on rails app?

版本:

gem 'rails', '4.2.10'
gem 'webpacker', '~> 3.6'
gem 'babel-transpiler'

0 个答案:

没有答案