首页 > 其他 > 详细

es7如何跑起来装饰器

时间:2020-08-23 10:17:47      阅读:75      评论:0      收藏:0      [点我收藏+]

今天学习es7新特性装饰器时,代码提示语法错误,babel照着以前的方法转码也不成功,故写下此文谈谈如何解决

大致步骤如下:
1.安装babel转码工具
2.安装第三方插件,用于支持decorators
3.配置jsconfig.json解决vscode提示语法错误
4.babel打包成功运行

注:我这里没有配置.babelrc文件

1,2.npm install babel-cli babel-plugin-transform-decorators-legacy babel-register --save-dev

3.jsconfig.json

{
    "compilerOptions": {
        "experimentalDecorators": true
    }
}

4.package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "babel --plugins transform-decorators-legacy src -d lib"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "babel-register": "^6.26.0"
  },
  "dependencies": {
    "babel-cli": "^6.26.0"
  }
}

最后执行打包命令:npm run build,即可成功打包代码,并且可在node环境下运行

es7如何跑起来装饰器

原文:https://www.cnblogs.com/ygjzs/p/13548363.html

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