index.js 1.5 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runWebpackDev = exports.runWebpackBuild = void 0;
const webpack_1 = __importDefault(require("webpack"));
fxy060608's avatar
fxy060608 已提交
8
const uni_shared_1 = require("@dcloudio/uni-shared");
fxy060608's avatar
fxy060608 已提交
9
const config_1 = require("./config");
fxy060608's avatar
fxy060608 已提交
10
const alias_1 = require("./alias");
fxy060608's avatar
fxy060608 已提交
11
const env_1 = require("../utils/env");
fxy060608's avatar
fxy060608 已提交
12
const initModuleAliasOnce = uni_shared_1.once(alias_1.initModuleAlias);
fxy060608's avatar
fxy060608 已提交
13 14
function runWebpack(mode, options) {
    env_1.initEnv(options);
fxy060608's avatar
fxy060608 已提交
15
    initModuleAliasOnce();
fxy060608's avatar
fxy060608 已提交
16
    return new Promise((resolve, reject) => {
fxy060608's avatar
fxy060608 已提交
17
        webpack_1.default(config_1.createConfig(mode, options), (err, stats) => {
fxy060608's avatar
fxy060608 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
            if (err) {
                return reject(err.stack || err);
            }
            if (stats.hasErrors()) {
                return reject(stats.toString());
            }
            const info = stats.toJson();
            if (stats.hasWarnings()) {
                console.warn(info.warnings);
            }
            console.log(stats.toString({
                chunks: true,
                colors: true, // 在控制台展示颜色
            }));
            resolve(void 0);
        });
    });
}
fxy060608's avatar
fxy060608 已提交
36 37
function runWebpackBuild(options) {
    return runWebpack('production', options);
fxy060608's avatar
fxy060608 已提交
38 39
}
exports.runWebpackBuild = runWebpackBuild;
fxy060608's avatar
fxy060608 已提交
40 41
function runWebpackDev(options) {
    return runWebpack('development', options);
fxy060608's avatar
fxy060608 已提交
42 43
}
exports.runWebpackDev = runWebpackDev;