'How to publish sitemap.xml file with webpack

I don't have much experience configuring Webpack and I am working on a React project and have created an external script that generates a sitemap.xml file. So far so good.

The project is using React 16 and Webpack 4.41, how can I make the sitemap.xml file available to be used in production? When I run npm run build locally I can see the file is not being added to the /public folder, even after I have added the xml rule ( module/rules ) to the webpack.config.js file.

mode: "production",
  context: path.resolve(__dirname, "./app"),
  entry: {
    app: "./js/app.js",
    styles: "./scss/main.scss",
  },
output: {
    filename: "[name].deploy.bundle.js",
    path: path.resolve(__dirname, "./public/assets"),
    publicPath: "/assets",
  },
module: {
    rules: [
      { test: /\.html/ },
      { test: /\.xml/ },
    ]
} 

What Am I missing?

Can it be because my file is currently outside the context folder?

The (simplified) project structure is as follows:

project 
|  sitemap.xml
|  node-script-that-creates-sitemap.js
|  webpack.config.js
|
└───app/
|
└───public/

I'd appreciate your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source