0
点赞
收藏
分享

微信扫一扫

react build 后,打包后自动将index.html copy 404.html - create-react-app 创建的项目

小典典Rikako 2022-08-29 阅读 123

起因:build上传gitee,启用路由需要404.html自动跳转

当前环境 create-react-app 搭建的架子

解决方案

由于默认的时候把build.js打包,无法查看,只好eject
有不需要eject的方法,但是为了更好的研究学习,就得eject

  1. npm run eject
  2. 找到 script/build.js
  3. 找到编译index.html的命令,然后在生成index.html之后进行404.html文件的copy
  4. 添加copy命令​​fs.copyFileSync('build/index.html', 'build/404.html');​

react build 后,打包后自动将index.html copy 404.html - create-react-app 创建的项目_html

思路分析

  1. 先找 build.js
  2. 找copy函数 copyPublicFolder
  3. 找生成index.html函数 return build(previousFileSizes);
  4. 找生成index.html后的then()
  5. 找到插入位置前 console.log(chalk.green('Compiled successfully.\n'));

---------------------------------------------
生活的意义并不是与他人争高下,而在于享受努力实现目标的过程,结果是对自己行动的嘉奖。
↑面的话,越看越不痛快,应该这么说:

生活的意义就是你自己知道你要做什么,明确目标。没有目标,后面都是瞎扯!

新博客 ​​​https://www.VuejsDev.com​​ 用于梳理知识点



举报

相关推荐

0 条评论