You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { Express } from "express";
|
|
|
|
import * as webpack from "webpack";
|
|
|
|
import * as webpackMiddleware from "webpack-dev-middleware";
|
|
|
|
import * as webpackHotMiddleware from "webpack-hot-middleware";
|
|
|
|
|
|
|
|
/* tslint:disable-next-line:no-var-requires */
|
|
|
|
const webpackConfig = require("../../app/webpack/config.js");
|
|
|
|
|
|
|
|
type Logger = (message?: any, ...optionalParams: any[]) => void;
|
|
|
|
|
|
|
|
function makeLogFunction(fn: Logger = console.log): Logger {
|
|
|
|
return (m, ...args) => fn("[webpack] " + m, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function serveApp(app: Express) {
|
|
|
|
const compiler = webpack(webpackConfig);
|
|
|
|
app.use(webpackMiddleware(compiler,
|
|
|
|
{
|
|
|
|
noInfo: true,
|
|
|
|
publicPath: webpackConfig.output.publicPath,
|
|
|
|
log: makeLogFunction(),
|
|
|
|
warn: makeLogFunction(console.warn),
|
|
|
|
error: makeLogFunction(console.error),
|
|
|
|
},
|
|
|
|
));
|
|
|
|
app.use(webpackHotMiddleware(compiler,
|
|
|
|
{
|
|
|
|
log: makeLogFunction(),
|
|
|
|
}));
|
|
|
|
}
|