bundle-dll.js 800 Bytes
var resolveCwd = require('import-cwd');
var webpack = resolveCwd('webpack');
/**
 * 根据传入dll配置打包库文件
 * webpack.dll.config
 */
function bundle(webpackConfig) {
    return new Promise((resolve, reject) => {
        const bundler = webpack(webpackConfig);
        let bundlerRunCount = 0;

        function onComplete(err, stats) {
            if (err) {
                return reject(err);
            }

            console.log(stats.toString(webpackConfig.stats));

            if (++bundlerRunCount === (global.WATCH ? webpackConfig.length : 1)) {
                return resolve();
            }
        }
        if (global.WATCH) {
            bundler.watch(200, onComplete);
        } else {
            bundler.run(onComplete);
        }
    });
}

module.exports = bundle;