- Add express and serve-static via npm:
$ npm install express serve-static
- Create file named
heroku.js
on at the root directory of a Vue.js project:
const express = require('express');
const serveStatic = require("serve-static")
const path = require('path');
app = express();
app.use(serveStatic(path.join(__dirname, 'dist')));
const port = process.env.PORT || 80;
app.listen(port);
- In
package.json
add the ff to thescripts
section:
"postinstall": "npm run build",
"start": "node heroku.js"
Then add the project to your Heroku and deploy.