React教程(三) : react-app-rewired

react-app-rewired的作用是在不eject的情况下修改webpack配置

目标:修改build的output目录
1: npm install react-app-rewired --save-dev
2: 根目录下新建文件:config-overrides.js
3:添加以下配置
module.exports = function override(config, env) {
// 修改path目录
const path = require('path');
const paths = require('react-scripts/config/paths');
paths.appBuild = path.join(path.dirname(paths.appBuild), 'dist');
config.output.path = path.join(path.dirname(config.output.path), 'dist');
console.log(custom output path - ${config.output.path} );
return config;
};
4:npm run build
会注意到build后的输出路劲变味了dist,而不是默认的build

示例代码:
https://github.com/992990831/modernization/tree/main/ts-config

posted @ 2020-11-03 21:35  老胡Andy  阅读(5542)  评论(0编辑  收藏  举报