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

25 lines
662 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 (_) {}
}