How to run production site after build vue cli
npm run build
creates a dist
directory with a production build of your app.
In order to serve index.html
in a browser you need an HTTP server.
For example serve:
npm install -g serveserve -s dist
The default port is 5000
, but can be adjusted using the -l
or --listen
flags:
serve -s build -l 4000
Docs:
Production build can be run locally by utilizing Vue CLI's tooling simply by running:
vue-cli-service serve --mode production
For convenience, this can be added to package.json scripts:
"scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "production": "vue-cli-service serve --mode production" }
Command:
$ npm run production
Very easy with express
, and highly extensible/configurable.
Install
npm install -D express
Compose
server.js
// optional: allow environment to specify portconst port = process.env.PORT || 8080// wire up the moduleconst express = require('express') // create server instanceconst app = express() // bind the request to an absolute path or relative to the CWDapp.use(express.static('dist'))// start the serverapp.listen(port, () => console.log(`Listening on port ${port}`))
Execute
node server.js