当前位置: 首页 > 工具软件 > react-circle > 使用案例 >

React - react-app-rewired

浦德明
2023-12-01

react-app-rewired 与 customize-cra 配合,用于 create-react-app 构建的项目中添加 Webpack 配置

yarn add customize-cra react-app-rewired --dev

更换 package.json 中的 script 命令

"scripts": {
  "start": "react-app-rewired start",
  "build": "react-app-rewired build",
  "test": "react-app-rewired test",
  "eject": "react-scripts eject"
}

在 package.json 同级目录下新建 config-overrides.js 文件

const {
  override,
  addDecoratorsLegacy,
  disableEsLint,
  addWebpackAlias,
} = require("customize-cra")
const path = require("path")

module.exports = override(
  // 添加装饰器
  addDecoratorsLegacy(), 

  disableEsLint(),
  
  // 设置路径别名
  addWebpackAlias({ 
    '@': path.resolve(__dirname, 'src'),
  }),
);

 

 类似资料: