Webpacker: Default to es2017

Created on 20 Dec 2016  路  15Comments  路  Source: rails/webpacker

Let's give the people async/await by default (and the other es2017 goodies).

Most helpful comment

in webpacker (3.2.0)
Add the babel plugin transform-runtime

npm install babel-plugin-transform-runtime

{
  "presets": [
    [
      "env",
      {
        "modules": false,
        "targets": {
          "browsers": "> 1%",
          "uglify": true
        },
        "useBuiltIns": true
      }
    ]
  ],
  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    "transform-runtime",
    [
      "transform-class-properties",
      {
        "spec": true
      }
    ]
  ]
}

All 15 comments

Done in af320768eb5dfe8

Cool 馃槃

Async/await is not working for me in version 1.2 without installing and loading babel-polyfill

Should I create a new issue or do you want to reopen this one?

@flybayer What version of node you got?

Node 7.10.0

thanks, and you got .babelrc with env preset?

I should have added the error I get in the Browser console without babel-polyfill:

Uncaught ReferenceError: regeneratorRuntime is not defined

My .babelrc:

{
  "presets": [
    ["env", {"modules": false}]
  ],
  "plugins": [
    "transform-object-rest-spread",
  ],
}

I guess something like this would work, please give it a go -

    "presets": [
      [
        "env",
        {
          "targets": {
            "node": "current"
          },
          "useBuiltIns": true
        }
      ]
    ]

We should probably update .babelrc

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "node": "current"
      },
      "useBuiltIns": true
    }]
  ]
}

This works perfect!! (without babel-polyfill). Thank you @gauravtiwari !!

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "node": "current"
      },
      "useBuiltIns": true
    }]
  ]
}

So this changed worked fine until I tried to run in production mode which results in uglify failing because of ES6/7 syntax (see #306).

I'm now back to using babel-polyfill and:

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "node": "current",
        "uglify": true
      },
      "useBuiltIns": true
    }]
  ]
}

Lets document this in README @flybayer as this depends on the use case

in webpacker (3.2.0)
Add the babel plugin transform-runtime

npm install babel-plugin-transform-runtime

{
  "presets": [
    [
      "env",
      {
        "modules": false,
        "targets": {
          "browsers": "> 1%",
          "uglify": true
        },
        "useBuiltIns": true
      }
    ]
  ],
  "plugins": [
    "syntax-dynamic-import",
    "transform-object-rest-spread",
    "transform-runtime",
    [
      "transform-class-properties",
      {
        "spec": true
      }
    ]
  ]
}

Thanks @MiguelSavignano. This solved the Uncaught ReferenceError: regeneratorRuntime is not defined issue for me too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankFang picture FrankFang  路  3Comments

ilrock picture ilrock  路  3Comments

eriknygren picture eriknygren  路  3Comments

ijdickinson picture ijdickinson  路  3Comments

towry picture towry  路  3Comments