代码配置
webpack.manu.config.js (只呈现生成entry和htmlwebpackplugin内容,其它部分省略)
const { join } = require("path");
const glob = require("glob");
const setMpa = () => {
const entry = {};
const htmlwebpackplugins = [];
const entryFiles = glob.sync(join(__dirname, "./src/*/index.js"));
entryFiles.map((item, index) => {
const entryName= item.match(/src\/(.*)\/index\.js$/);
const pageName = entryName[1];
entry[pageName] = item;
htmlwebpackplugins.push(
new htmlWebpackPlugin({
template: join(_dirname, `./src/${pageName}/index.html`),
filename: `${pageName}.html`,
chunks: [pageName],
}));
});
return { entry, htmlwebpackplugins };
在此之前需要在package.json就进行配置。
如"script" : {
manulDev: “webpack --config ./webpack.manu.config.js”
}