Skip to content

Commit 16a0bfd

Browse files
committed
feat: 404
1 parent 2aa4173 commit 16a0bfd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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"

scripts/copyIndex2404.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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();

0 commit comments

Comments
 (0)