A webpack demo. The code is simple:
`module.exports = {
entry: {
main: "./src/main.js",
main2: "./src/main2.js"
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "[name].[chunkhash].js"
},
plugins: [
new HtmlWebpackPlugin({
title: "my-cli",
template: "./html/index.html"
}),
new CleanWebpackPlugin("dist")
]
} `
main.js
const test = require("./test.js");
console.log(test);
test.js
const str = "test is loaded122";
module.exports = str;
main2.js
const test = require("./test2.js");
console.log(test);
test2.js
const str = "test is loaded22ff";
module.exports = str;
I don"t quite understand why the chunkid of main2.js is 0 and the chunkid of main.js is 1 after it is packaged.
as shown in the figure
and if the require in main2.js is deleted, the chunkid of main.js is 0. Main2.js chunkid is 1, which remains the same if the require of main.js is removed. And there is no chunkId-related code in the two packaged chunk. Ask the great god for an answer.
main2.js
console.log(test);