moyan's life

vuePress-theme-reco moyanfaker    2017 - 2021
moyan's life moyan's life

Choose mode

  • dark
  • auto
  • light
Home
Category
  • ES6
  • 闭包
  • js的未来
  • 数组
  • Typescript
  • 函数式编程
  • 防抖和节流
Tag
TimeLine
Docs
  • vuepress-reco
Contact
  • GitHub
author-avatar

moyanfaker

12

Article

12

Tag

Home
Category
  • ES6
  • 闭包
  • js的未来
  • 数组
  • Typescript
  • 函数式编程
  • 防抖和节流
Tag
TimeLine
Docs
  • vuepress-reco
Contact
  • GitHub

babel.js编译

vuePress-theme-reco moyanfaker    2017 - 2021

babel.js编译

moyanfaker 2020-12-14 Babeljs

# babel.js 编译

# 方式 1--引入 JS 文件(知道有就行 糊弄人用的)

1.引入 browser

2.type="text/babel"

<script src="browser.min.js" charset ="utf-8"></script>
  <script type = "text/babel">
    let a = 1;
    alert(a);
  </script>
1
2
3
4
5

# 方式 2---编译 JS 文件

1.安装 Node.js、初始化项目

npm init -y

2.安装 babel-cli

npm i @babel/core@babel/cli@babel/preset-env -D

npm i @babel/polyfill-S

3.在 package.json 中添加执行脚本

"scripts":{
"build":"babel src -d dest"
}
1
2
3

4.添加.babelrc 配置文件

{
  "presets": ["@babel/preset-env"]
}
1
2
3

5.执行编译

npm run build