Add default port as 8080 in options.js to match webpack-dev-server.js
See original GitHub issue- Operating System: Windows 10 x64
- Node Version: v11.4.0
- NPM Version: 6.4.1
- webpack Version: 4.29.6
- webpack-dev-server Version: 3.3.1
- This is a bug
- This is a modification request
Code
The minimal changes to webpack.config.js
to introduce HMR are:
// webpack.config.js
// ....
devServer: {
hot: true,
port: 8080
}
// ...
plugins: [
new HotModuleReplacementPlugin(),
// other plugins...
]
Expected Behavior
The port
option should default to 8080
(just like the server does).
Actual Behavior
The port
option does not have a default, which results in the generated code trying to contact webpack-dev-server
at the default port (for URLs) of 80
.
Relevant webpack-dev-server
code
In bin/webpack-dev-server.js
const DEFAULT_PORT = 8080;
In bin/options.js
(missing a default
key)
port: {
describe: 'The port',
group: CONNECTION_GROUP,
},
For Bugs; How can we reproduce the behavior?
Simply remove the port
option above from a simple webpack-dev-server
example project. There will be console errors on the loaded page, and if you check the generated bundle code, you’ll find that it tries to contact webpack-dev-server
at http://localhost
instead of http://localhost:8080
For Features; What is the motivation and/or use-case for the feature?
Having less required options makes webpack
much more approachable to beginners looking to “just make it work”.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:29 (14 by maintainers)
Top Results From Across the Web
How do I change webpack dev server's default port from 8080 ...
You can use the devServer.port option in the webpack config. devServer: { port: 9000 }. Alternatively you can use the --port CLI option...
Read more >DevServer - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >webpack-dev-server - npm
Start using webpack-dev-server in your project by running `npm i ... In the directory where your webpack.config.js is, run:.
Read more >Setting up the Webpack Dev Server - Three.js Tutorials
Dev Server has been initialized using an options object that does not match the API schema. - options has an unknown property 'contentBase'....
Read more >Static website, multiple html pages, using Webpack + example ...
Requirements at hand; Choosing task runner/bundler; Development server; More HTML pages; Adding CSS; Use latest Javascript language features ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
In v3.8.2, when using with program style, you also need to specify the
port
in optionsI think it is bug:
findPort
(https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js#L242) before run compilation https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js#L145 so you always have portcli
andnode
api usage