babel运行nodejs

Terwer 前端开发评论26字数 528阅读1分45秒阅读模式

安装依赖文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

yarn add @babel/core @babel/cli @babel/node @babel/preset-env -D

~~或者全局安装~~文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

yarn global add @babel/core @babel/cli @babel/node @babel/preset-env

注意:全局安装需要把yarn的全局目录添加到Windows的path,查找path命令如下文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

yarn global bin

~~不建议全局安装,很多时候以来都成问题~~文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

完整的依赖文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

{
  "dependencies": {
    "core-js": "^3.8.3"
  },
  "devDependencies": {
    "@babel/cli": "^7.18.9",
    "@babel/node": "^7.18.9",
    "@babel/preset-env": "^7.18.9"
  }
}

配置 .babelrc文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "entry",
        "corejs": "3.8.3"
      }
    ]
  ]
}

接下来运行即可文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

编译文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

babel test.js

编译与执行文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

babel-node test.js

参考

https://babeljs.io/docs/en/babel-preset-env文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

文章源自浅海拾贝-https://blog.terwergreen.com/babel-run-nodejs-19pblp.html

相关文章
  • 扫码加我微信
  • 验证消息请输入:来自你的博客
  • weinxin
  • 我的微信公众号
  • 微信扫一扫与我交流吧
  • weinxin
Terwer
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: