-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Provide more webpack-dev-server API #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is what I'm looking for too. To reduce the number of API calls on page load I have moved to having a dynamic index.html served by express instead of a static one served by nginx. Now I'm trying to replicate the functionality of webpack-dev-server using webpack-dev-middleware and webpack-hot-middleware. This turns out to be really challenging. I'm still lacking incremental compiling (full recompile happens on every change) and page reload is not happening automatically and I have no idea how to fix them. I'm considering proxying webpack-dev-server from my express server in dev mode but this means having multiple processes which I don't really want. It would be much easier if I could just mount the webpack-dev-server as a middleware. |
Have you tried the following way? // devServer.js
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const createLogger = require('webpack-dev-server/lib/utils/createLogger');
const findport = require('./findport');
module.exports = async (config) => {
try {
const compiler = webpack(config);
const options = config.devServer || {};
const log = createLogger(options);
const port = await findport(options.port);
options.port = port;
const devServer = new WebpackDevServer(compiler, options, log);
return devServer.app;
} catch (error) {
console.warn(error);
}
}; devServer.app is a express instance. |
I think it should be able to run, but I haven't actually tested it yet. |
@jiankafei what exactly you want to have in API? |
@evilebottnawi main: defines middleware and exposes it; Such a design can ensure the use of bin commands, but also allow developers to use the middleware of main. Meet the developer's custom development. |
@jiankafei it is require a lot of work, also it is impossible only |
You should use custom setup for these purpose what you describe |
@evilebottnawi |
@jiankafei here |
@evilebottnawi |
Need more information what is not works as expected |
@evilebottnawi with webpack-dev-server I didn't need any conditional logic in webpack.config.js - my production mode settings just worked perfectly with the dev server which is great. Now with dev middleware and HMR I must have conditional logic for setting:
Plus conditional express routing is required to use either static middleware or webpack middleware. In my case extra config was required to make sure HMR is served with the correct base path since all my micro-front-end apps are proxied (I set the express hot middleware "path" and the webpack output "hotUpdateChunkFilename" config). Everything is working perfectly for me now but it was a very painful 1-2 days to figure out all these tweaks and now my webpack config has conditional logic which I'd rather not have. |
Fixed in https://github.com/webpack/webpack/releases/tag/v4.24.0
Not related to |
I think ability to manually reload browser window would be great. Such ability exists in BrowserSync, but not in WDS :'(
|
@felixcatto why? |
i am using WDS and webpack only for bundling client js. For moving images, process CSS and transpile server js i am using gulp. So when i change my server code, all code transpiled and i want to refresh browser after this process. I make a simple WDS config with proxy option to target my original server. It works well, when i change client code, but i can't trigger refresh after my server code changed. There was one similar request in the past |
You can run
|
Webpack-dev-server is now like a black box, hoping to provide a convenient API for developers to call. The advantage of this approach is that, on the premise of ensuring devServer configuration, developers can use it programmatically and access custom logic.
The text was updated successfully, but these errors were encountered: