Files
soul-yongping/scripts/write-standalone-warning.js

25 lines
662 B
JavaScript
Raw Normal View History

#!/usr/bin/env node
/**
* postbuild .next/standalone 中写入提示避免用户 cd 进去直接 node server.js 导致 404
*/
const fs = require('fs');
const path = require('path');
const standaloneDir = path.join(__dirname, '..', '.next', 'standalone');
const msg = `不要在此目录直接运行 node server.js
否则 .next/static public 未复制页面会空白并报 404
请在项目根目录执行
pnpm start
node scripts/start-standalone.js
`;
const file = path.join(standaloneDir, '请勿直接运行.txt');
if (fs.existsSync(standaloneDir)) {
try {
fs.writeFileSync(file, msg, 'utf8');
} catch (_) {}
}