Ad

Webpack Not Loading Partial Files From The Same Root

- 1 answer

I am compiling a javascript bundle with Webpack. I am specifiying a single file in my build task:

webpack({
    entry: 'src/js/main.js',
    output: { path: 'dist/js' }
}, function(e) {});

And then I am specifying some async packages in my bundle

require([ 'test.json' ], function() {});

Both the main bundle and the partial bundles compile into "dist/js/main.js", "dist/js/1.main.js", etc.

The main bundle loads from "localhost:8000/dist/js/main.js," but the async/partial dependencies are trying to load from "localhost:8000/1.main.js". Am I missing a critical piece of this?

Ad

Answer

You need to set the publicPath property, eg:

{
    entry: 'src/js/main.js',
    output: {
        path: 'dist/js',
        publicPath: '/dist/js/'
    }
}

References:

Ad
source: stackoverflow.com
Ad