使用node創建伺服器 運行vue打包的文件

  • 2020 年 1 月 13 日
  • 筆記

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

Tags: