initialization
Create a new empty folder, under the empty folder cmd to npm init -y
initialize a new project
Install Babel dependencies
- @ babel / cli
for command-line compiler file official documents address - @ babel / core
core of Babel, various conversion methods are written in here official documents address - @babel/preset-env
intelligently compile js, you only need to specify the range of browsers you want to support, and you can compile intelligently. Official document address
npm install @babel/cli @babel/core @babel/preset-env --save-dev
Add configuration file
.babelrc
{
"presets": ["@babel/preset-env"]
}
.browserslistrc is used to specify the range of browsers supported by compiled js
"> 1%"
Add in scripts of package.json
"babel": "babel src --out-dir dist --watch"
Add test file
Create a new src folder, add test.js to the folder, and write a little es7 code
function box(){
new Promise((resolve,reject)=>{
setTimeout(()=>{
return resolve(135300)
})
})
}
async function test(){
let a = await box()
}
console.log(test())
File Directory
run
npm run babel
Check the dist/test.js file to see the compiled js