Create a file server running node using packaged vue

vueproject packaging operations

npm build
vue project after the default package compiled static resources in the dist directory
if you want to test before the formal deployment, it can run directly dependent on node-static

Node-static mounted reliance

npm install -g node-static

Or write node脚本
new in the root directorynode-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

note

If no node-static, you can write the whole path or incorporated in the respective dependent and install package.json

advanced

If you want to customize, you can see the specific documentation
https://www.npmjs.com/package/node-static

Guess you like

Origin www.cnblogs.com/chywx/p/12167911.html