UNPKG

@ali-i18n-fe/dada-component

Version:
42 lines (37 loc) 947 B
const webpack = require("webpack"); function showWebpackConfig(config) { const program = require("commander"); if (program.debug) { console.log("Webpack配置:".green, JSON.stringify(config, null, 2)); } } async function webpackPromise( config, options = { all: false, assets: true, modules: false, maxModules: 0, errors: true, warnings: false, moduleTrace: false, colors: true, errorDetails: true } ) { return new Promise((resolve, reject) => { let loged = false; showWebpackConfig(config); webpack(config, async (err, stats) => { if (err || !!(stats.compilation && stats.compilation.errors.length)) { return reject(new Error(stats.toString({ colors: true }))); } if (!loged) { console.log(stats.toString(options)); loged = true; } resolve(stats); }); }); } module.exports = { webpackPromise, showWebpackConfig };