Alex Mikhalev
7 years ago
6 changed files with 47 additions and 9 deletions
@ -1,11 +1,30 @@
@@ -1,11 +1,30 @@
|
||||
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"); |
||||
|
||||
export default function serveApp() { |
||||
return webpackMiddleware( |
||||
webpack(webpackConfig), |
||||
); |
||||
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(), |
||||
})); |
||||
} |
||||
|
Loading…
Reference in new issue