标签:out art npm res sha 运行 exec running nbsp
1.在nuxt项目根目录下创建server.js
2.安装chalk
npm install chalk
server.js
const http = require(‘http‘); const chalk = require(‘chalk‘); const OneProcess = require(‘child_process‘); const CMD = ‘npm run generate‘;//配置运行命令 const PORT = ‘7777‘//配置服务端口 const responseHandle = function (response){ response.writeHead(200, {‘Content-Type‘: ‘text/plain‘}); response.end(‘OK‘) } const runCmd = function (response) { OneProcess.exec(CMD, (error, stdout, stderr) => { if (error) { console.error(`执行的错误: ${error}`); return; }else{ console.log(`${stdout}`); responseHandle(response); } }); } http.createServer(function(request,response){ runCmd(response) }).listen(PORT); console.log(`Server running at ${chalk.green(`http://127.0.0.1:${PORT}`)}`);
3.启动服务
node server.js 检查能否运行
4.部署到服务器开启一个pm2进程守护
pm2 start node -- server.js
5.访问服务 执行命令对nuxt项目静态页重新编译
标签:out art npm res sha 运行 exec running nbsp
原文地址:https://www.cnblogs.com/huangcaijin/p/14384795.html