Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async/await with webpack+babel
{
"presets": ["es2015"],
"plugins": ["transform-async-to-generator"]
}
async function foo() {
console.log('async working!')
}
async function bar() {
await foo()
console.log('after foo')
}
bar()
{
"name": "async-await",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"devDependencies": {
"babel-loader": "^6.2.2",
"babel-plugin-transform-async-to-generator": "^6.5.0",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"webpack": "^1.12.13"
}
}
module.exports = {
entry: ['babel-polyfill', './index.js'],
output: {
filename: 'bundle.js'
},
devtool: 'sourcemap',
module: {
loaders: [{
test: /\.js?$/,
exclude: /(node_modules)/,
loader: 'babel'
}]
}
}
@dandv

This comment has been minimized.

Copy link

dandv commented Oct 4, 2016

@adarrra

This comment has been minimized.

Copy link

adarrra commented Mar 3, 2017

also for .eslintrc:

{
    "parserOptions": {
        "ecmaVersion": 8 // or 2017
    },
    "rules": {}
    }
}
@johnsoftek

This comment has been minimized.

Copy link

johnsoftek commented Mar 11, 2017

If you want to be lazy... babel-preset-2017 includes babel-plugin-transform-async-to-generator.

Also, babel-preset-latest includes babel-preset-2015, babel-preset-2016 and babel-preset-2017.

@kenjinp

This comment has been minimized.

Copy link

kenjinp commented Apr 3, 2017

@johnsoftek be aware that babel-preset-2017 doesn't work for older versions of safari and firefox, so a solution with async and es2015 will be necessary

@Zcyisabigman

This comment has been minimized.

Copy link

Zcyisabigman commented May 23, 2017

Thanks

@mqliutie

This comment has been minimized.

Copy link

mqliutie commented May 30, 2018

Is polyfill necessary ?

@qodesmith

This comment has been minimized.

Copy link

qodesmith commented Jun 6, 2018

Wondering if polyfill is necessary also.

@cotyembry

This comment has been minimized.

Copy link

cotyembry commented Jul 26, 2018

Its necessary if your wanting to use certain features - Im having to add it to include the async await features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.