1👍
In vue.config.js
(make one in your client src
folder if you haven’t already), add the target directory for the build:
const path = require("path");
module.exports = {
outputDir: path.resolve(__dirname, "path/to/server/directory/public")
};
Now when you run npm run build
the static files will be bundled there.
Then, all you need to do is point your server to that folder.
If you’re using Node/Express as a backend:
// Handle production
if (process.env.NODE_ENV === 'production') {
// Static folder
app.use(express.static(__dirname + '/public/'));
}
Also, if your Vue app is an SPA, add this inside the if
block, after app.use(express.static(__dirname + '/public/'));
, to handle routing:
// Handle SPA
app.get(/.*/, (req, res) => res.sendFile(__dirname + '/public/index.html'));
Source:stackexchange.com