"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.webpack = void 0;
const tslib_1 = require("tslib");
const webpack_1 = tslib_1.__importDefault(require("webpack"));
const log_1 = require("@/utils/log");
const bundle_version_1 = require("@/utils/bundle-version");
const webpack_2 = require("@/utils/webpack");
const log = new log_1.Logger('app-dev-server');
const webpack = (webpackConfig, cb) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    if (!webpackConfig) {
        log.error('you must config webpack.config file path to start webpack-dev-server!');
        return process.exit(0);
    }
    const id = bundle_version_1.getBundleVersionId();
    webpack_2.normalizeWebpackConfig(id, webpackConfig);
    if (webpackConfig.devServer) {
        webpackConfig.devServer.id = id;
    }
    const compiler = webpack_1.default(webpackConfig);
    const WebpackDevServer = (yield Promise.resolve().then(() => tslib_1.__importStar(require('./webpack-dev-server/lib/Server')))).default;
    const webpackDevServer = new WebpackDevServer(webpackConfig.devServer, compiler, (err, stats) => {
        var _a;
        if (cb)
            cb(err, stats);
        if ((_a = webpackConfig.devServer) === null || _a === void 0 ? void 0 : _a.cb)
            webpackConfig.devServer.cb();
    });
    yield webpackDevServer.start();
    return compiler;
});
exports.webpack = webpack;
