function webpackCompile(config, statsConfig) {
    return new Promise((resolve, reject) => {
        webpack(config, (err, stats) => {
            if (err) {
                console.error(err.stack || err);
                if (err.details) {
                    err.details.forEach(detail => console.error(detail));
                }
                reject(err);
                return;
            }

            const info = stats.toJson();

            if (stats.hasErrors()) {
                info.errors.forEach(error => console.error(error));
                reject(info.errors);
                return;
            }

            if (stats.hasWarnings()) {
                info.warnings.forEach(warning => console.warn(warning));
            }

            /**
             * output stats info if a config is provided
             * https://doc.webpack-china.org/configuration/stats/
             */
            if (statsConfig) {
                console.log('\n' + stats.toString(statsConfig));
            }

            resolve();
        });
    });
}
start to compile with webpack, record the errors & warnings in process

@param {Object|Array} config webpack config
@param {Object?} statsConfig config for showing webpack stats
@return {Promise} promise