@rsbuild/core 0.0.28 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/compiled/dotenv/index.js +1 -0
  2. package/compiled/dotenv/lib/main.d.ts +156 -0
  3. package/compiled/dotenv/license +23 -0
  4. package/compiled/dotenv/package.json +1 -0
  5. package/compiled/dotenv-expand/index.js +1 -0
  6. package/compiled/dotenv-expand/lib/main.d.ts +29 -0
  7. package/compiled/dotenv-expand/license +24 -0
  8. package/compiled/dotenv-expand/package.json +1 -0
  9. package/dist/cli/commands.d.ts +7 -1
  10. package/dist/cli/commands.js +37 -24
  11. package/dist/cli/config.js +28 -16
  12. package/dist/cli/prepare.js +1 -1
  13. package/dist/client/hmr.js +187 -187
  14. package/dist/loadEnv.d.ts +5 -0
  15. package/dist/loadEnv.js +58 -0
  16. package/dist/plugins/asset.js +1 -1
  17. package/dist/plugins/bundleAnalyzer.js +1 -1
  18. package/dist/plugins/cache.js +1 -1
  19. package/dist/plugins/cleanOutput.js +1 -1
  20. package/dist/plugins/define.js +1 -1
  21. package/dist/plugins/devtool.js +1 -1
  22. package/dist/plugins/entry.js +1 -1
  23. package/dist/plugins/externals.js +1 -1
  24. package/dist/plugins/fileSize.js +5 -4
  25. package/dist/plugins/html.d.ts +6 -4
  26. package/dist/plugins/html.js +39 -27
  27. package/dist/plugins/inlineChunk.js +8 -12
  28. package/dist/plugins/moment.js +1 -1
  29. package/dist/plugins/nodeAddons.js +1 -1
  30. package/dist/plugins/performance.js +1 -1
  31. package/dist/plugins/splitChunks.js +1 -1
  32. package/dist/plugins/startUrl.js +1 -1
  33. package/dist/plugins/target.js +1 -1
  34. package/dist/plugins/toml.js +1 -1
  35. package/dist/plugins/wasm.js +1 -1
  36. package/dist/plugins/yaml.js +1 -1
  37. package/dist/rspack-plugins/HtmlBasicPlugin.d.ts +2 -2
  38. package/dist/rspack-plugins/HtmlBasicPlugin.js +9 -17
  39. package/dist/rspack-provider/core/createContext.js +1 -1
  40. package/dist/rspack-provider/plugins/basic.js +1 -1
  41. package/dist/rspack-provider/plugins/css.js +1 -1
  42. package/dist/rspack-provider/plugins/hmr.js +1 -1
  43. package/dist/rspack-provider/plugins/less.js +1 -1
  44. package/dist/rspack-provider/plugins/minimize.js +1 -1
  45. package/dist/rspack-provider/plugins/output.js +1 -1
  46. package/dist/rspack-provider/plugins/progress.js +1 -1
  47. package/dist/rspack-provider/plugins/resolve.js +1 -1
  48. package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
  49. package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
  50. package/dist/rspack-provider/plugins/sass.js +1 -1
  51. package/dist/rspack-provider/plugins/swc.js +3 -4
  52. package/dist/rspack-provider/plugins/transition.js +1 -5
  53. package/dist/server/dev-middleware/index.d.ts +5 -2
  54. package/dist/server/dev-middleware/index.js +24 -5
  55. package/dist/server/devServer.js +11 -12
  56. package/dist/server/middlewares.d.ts +2 -2
  57. package/dist/server/middlewares.js +19 -12
  58. package/dist/server/prodServer.d.ts +6 -3
  59. package/dist/server/prodServer.js +52 -11
  60. package/dist/server/proxy.d.ts +4 -3
  61. package/dist/server/restart.js +4 -1
  62. package/package.json +4 -4
  63. package/dist/server/https.d.ts +0 -6
  64. package/dist/server/https.js +0 -50
@@ -50,6 +50,7 @@ class RsbuildDevServer {
50
50
  this.output = options.output;
51
51
  this.devMiddleware = new import_dev_middleware.default({
52
52
  dev: this.dev,
53
+ publicPaths: options.output.publicPaths,
53
54
  devMiddleware: options.devMiddleware
54
55
  });
55
56
  }
