webpack-dev-server configuration #248
Replies: 4 comments 18 replies
-
I would like to propose an updated to support a developer-provided configuration file for webpack-dev-server. The following code would merge any provided configuration with the current settings that are hard-coded: const webpackConfig = require(path.join(process.cwd(), "webpack.config"));
const compiler = Webpack(webpackConfig[1]);
// notify console that webpack is happening
compiler.hooks.beforeCompile.tap("webpackServe", () => {
console.log("webpack compiling")
});
const webpackDevServerConfig = optionalRequire(path.join(process.cwd(), "webpack.devServer.config"), true) || {} ;
const dsOpts = {
hot: false,
host: "localhost",
port: 9000,
allowedHosts: "all",
devMiddleware: {
writeToDisk: true,
stats: {
all: false,
colors: true,
errors: true,
warnings: true,
timings: true,
entrypoints: true
}
}
}
lodash.merge(dsOpts, webpackDevServerConfig);
const server = new WebpackDevServer(dsOpts, compiler); If this seems reasonable, I can put a PR together. |
Beta Was this translation helpful? Give feedback.
-
Strange that you see the performance warning during the development. Are you sure that you're running Regarding the issue your suggestion looks perfectly valid to me, however, I would make it a bit simpler. Webpack supports the
But we can simply merge those settings in our code easily, smth like in the below code: const webpackConfig = require(path.join(process.cwd(), "webpack.config"));
const feConfig = webpackConfig[1];
const defaultDevServerOpts = {
hot: false,
host: "localhost",
port: 9000,
allowedHosts: "all",
.... etc.
};
// if developer provided specific devServer options, then merge them with the default one
if(feConfig.devServer) {
lodash.merge(defaultDevServerOpts, feConfig.devServer);
}
const compiler = Webpack(feConfig);
const server = new WebpackDevServer(defaultDevServerOpts, compiler); That way a developer keeps everything in one file and in one configuration. Additionally, I would make a change to the default overlay setting and make a warning to be disabled, like in your initial fix, ie.: client: {
overlay: {
warnings: false,
error: true
}
} |
Beta Was this translation helpful? Give feedback.
-
What if we added an option, similar to SPFx, where you can modify this in your local webpack and then merge them? |
Beta Was this translation helpful? Give feedback.
-
I've renamed this issue to better reflect what I am really asking for. :) Below are the items I feel would help developer understand what is happening and how to best get the application developed. (I've written them as declarative statements, like a requirement. Please treat them as suggestions/requests.) I'm using "serve task" to mean both
|
Beta Was this translation helpful? Give feedback.
-
The default settings for webpack-dev-server will display an overlay in the browser when there are warnings. In my scenario, and I’m guessing others in the future, I get a performance warning because the webpack size is larger than the recommended. This happens in development, but not production. That does not seem unreasonable.
However, the overlay shows On. Every. Page. Load. Or. Refresh. 😖
I was able to resolve my issue by updating the configuration in the
yoteams-build-core\dist\webpackServe.js
file. The following entry suppresses the warnings that frustrate me:Obviously, these changes would be reverted by an update to the package, and would not exist in any new projects I create.
I understand that these changes may not be desirable for all users. So, does it make sense to look for a different config file in the project? Or an entry in the existing
webpack.config.js
? Or even change the default?Beta Was this translation helpful? Give feedback.
All reactions