'Files not output to directory by webpack - publicPath not working

I have a simple webpack and trying to use publicPath:

const path = require('path');

module.exports = {
    entry: {
        jquery: './node_modules/jquery/dist/jquery.min.js',
    },
    output: {
       path: path.join(__dirname, '/wwwroot/dist/js/'),
       filename: '[name].build.js',
       publicPath: 'virtual-location'
    }
};

The file is placed in the dist folder and is browsable there :

<script type="text/javascript" src="~/dist/js/jquery.build.js"></script>

however when I try to browse publicPath - I get 404:

https://localhost:44306/virtual-location/jquery.build.js

And it does not matter whether I write it with folder slashes or not:

publicPath: 'virtual-location'

or

publicPath: '/virtual-location/'

Versions I use:

"jquery": "3.4.1",
"jquery-ui": "^1.13.1",
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2",

The output file look correct and do not present any errors.

Any idea why the built is not finding the file neither in physical nor virtual location?



Sources

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

Source: Stack Overflow

Solution Source