@@ -116,14 +117,14 @@ class RsbuildDevServer {
116
117
  this.middlewares.use(
117
118
  (0, import_middlewares.getHtmlFallbackMiddleware)({
118
119
  distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
119
- publicPath: this.output.publicPath,
120
- callback: devMiddleware.middleware
120
+ callback: devMiddleware.middleware,
121
+ htmlFallback: this.dev.htmlFallback
121
122
  })
122
123
  );
123
124
  if (dev.historyApiFallback) {
124
125
  const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
125
126
  const historyApiFallbackMiddleware = connectHistoryApiFallback(
126
- typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback
127
+ dev.historyApiFallback === true ? {} : dev.historyApiFallback
127
128
  );
128
129
  this.middlewares.use(historyApiFallbackMiddleware);
129
130
  devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
@@ -135,9 +136,7 @@ class RsbuildDevServer {
135
136
  const { dev } = this;
136
137
  const devHttpsOption = typeof dev === "object" && dev.https;
137
138
  if (devHttpsOption) {
138
- const { genHttpsOptions } = require("./https");
139
- const httpsOptions = await genHttpsOptions(devHttpsOption, this.pwd);
140
- return (0, import_https.createServer)(httpsOptions, this.middlewares);
139
+ return (0, import_https.createServer)(devHttpsOption, this.middlewares);
141
140
  } else {
142
141
  return (0, import_http.createServer)(this.middlewares);
143
142
  }
@@ -165,7 +164,7 @@ async function startDevServer(options, createDevMiddleware, {
165
164
  logger: customLogger,
166
165
  getPortSilently
167
166
  } = {}) {
168
- var _a, _b, _c, _d, _e;
167
+ var _a, _b, _c, _d;
169
168
  if (!process.env.NODE_ENV) {
170
169
  process.env.NODE_ENV = "development";
171
170
  }
@@ -183,24 +182,24 @@ async function startDevServer(options, createDevMiddleware, {
183
182
  open
184
183
  };
185
184
  const protocol = https ? "https" : "http";
186
- let urls = (0, import_shared.getAddressUrls)(protocol, port, (_a = rsbuildConfig.dev) == null ? void 0 : _a.host);
185
+ let urls = (0, import_shared.getAddressUrls)(protocol, port, host);
187
186
  const routes = (0, import_shared.formatRoutes)(
188
187
  options.context.entry,
189
- (_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.html
188
+ (_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.html
190
189
  );
191
190
  (0, import_shared.debug)("create dev server");
192
191
  const { devMiddleware, compiler } = await createDevMiddleware(
193
192
  options,
194
193
  customCompiler
195
194
  );
196
- const publicPath = compiler.compilers ? (0, import_shared.getPublicPathFromCompiler)(compiler.compilers[0]) : (0, import_shared.getPublicPathFromCompiler)(compiler);
195
+ const publicPaths = compiler.compilers ? compiler.compilers.map(import_shared.getPublicPathFromCompiler) : [(0, import_shared.getPublicPathFromCompiler)(compiler)];
197
196
  const server = new RsbuildDevServer({
198
197
  pwd: options.context.rootPath,
199
198
  devMiddleware,
200
199
  dev: devServerConfig,
201
200
  output: {
202
- distPath: ((_e = (_d = rsbuildConfig.output) == null ? void 0 : _d.distPath) == null ? void 0 : _e.root) || import_shared.ROOT_DIST_DIR,
203
- publicPath
201
+ distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
202
+ publicPaths
204
203
  }
205
204
  });
206
205
  (0, import_shared.debug)("create dev server done");
@@ -1,8 +1,8 @@
1
- import { RequestHandler as Middleware } from '@rsbuild/shared';
1
+ import { RequestHandler as Middleware, HtmlFallback } from '@rsbuild/shared';
2
2
  export declare const faviconFallbackMiddleware: Middleware;
3
3
  export declare const notFoundMiddleware: Middleware;
4
4
  export declare const getHtmlFallbackMiddleware: (params: {
5
5
  distPath: string;
6
- publicPath: string;
7
6
  callback?: Middleware;
7
+ htmlFallback?: HtmlFallback;
8
8
  }) => Middleware;
@@ -48,14 +48,14 @@ const notFoundMiddleware = (_req, res, _next) => {
48
48
  res.statusCode = 404;
49
49
  res.end();
50
50
  };
51
- const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
51
+ const getHtmlFallbackMiddleware = ({ htmlFallback, distPath, callback }) => {
52
52
  return (req, res, next) => {
53
53
  if (
54
54
  // Only accept GET or HEAD
55
55
  req.method !== "GET" && req.method !== "HEAD" || // Require Accept header
56
56
  !req.headers || typeof req.headers.accept !== "string" || // Ignore JSON requests
57
57
  req.headers.accept.includes("application/json") || // Require Accept: text/html or */*
58
- !(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url
58
+ !(req.headers.accept.includes("text/html") || req.headers.accept.includes("*/*")) || !req.url || ["/favicon.ico"].includes(req.url)
59
59
  ) {
60
60
  return next();
61
61
  }
@@ -66,31 +66,38 @@ const getHtmlFallbackMiddleware = ({ publicPath, distPath, callback }) => {
66
66
  const { devMiddleware } = res.locals.webpack;
67
67
  outputFileSystem = devMiddleware.outputFileSystem;
68
68
  }
69
- const tryRewrite = (filePath, newUrl) => {
69
+ const rewrite = (newUrl) => {
70
70
  var _a;
71
- if (outputFileSystem.existsSync(filePath) && callback) {
72
- newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
73
- (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
74
- req.url = newUrl;
71
+ (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
72
+ req.url = newUrl;
73
+ if (callback) {
75
74
  return callback(req, res, (...args) => {
76
- req.url = url;
77
75
  next(...args);
78
76
  });
77
+ } else {
78
+ return next();
79
79
  }
80
80
  };
81
81
  if (pathname.endsWith("/")) {
82
82
  const newUrl = url + "index.html";
83
83
  const filePath = import_path.default.join(distPath, pathname, "index.html");
84
- tryRewrite(filePath, newUrl);
84
+ if (outputFileSystem.existsSync(filePath)) {
85
+ return rewrite(newUrl);
86
+ }
85
87
  } else if (
86
88
  // '/main' => '/main.html'
87
89
  !pathname.endsWith(".html")
88
90
  ) {
89
91
  const newUrl = url + ".html";
90
92
  const filePath = import_path.default.join(distPath, pathname + ".html");
91
- tryRewrite(filePath, newUrl);
92
- } else {
93
- tryRewrite(import_path.default.join(distPath, pathname), url);
93
+ if (outputFileSystem.existsSync(filePath)) {
94
+ return rewrite(newUrl);
95
+ }
96
+ }
97
+ if (htmlFallback === "index") {
98
+ if (outputFileSystem.existsSync(import_path.default.join(distPath, "index.html"))) {
99
+ return rewrite("/index.html");
100
+ }
94
101
  }
95
102
  next();
96
103
  };
@@ -1,9 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
3
4
  import type { ListenOptions } from 'net';
4
5
  import { Server } from 'http';
5
6
  import connect from '@rsbuild/shared/connect';
6
- import { Context, RsbuildConfig, StartServerResult, PreviewServerOptions, ServerConfig } from '@rsbuild/shared';
7
+ import { type Context, type ServerConfig, type RsbuildConfig, type StartServerResult, type PreviewServerOptions } from '@rsbuild/shared';
7
8
  type RsbuildProdServerOptions = {
8
9
  pwd: string;
9
10
  output: {
@@ -20,11 +21,13 @@ export declare class RsbuildProdServer {
20
21
  onInit(app: Server): Promise<void>;
21
22
  private applyDefaultMiddlewares;
22
23
  private applyStaticAssetMiddleware;
23
- createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
24
+ createHTTPServer(): Promise<Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
24
25
  listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
25
26
  close(): void;
26
27
  }
27
28
  export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
28
- printURLs
29
+ printURLs,
30
+ strictPort,
31
+ getPortSilently
29
32
  }?: PreviewServerOptions): Promise<StartServerResult>;
30
33
  export {};
@@ -33,11 +33,13 @@ __export(prodServer_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(prodServer_exports);
35
35
  var import_http = require("http");
36
+ var import_https = require("https");
36
37
  var import_connect = __toESM(require("@rsbuild/shared/connect"));
37
38
  var import_path = require("path");
38
39
  var import_sirv = __toESM(require("../../compiled/sirv"));
39
40
  var import_shared = require("@rsbuild/shared");
40
41
  var import_middlewares = require("./middlewares");
42
+ var import_proxy = require("./proxy");
41
43
  class RsbuildProdServer {
42
44
  constructor(options) {
43
45
  this.middlewares = (0, import_connect.default)();
@@ -49,7 +51,16 @@ class RsbuildProdServer {
49
51
  await this.applyDefaultMiddlewares();
50
52
  }
51
53
  async applyDefaultMiddlewares() {
52
- const { headers } = this.options.serverConfig;
54
+ const { headers, proxy, historyApiFallback, compress } = this.options.serverConfig;
55
+ if (compress) {
56
+ const { default: compression } = await Promise.resolve().then(() => __toESM(require("../../compiled/http-compression")));
57
+ this.middlewares.use((req, res, next) => {
58
+ compression({
59
+ gzip: true,
60
+ brotli: false
61
+ })(req, res, next);
62
+ });
63
+ }
53
64
  if (headers) {
54
65
  this.middlewares.use((_req, res, next) => {
55
66
  for (const [key, value] of Object.entries(headers)) {
@@ -58,18 +69,34 @@ class RsbuildProdServer {
58
69
  next();
59
70
  });
60
71
  }
72
+ if (proxy) {
73
+ const { middlewares } = (0, import_proxy.createProxyMiddleware)(proxy, this.app);
74
+ middlewares.forEach((middleware) => {
75
+ this.middlewares.use(middleware);
76
+ });
77
+ }
61
78
  this.applyStaticAssetMiddleware();
79
+ if (historyApiFallback) {
80
+ const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
81
+ const historyApiFallbackMiddleware = connectHistoryApiFallback(
82
+ historyApiFallback === true ? {} : historyApiFallback
83
+ );
84
+ this.middlewares.use(historyApiFallbackMiddleware);
85
+ this.applyStaticAssetMiddleware();
86
+ }
62
87
  this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
63
88
  }
64
89
  applyStaticAssetMiddleware() {
65
90
  const {
66
91
  output: { path, assetPrefix },
92
+ serverConfig: { htmlFallback },
67
93
  pwd
68
94
  } = this.options;
69
95
  const assetMiddleware = (0, import_sirv.default)((0, import_path.join)(pwd, path), {
70
96
  etag: true,
71
97
  dev: true,
72
- ignores: false
98
+ ignores: ["favicon.ico"],
99
+ single: htmlFallback === "index"
73
100
  });
74
101
  this.middlewares.use((req, res, next) => {
75
102
  const url = req.url;
@@ -85,7 +112,13 @@ class RsbuildProdServer {
85
112
  });
86
113
  }
87
114
  async createHTTPServer() {
88
- return (0, import_http.createServer)(this.middlewares);
115
+ const { serverConfig } = this.options;
116
+ const httpsOption = serverConfig.https;
117
+ if (httpsOption) {
118
+ return (0, import_https.createServer)(httpsOption, this.middlewares);
119
+ } else {
120
+ return (0, import_http.createServer)(this.middlewares);
121
+ }
89
122
  }
90
123
  listen(options, listener) {
91
124
  const callback = () => {
@@ -101,31 +134,39 @@ class RsbuildProdServer {
101
134
  this.app.close();
102
135
  }
103
136
  }
104
- async function startProdServer(context, rsbuildConfig, { printURLs = true } = {}) {
105
- var _a, _b, _c, _d;
137
+ async function startProdServer(context, rsbuildConfig, {
138
+ printURLs = true,
139
+ strictPort = false,
140
+ getPortSilently
141
+ } = {}) {
142
+ var _a, _b, _c;
106
143
  if (!process.env.NODE_ENV) {
107
144
  process.env.NODE_ENV = "production";
108
145
  }
109
- const port = await (0, import_shared.getPort)(((_a = rsbuildConfig.dev) == null ? void 0 : _a.port) || import_shared.DEFAULT_PORT);
146
+ const { serverConfig, port, host, https } = await (0, import_shared.getServerOptions)({
147
+ rsbuildConfig,
148
+ strictPort,
149
+ getPortSilently
150
+ });
110
151
  const server = new RsbuildProdServer({
111
152
  pwd: context.rootPath,
112
153
  output: {
113
- path: ((_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.root) || import_shared.ROOT_DIST_DIR,
114
- assetPrefix: (_d = rsbuildConfig.output) == null ? void 0 : _d.assetPrefix
154
+ path: ((_b = (_a = rsbuildConfig.output) == null ? void 0 : _a.distPath) == null ? void 0 : _b.root) || import_shared.ROOT_DIST_DIR,
155
+ assetPrefix: (_c = rsbuildConfig.output) == null ? void 0 : _c.assetPrefix
115
156
  },
116
- serverConfig: rsbuildConfig.server || {}
157
+ serverConfig
117
158
  });
118
159
  const httpServer = await server.createHTTPServer();
119
160
  await server.onInit(httpServer);
120
161
  return new Promise((resolve) => {
121
162
  server.listen(
122
163
  {
123
- host: import_shared.DEFAULT_DEV_HOST,
164
+ host,
124
165
  port
125
166
  },
126
167
  () => {
127
168
  var _a2, _b2;
128
- const urls = (0, import_shared.getAddressUrls)("http", port);
169
+ const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
129
170
  if (printURLs) {
130
171
  const routes = (0, import_shared.formatRoutes)(
131
172
  context.entry,
@@ -1,8 +1,9 @@
1
+ /// <reference types="node" />
1
2
  import http from 'http';
2
3
  import { RequestHandler } from '@rsbuild/shared/http-proxy-middleware';
3
- import { type ProxyDetail, type RequestHandler as Middleware, type RsbuildProxyOptions } from '@rsbuild/shared';
4
- export declare function formatProxyOptions(proxyOptions: RsbuildProxyOptions): ProxyDetail[];
4
+ import { type ProxyDetail, type RequestHandler as Middleware, type ProxyOptions } from '@rsbuild/shared';
5
+ export declare function formatProxyOptions(proxyOptions: ProxyOptions): ProxyDetail[];
5
6
  export type HttpUpgradeHandler = NonNullable<RequestHandler['upgrade']>;
6
- export declare const createProxyMiddleware: (proxyOptions: RsbuildProxyOptions, app: http.Server) => {
7
+ export declare const createProxyMiddleware: (proxyOptions: ProxyOptions, app: http.Server) => {
7
8
  middlewares: Middleware[];
8
9
  };
@@ -52,7 +52,10 @@ const restartDevServer = async ({ filePath }) => {
52
52
  for (const cleaner of cleaners) {
53
53
  await cleaner();
54
54
  }
55
- const rsbuild = await (0, import_commands.init)();
55
+ const rsbuild = await (0, import_commands.init)({ isRestart: true });
56
+ if (!rsbuild) {
57
+ return;
58
+ }
56
59
  await rsbuild.startDevServer();
57
60
  };
58
61
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.0.28",
3
+ "version": "0.1.1",
4
4
  "description": "Unleash the power of Rspack with the out-of-the-box build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -58,19 +58,19 @@
58
58
  "types.d.ts"
59
59
  ],
60
60
  "dependencies": {
61
- "@rspack/core": "0.3.14",
61
+ "@rspack/core": "0.4.0",
62
62
  "core-js": "~3.32.2",
63
63
  "html-webpack-plugin": "npm:html-rspack-plugin@5.5.7",
64
64
  "postcss": "8.4.31",
65
65
  "semver": "^7.5.4",
66
66
  "ws": "^8.2.0",
67
- "@rsbuild/shared": "0.0.28"
67
+ "@rsbuild/shared": "0.1.1"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^16",
71
71
  "@types/ws": "^8.2.0",
72
72
  "@types/semver": "^7.5.4",
73
- "typescript": "^5.2.2"
73
+ "typescript": "^5.3.0"
74
74
  },
75
75
  "engines": {
76
76
  "node": ">=14.0.0"
@@ -1,6 +0,0 @@
1
- /// <reference types="node" />
2
- import { type DevServerHttpsOptions } from '@rsbuild/shared';
3
- export declare const genHttpsOptions: (userOptions: DevServerHttpsOptions, pwd: string) => Promise<{
4
- key?: Buffer | string;
5
- cert?: Buffer | string;
6
- }>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var https_exports = {};
20
- __export(https_exports, {
21
- genHttpsOptions: () => genHttpsOptions
22
- });
23
- module.exports = __toCommonJS(https_exports);
24
- var import_shared = require("@rsbuild/shared");
25
- const genHttpsOptions = async (userOptions, pwd) => {
26
- const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
27
- if (!httpsOptions.key || !httpsOptions.cert) {
28
- let devcertPath;
29
- try {
30
- devcertPath = require.resolve("devcert", { paths: [pwd, __dirname] });
31
- } catch (err) {
32
- const command = import_shared.color.bold(import_shared.color.yellow(`npm add devcert@1.2.2 -D`));
33
- import_shared.logger.error(
34
- `You have enabled "dev.https" option, but the "devcert" package is not installed.`
35
- );
36
- import_shared.logger.error(
37
- `Please run ${command} to install manually, otherwise the https can not work.`
38
- );
39
- throw new Error('[https] "devcert" is not found.');
40
- }
41
- const devcert = require(devcertPath);
42
- const selfsign = await devcert.certificateFor(["localhost"]);
43
- return selfsign;
44
- }
45
- return httpsOptions;
46
- };
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- genHttpsOptions
50
- });