Webpack has several options when it comes to packaging:
Entry: "./app/entry",//String | Object | Array entry: ["./app/entry1", "./app/entry2"], entry: { a: "./app/entry-a", B: ["./app/entry-b1", ". /app/entry-b2 "] },
For non-single-page applications, often choose the third way of writing, set multiple portals, this is not a problem, but sometimes more pages, maintenance of the entry object is very troublesome.
That's a different way of thinking, usually the page directory of items are regular, such as/src/pagea/index.js,/src/pageb/index.js, if you can keep such a name reading
We can get entry to find all of the [Pagename]/index.js portals and implement packaging.
var glob = require ("Glob"), var entries = Glob.sync ("./src/page/*/index.ts"). Reduce (function (prev, item) { key = Item . replace (/\//g, ' _ '). Replace (/^\./, "). Replace (/^\_/,"). Replace (/\.js$/, "); Prev[key] = Item; return prev;}, {}); module.exports = { entry:entries, output: { path:path.resolve (__dirname, "bin"), FileName: "[name].js" }, //...}
The function of the regular substitution here is to change the form like Src/page/projecta/index.js to Src_page_projecta_index (the value of the name variable) and output it to Bin/src_page_projecta_ Index.js.
Finish
Webpack's entry