webpack-dev-middleware
webpack-dev-middleware copied to clipboard
Response Callback
I used it for the first time, and a lot of it was not very clear, but it was very good, thank you for providing this middleware.
- Operating System: windows7
- Node Version:8.9.4
- NPM Version:5.6.0
- webpack version:3.11.0
- webpack-dev-middleware Version:2.0.6
- [x] This is a feature request
- [ ] This is a bug
Code
My suggestion is can you add the support of template engine analysis in the middleware, or provide a callback function for us to use? For example, ejs, jade:
var ejs = require('ejs');
app.use(webpackDevMiddleWare(complier, {
stats: {
assets: true,
children: false,
modules: false,
colors: true
},
respCallback: function(res, filename, content) {
if (/\.html$/.test(filename)) {
res.send(ejs.render(content.toString(), app.locals));
} else {
if (res.send) res.send(content);
else res.end(content);
}
}
}));
middleware.js#85line
const { respCallback } = context.options;
if (respCallback && typeof respCallback === 'function') {
respCallback(res, filename, content);
} else {
if (res.send) res.send(content);
else res.end(content);
}
Thanks for the issue. In the future please fill out the entire issue template and don't remove sections.
This seems like a very niche feature and I'm not sure there would be a widespread advantage to users. We'll leave this issue open for some time and if there is a large upvoting of the request we'll consider adding it.
Thanks for the reply, I'll pay attention to the template later, yes, the function of the template engine is very small, but I feel it is very meaningful to provide a response callback, and we can do some custom functions based on this callback.
/cc @shenguotao2015
I would like to see this feature aswell, plus having an extra feature can't hurt.
/cc @justablob Do you want send a PR
I can't think of a use case but do you need this feature that provides a callback?
I used it for the first time, and a lot of it was not very clear, but it was very good, thank you for providing this middleware.
Operating System: windows7
Node Version:8.9.4
NPM Version:5.6.0
webpack version:3.11.0
webpack-dev-middleware Version:2.0.6
[x] This is a feature request
[ ] This is a bug
Code
My suggestion is can you add the support of template engine analysis in the middleware, or provide a callback function for us to use? For example, ejs, jade:
var ejs = require('ejs'); app.use(webpackDevMiddleWare(complier, { stats: { assets: true, children: false, modules: false, colors: true }, respCallback: function(res, filename, content) { if (/\.html$/.test(filename)) { res.send(ejs.render(content.toString(), app.locals)); } else { if (res.send) res.send(content); else res.end(content); } } }));
middleware.js#85line
const { respCallback } = context.options; if (respCallback && typeof respCallback === 'function') { respCallback(res, filename, content); } else { if (res.send) res.send(content); else res.end(content); }
I would like to work on this feature. Can I have a little more details?
@mitchell-frost Can you provide real use case?
I'm running into a similar issue as outlined in this SO post.
In short, I'm using this indirectly with Angular's ng serve
(WebPack dev server) and I need to be able to embed the URL that the dev-server received the request on into my index.html
body so that I can calculate a relative href from it. (My user will serve this app from a folder I don't know the path of at build time).