首页 > 其他 > 详细

Babel编辑ES6代码

时间:2019-07-04 23:55:06      阅读:165      评论:0      收藏:0      [点我收藏+]

1.安装babel依赖

npm install --save-dev @babel/core @babel/cli @babel/preset-env
npm install --save @babel/polyfill

  

2.用node初始化一个项目

node init -y

  

初始化后的package.json长这样

{
  "name": "learn2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

  

在package.json中增加scripts命令

{
  "name": "learn2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "babel src -d dest"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

  

3.配置 babel.config.js

const presets = [
	[
		"@babel/env",
		{
			targets: {
				edge: "9",
				firefox: "60",
				chrome: "67",
				safari: "11.1",
			},
			useBuiltIns: "usage",
		},
	],
];

module.exports = { presets };

  

4.运行

npm run build

  

Babel编辑ES6代码

原文:https://www.cnblogs.com/413xiaol/p/11135479.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!