码迷,mamicode.com
首页 > 其他好文 > 详细

Babel编辑ES6代码

时间:2019-07-05 00:05:51      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:nbsp   运行   index   ref   package   amp   pac   license   chrome   

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代码

标签:nbsp   运行   index   ref   package   amp   pac   license   chrome   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!