File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 1515 "scripts" : {
1616 "start" : " cross-env NODE_ENV=development webpack serve -c ./scripts/webpack.config.cjs --mode development" ,
1717 "build" : " cross-env NODE_ENV=production webpack -c ./scripts/webpack.config.cjs --mode production" ,
18- "build:homepage" : " cross-env NODE_ENV=homepage webpack -c ./scripts/webpack.config.cjs --mode production" ,
18+ "build:homepage" : " cross-env NODE_ENV=homepage webpack -c ./scripts/webpack.config.cjs --mode production && node ./scripts/copyIndex2404.cjs " ,
1919 "dev:build" : " cross-env NODE_ENV=development webpack -c ./scripts/webpack.config.cjs --mode development" ,
2020 "lint" : " eslint --fix && tsc --noEmit" ,
2121 "prepare" : " husky install"
Original file line number Diff line number Diff line change 1+ // 工具方法:复制 dist/index.html 至 dist/404.html
2+ const fs = require ( "node:fs" ) ;
3+ const path = require ( "node:path" ) ;
4+
5+ function copyIndexTo404 ( ) {
6+ const distDir = path . resolve ( __dirname , "../dist" ) ;
7+ const indexPath = path . join ( distDir , "index.html" ) ;
8+ const notFoundPath = path . join ( distDir , "404.html" ) ;
9+ if ( fs . existsSync ( indexPath ) ) {
10+ fs . copyFileSync ( indexPath , notFoundPath ) ;
11+ // 只允许 console.warn 或 console.error
12+ console . warn ( "index.html 已复制为 404.html" ) ;
13+ }
14+ else {
15+ console . error ( "index.html 不存在,无法复制" ) ;
16+ }
17+ }
18+
19+ copyIndexTo404 ( ) ;
You can’t perform that action at this time.
0 commit comments