【webpack】动态entry

const fs = require("fs");
const asyncReadDir = (url) => {
     
    return new Promise(resolve => {
     
        fs.readdir(url,'utf8',(err,files) => {
     
            const entryObj = {
     };
            files.forEach(filename => {
     
                entryObj[filename] = path.resolve(url,filename,'index.js');
            });
            resolve(entryObj);
        })
    })
}

module.exports = {
     
    entry:() => asyncReadDir(path.resolve(__dirname,'src')),
    output:{
     
        filename:"[name].js",
        path:path.resolve(__dirname,"dist")
    }
}

你可能感兴趣的:(webpack)