UNPKG

debug-server-next

Version:

Dev server for hippy-core.

47 lines (46 loc) 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.startWebpackDevServer = void 0; const tslib_1 = require("tslib"); const fs_1 = tslib_1.__importDefault(require("fs")); const path_1 = tslib_1.__importDefault(require("path")); const log_1 = require("@/utils/log"); const config_1 = require("@/config"); const log = new log_1.Logger('app-dev-server'); function startWebpackDevServer(config) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { const webpackConfig = yield getWebpackConfig(config); if (!webpackConfig) { log.error('you must config webpack.config file path to start webpack-dev-server!'); return process.exit(0); } const hmrPort = ((_a = webpackConfig.devServer) === null || _a === void 0 ? void 0 : _a.port) || 38988; saveHmrPort(hmrPort); const { startAdbProxy } = yield Promise.resolve().then(() => tslib_1.__importStar(require('./child-process/index'))); startAdbProxy(); const WebpackDevServer = (yield Promise.resolve().then(() => tslib_1.__importStar(require('./webpack-dev-server/lib/Server')))).default; const Webpack = (yield Promise.resolve().then(() => tslib_1.__importStar(require('webpack')))).default; const compiler = Webpack(webpackConfig); const webpackDevServer = new WebpackDevServer(webpackConfig.devServer, compiler); yield webpackDevServer.start(); }); } exports.startWebpackDevServer = startWebpackDevServer; function getWebpackConfig(configPath) { return tslib_1.__awaiter(this, void 0, void 0, function* () { let webpackConfig; const webpackConfigPath = path_1.default.resolve(process.cwd(), configPath); log.info('webpack config path: ', webpackConfigPath); if (configPath && fs_1.default.existsSync(webpackConfigPath)) { webpackConfig = yield Promise.resolve().then(() => tslib_1.__importStar(require(webpackConfigPath))); } return (webpackConfig === null || webpackConfig === void 0 ? void 0 : webpackConfig.default) || webpackConfig; }); } /** * hippy-dev 进程保存 hmrPort,hippy-debug 进程可监听设备连接与断连,在设备重连时自动 reverse hmrPort */ function saveHmrPort(hmrPort) { return fs_1.default.writeFileSync(config_1.config.hmrPortPath, String(hmrPort)); }