UNPKG

2.68 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.startDevServer = void 0;
4const dev_server_core_1 = require("@web/dev-server-core");
5const mergeConfigs_js_1 = require("./config/mergeConfigs.js");
6const parseConfig_js_1 = require("./config/parseConfig.js");
7const readCliArgs_js_1 = require("./config/readCliArgs.js");
8const readFileConfig_js_1 = require("./config/readFileConfig.js");
9const DevServerStartError_js_1 = require("./DevServerStartError.js");
10const createLogger_js_1 = require("./logger/createLogger.js");
11const openBrowser_js_1 = require("./openBrowser.js");
12/**
13 * Starts the dev server.
14 */
15async function startDevServer(options = {}) {
16 var _a;
17 const { config: extraConfig, readCliArgs: readCliArgsFlag = true, readFileConfig: readFileConfigFlag = true, configName, autoExitProcess = true, logStartMessage = true, argv = process.argv, } = options;
18 try {
19 const cliArgs = readCliArgsFlag ? (0, readCliArgs_js_1.readCliArgs)({ argv }) : {};
20 const rawConfig = readFileConfigFlag
21 ? await (0, readFileConfig_js_1.readFileConfig)({ configName, configPath: cliArgs.config })
22 : {};
23 const mergedConfig = (0, mergeConfigs_js_1.mergeConfigs)(extraConfig, rawConfig);
24 const config = await (0, parseConfig_js_1.parseConfig)(mergedConfig, cliArgs);
25 const { logger, loggerPlugin } = (0, createLogger_js_1.createLogger)({
26 debugLogging: !!config.debug,
27 clearTerminalOnReload: !!config.watch && !!config.clearTerminalOnReload,
28 logStartMessage: !!logStartMessage,
29 });
30 config.plugins = (_a = config.plugins) !== null && _a !== void 0 ? _a : [];
31 config.plugins.unshift(loggerPlugin);
32 const server = new dev_server_core_1.DevServer(config, logger);
33 if (autoExitProcess) {
34 process.on('uncaughtException', error => {
35 /* eslint-disable-next-line no-console */
36 console.error(error);
37 });
38 process.on('SIGINT', async () => {
39 await server.stop();
40 process.exit(0);
41 });
42 }
43 await server.start();
44 if (config.open != null && config.open !== false) {
45 await (0, openBrowser_js_1.openBrowser)(config);
46 }
47 return server;
48 }
49 catch (error) {
50 if (error instanceof DevServerStartError_js_1.DevServerStartError) {
51 console.error(error.message);
52 }
53 else {
54 console.error(error);
55 }
56 process.exit(1);
57 }
58}
59exports.startDevServer = startDevServer;
60//# sourceMappingURL=startDevServer.js.map
\No newline at end of file