0

In default webpack setting, the output js/css is under the root path, something like

    <link href=/css/app.ff6d5467.css rel=preload as=style>
    <link href=/css/chunk-vendors.e6bc587c.css rel=preload as=style>
    <link href=/js/app.a9f1ae4f.js rel=preload as=script>
    <link href=/js/chunk-vendors.7cfe59d2.js rel=preload as=script>
    <link href=/css/chunk-vendors.e6bc587c.css rel=stylesheet>
    <link href=/css/app.ff6d5467.css rel=stylesheet>

However, when I deploy my service, it's under a sub path of the host, something like http://all-services.com/myservice, where there is a nginx proxy routing all traffic under /myservice to my service, so these js/css will end up with 404 error because they're trying to access resource under http://all-service.com/js and http://all-service.com/css.

I want to change the path of these js/css when webpack build, change to /myservice/js and /myservice/css for example, how should I config this in webpack?

2
  • Hi Ziqi, do you only need js/css or all of your bundled files to be served at /myservice/? Commented Nov 2, 2021 at 20:59
  • @LucasDavidFerrero yes we assume /myserivce only serve those bundled files (through nginx static file serving), i.e., mostly frontend things, and API calls to backend will go through other paths Commented Nov 3, 2021 at 19:08

1 Answer 1

1

Add this to your webpack.config.js:

output: {
    publicPath: "/myservice",
},

The publicPath component will be inserted into the href before the css or js uri path component.

Documentation: https://webpack.js.org/guides/public-path/

Sign up to request clarification or add additional context in comments.

Comments

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.