react装饰器配置

118 阅读1分钟
  1. npm run eject 暴露配置项,webpack.config.js
  2. webpack.config.js中plugins下添加
  [
    "@babel/plugin-proposal-decorators",
    { "legacy": true }
  ],

image.png

  1. 最外层src同级目录配置config-overrides.js文件,方便文件夹的调用,内容如下
const { override, fixBabelImports, addLessLoader, addDecoratorsLegacy } = require("customize-cra");
//是config-overrides.js, 不是config.overrides.js
module.exports = override(
    fixBabelImports("import",{//antd按需加载
        libraryName: "antd",
        libraryDirectory: "es",
        style: true //使用color需要设置为true.
    }),
    addDecoratorsLegacy(),  //装饰器使用,只使用装饰器只加这个即可
    //设置antd主题色
    addLessLoader({
        javascriptEnabled: true,
        modifyVars: {
            "@primary-color": "red",
            "@link-color": "green" // 链接色
        }
    })
)
  1. 重启项目, yarn start