Babel7转码-装饰器语法和动态导入

装饰器语法支持

  1. 安装依赖

    yarn add @babel/plugin-proposal-decorators @babel/plugin-proposal-class-properties -D
    
  2. .babelrc 增加配置

    {
      "presets": [],
      "plugins": [
        [
          "@babel/plugin-proposal-decorators",  // @babel/plugin-proposal-decorators需要在@babel/plugin-proposal-class-properties之前
          {
            "legacy": true // 推荐
          }
        ],
        [
          "@babel/plugin-proposal-class-properties",
          {
            "loose": true // babel编译时,对class的属性采用赋值表达式,而不是Object.defineProperty(更简洁)
          }
        ]
      ]
    }
    

import - 动态导入支持

  1. 安装依赖

    yarn add @babel/plugin-syntax-dynamic-import -D
    
  2. .babelrc 文件增加配置

    {
      "presets": [],
      "plugins": [
        "@babel/plugin-syntax-dynamic-import",
      ]
    }
    
分享 提问
comments powered by Disqus