1 Star 5 Fork 1

ShoneSingLone / var-admin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
hmr.js 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
ShoneSingLone 提交于 2020-04-14 18:01 . update
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");
const {
PassThrough
} = require("stream");
exports.koaDevMiddleware = (webpackCompiler, options) => {
const expressStyled = webpackDevMiddleware(webpackCompiler, options);
const koaStyled = async (ctx, next) => {
await expressStyled(ctx.req, {
end: (content) => {
ctx.body = content;
},
setHeader: (name, value) => {
ctx.set(name, value);
},
locals: ctx.state,
}, next);
};
koaStyled.close = expressStyled.close;
koaStyled.invalidate = expressStyled.invalidate;
koaStyled.waitUntilInvalid = expressStyled.waitUntilInvalid;
return koaStyled;
};
exports.koaHotMiddleware = (webpackCompiler, options) => {
const expressStyled = webpackHotMiddleware(webpackCompiler, options);
return async (ctx, next) => {
const stream = new PassThrough();
await expressStyled(ctx.req, {
write: stream.write.bind(stream),
writeHead: (status, headers) => {
ctx.body = stream;
ctx.status = status;
ctx.set(headers);
},
}, next);
};
};
JavaScript
1
https://gitee.com/ShoneSingLone/var-admin.git
git@gitee.com:ShoneSingLone/var-admin.git
ShoneSingLone
var-admin
var-admin
master

搜索帮助