UNPKG

@hippy/debug-server-next

Version:
53 lines (52 loc) 2.2 kB
"use strict"; /* * Tencent is pleased to support the open source community by making * Hippy available. * * Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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("@debug-server-next/utils/log"); const bundle_version_1 = require("@debug-server-next/utils/bundle-version"); const webpack_2 = require("@debug-server-next/utils/webpack"); const log = new log_1.Logger('app-dev-server'); const webpack = async (webpackConfig, cb) => { if (!webpackConfig) { log.error('you must config webpack.config file path to start webpack-dev-server!'); return process.exit(0); } const id = (0, bundle_version_1.getBundleVersionId)(); (0, webpack_2.normalizeWebpackConfig)(id, webpackConfig); if (webpackConfig.devServer) { webpackConfig.devServer.id = id; } // @ts-ignore const compiler = (0, webpack_1.default)(webpackConfig); const WebpackDevServer = (await 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(); }); await webpackDevServer.start(); return compiler; }; exports.webpack = webpack;