Skip to content

Instantly share code, notes, and snippets.

@icebob
Last active May 1, 2022 16:31
Show Gist options
  • Save icebob/0dda386fceb8e14b91d84d057fac676f to your computer and use it in GitHub Desktop.
Save icebob/0dda386fceb8e14b91d84d057fac676f to your computer and use it in GitHub Desktop.
Running Vue CLI 3 generated project with custom Express server
"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);
});
@7iomka
Copy link

7iomka commented Nov 29, 2019

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