0

I use webpack dev-server with npm and having simple config file all works perfectly except that I would like to have dev-server runnning the browser with additional url params attached to 'host' url.

config:

...
{
            static: path.resolve(__dirname, "../public"),
            host: "localhost",
            hot: true,
            port: 8080
}
...
target: "web"

Unfortunately adding anything to host like:

"localhost/?developer=John"

will not work, but I would like to set this param in config.js (which is handled then in the code) than copy paste it to url every time dev sever runs. Is there anyway to attach url params to the host url running the code with webpack dev server ?

Thanks in advance

3
  • Could you please try to add the given line publicPath: "http://localhost/?developer=John", after port : 8080. When we setting up publicPath to "http://localhost/?developer=John", the webpack dev server will start serving your application files from this URL. Commented Jul 5, 2024 at 6:49
  • I am using webpack & dev-server with version 5.x and I think there is no such a parameter - "publicPath". CLI output in this case: [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options has an unknown property 'publicPath'. These properties are valid: object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, ipc?, liveReload?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? Commented Jul 5, 2024 at 8:14
  • Looking into webpack docs I found that "publicPath" parameter applies into "output" object in configuration. Unfortunately by adding it I retrieve "failed: connection refused" as the script code in my index.html executes request to external server with something like that: localhost/?developer=John/https://external-server.com/data/… Commented Jul 5, 2024 at 8:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.