Last active
May 1, 2022 16:31
-
-
Save icebob/0dda386fceb8e14b91d84d057fac676f to your computer and use it in GitHub Desktop.
Running Vue CLI 3 generated project with custom Express server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Generate webpack config with CLI service | |
const webpackConfig = require("@vue/cli-service/webpack.config.js"); | |
// Create express app | |
const express = require("express"); | |
const app = express(); | |
// Configure webpack as middleware | |
const webpack = require("webpack"); | |
webpackConfig.entry.app.unshift('webpack-hot-middleware/client'); | |
const compiler = webpack(webpackConfig); | |
const devMiddleware = require('webpack-dev-middleware'); // eslint-disable-line | |
app.use(devMiddleware(compiler, { | |
noInfo: false, | |
publicPath: webpackConfig.output.publicPath, | |
headers: { "Access-Control-Allow-Origin": "*" }, | |
stats: {colors: true} | |
})); | |
const hotMiddleware = require('webpack-hot-middleware'); // eslint-disable-line | |
app.use(hotMiddleware(compiler, { | |
log: console.log | |
})); | |
const port = 8080; | |
app.listen(port, function() { | |
console.log("Developer server running on http://localhost:" + port); | |
}); |
Here's my approach: Using Vue-CLI to serve an Express app.
Thank you for your approach! It working for some cases.
But for some - not.
For example I need to connect dyson service (like fake api service) to express app before app.listen(..)
I try to use before or after hooks - not works at all - server not initalize at all(
webpro/dyson#104
Help me please)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nevamind. I didn't think this would work but adding
hotModuleReplacementPluging()
viavue.config.js
seems to fix it: