React serve build .js files under custom path with webpack

Viewed 86

I have a SSR react app uses express. In webpack client configuration file, i specify the output folder as

output: {
  filename: "[name].[contenthash].js",
  path: path.resolve(__dirname, "../../build/public"),
}

in express, i specify the public folder as:

app.use(Express.static("build/public"));

so, when i build the app, i see something like that when including to HTML document:

<script src="/foobar.js"></script>

If i change the output folder as build/assets or build/public/assets it doesn't change the files locations. It only changes the /build folder structure as i specified, but it keeps root folder in HTML document. I want to serve .js files under a custom path, so it would be like this:

<script src="/assets/foobar.js"></script>
0 Answers
Related