Simple use of Babel7

initialization

Create a new empty folder, under the empty folder cmd to npm init -yinitialize a new project

Install Babel dependencies

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

Insert picture description here

run

npm run babel

Insert picture description here
Check the dist/test.js file to see the compiled js
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_35958891/article/details/107372399