使用node创建服务器 运行vue打包的文件

vueproject打包操作

npm build
vue project打包之后默认在dist目录下编译生成静态资源
如果想在正式部署前测试,可以依赖node-static直接运行

安装node-static依赖

npm install -g node-static

或者编写node脚本
在根目录下新建node-static-start.js

var static = require('node-static');

//
// Create a node-static server instance to serve the './public' folder
//
var file = new static.Server('./dist');

require('http').createServer(function (request, response) {
  request.addListener('end', function () {
    //
    // Serve files!
    //
    file.serve(request, response);
  }).resume();
}).listen(8080);

运行
node node-static-start.js

注意

如果没有找到node-static,可以写全路径或者在package.json中引入相应的依赖并install

高级

如果想自定义的话,可以查看具体的文档
https://www.npmjs.com/package/node-static

posted @ 2020-01-08 19:37  陈灬大灬海  阅读(1162)  评论(0编辑  收藏  举报