25 lines
662 B
JavaScript
25 lines
662 B
JavaScript
|
|
#!/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 (_) {}
|
|||
|
|
}
|