$ tree
.
├── README.md
├── babel.config.js
├── lib
├── package.json
└── src
├── app.js
└── lib.js
2 directories, 5 files
$ npm install
$ npm run build
$ tree -I node_modules
.
├── README.md
├── babel.config.js
├── lib
│ ├── app.js
│ └── lib.js
├── package-lock.json
├── package.json
└── src
├── app.js
└── lib.js
Last active
December 8, 2018 21:43
-
-
Save knksmith57/a554defde2d3d7cf64c4f453565352a0 to your computer and use it in GitHub Desktop.
configure babel to support ESM and async/await (SO #53540716)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/app.js | |
import { guid, currentDateTimeISOString, stringToBoolean } from './lib' | |
async function hello() { | |
return 'world' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
plugins: ['@babel/plugin-transform-async-to-generator'], | |
presets: [ | |
[ | |
'@babel/env', | |
{ | |
targets: { | |
node: 'current' | |
}, | |
modules: 'cjs' | |
} | |
] | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/lib.js | |
// generate unique id | |
export const guid = () => { | |
const s4 = () => { | |
return Math.floor((1 + Math.random()) * 0x10000) | |
.toString(16) | |
.substring(1) | |
} | |
return ( | |
s4() + | |
s4() + | |
'-' + | |
s4() + | |
'-' + | |
s4() + | |
'-' + | |
s4() + | |
'-' + | |
s4() + | |
s4() + | |
s4() | |
) | |
} | |
// get current date as ISO string | |
export const currentDateTimeISOString = () => { | |
var iso_string = new Date().toISOString() | |
return iso_string | |
} | |
// convert boolean string to boolean | |
export const stringToBoolean = val => { | |
var a = { | |
true: true, | |
false: false | |
} | |
return a[val] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "babel-esm-async", | |
"version": "0.0.0", | |
"main": "lib/app.js", | |
"scripts": { | |
"build": "babel src -d lib" | |
}, | |
"devDependencies": { | |
"@babel/cli": "^7.2.0", | |
"@babel/core": "^7.2.0", | |
"@babel/plugin-transform-async-to-generator": "^7.2.0", | |
"@babel/preset-env": "^7.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment