Skip to content

Instantly share code, notes, and snippets.

@kimobrian
Created February 19, 2018 13:15
Show Gist options
  • Save kimobrian/22de51fd7308ee38d8232142591cb872 to your computer and use it in GitHub Desktop.
Save kimobrian/22de51fd7308ee38d8232142591cb872 to your computer and use it in GitHub Desktop.
Express webpack serve issue
var express = require('express');
var app = express();
var webpack = require('webpack');
var path = require('path');
var compiler = webpack(require('./webpack.config.js'));
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: '/'
}));
app.use('*', function (req, res, next) {
var filename = path.join(compiler.outputPath,'index.html');
compiler.outputFileSystem.readFile(filename, function(err, result){
if (err) {
return next(err);
}
res.set('content-type','text/html');
res.send(result);
res.end();
});
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment