So how exactly do you use the Webpack dynamic setting _ _ webpack_public_path__?

read the Chinese and English documents and say that instead of output.publicPath, you need to set output.publicPath to"", and then set webpack_public_path =" http://a.com"; in the entry file.

the expected result is that the js import address in the html file packaged by htmlwebpackplugin is" http "/ / a.compool xx.js"

webpack.config.js is set as follows:

output: {
    filename: "[name].[hash:8].js",
    publicPath: ""
}

the htmlwebpackplugin plug-in is set as follows:

let entries = glob.sync("./src/entries/**/index.js").reduce((prev, curr) => {
    prev["assets/" + curr.slice(14, -3)] = curr;
    return prev;
}, {}); // entries  webpack  entry js

let htmls = Object.keys(entries).map((html) => {
    return new HWP({
        title: html.slice(-5, -1), // , 
        filename: `${html.slice(7, -6)}.html`, // , 
        template: "./src/tpl/index.html", 
        chunks: [html], // , 
        inject: "body", // , 
        minify: false,
        data: {
            build: true
        }
    });
});

the entry file is set as follows:

__webpack_public_path__ = "http://a.com";
    
import a from "./a.js";
import b from "./b.js";
blabla...

then happily expects that the src attribute in the script in the generated html is http://a.com/*/.js but does not have http://a.com.

looked through the SO, github, and said it was OK, but I didn"t get the expected result is that I missed something, or was it because I misunderstood the webpack_public_path ?

Jun.23,2021

publicPath deleted and cannot be an empty string

Menu