31 lines
919 B
JavaScript
31 lines
919 B
JavaScript
import webpack from 'webpack';
|
|
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
import path from 'path';
|
|
import getWebpackDevConfig from '../client/config/getWebpackDevConfig';
|
|
|
|
const initWebpack = ({ config, app }) => {
|
|
const webpackDevConfig = getWebpackDevConfig(config);
|
|
const compiler = webpack(webpackDevConfig);
|
|
|
|
app.use(webpackDevMiddleware(compiler, {
|
|
publicPath: webpackDevConfig.output.publicPath,
|
|
}));
|
|
|
|
app.use(webpackHotMiddleware(compiler));
|
|
|
|
app.get(`${config.routes.admin}*`, (req, res, next) => {
|
|
const filename = path.resolve(compiler.outputPath, 'index.html');
|
|
compiler.outputFileSystem.readFile(filename, (err, result) => {
|
|
if (err) {
|
|
return next(err);
|
|
}
|
|
res.set('content-type', 'text/html');
|
|
res.send(result);
|
|
res.end();
|
|
});
|
|
});
|
|
};
|
|
|
|
export default initWebpack;
|