@rsbuild/core 0.0.27 → 0.1.0

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 (60) 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 +33 -20
  11. package/dist/cli/config.js +28 -16
  12. package/dist/cli/prepare.js +1 -1
  13. package/dist/loadEnv.d.ts +5 -0
  14. package/dist/loadEnv.js +58 -0
  15. package/dist/plugins/asset.js +1 -1
  16. package/dist/plugins/bundleAnalyzer.js +1 -1
  17. package/dist/plugins/cache.js +1 -1
  18. package/dist/plugins/cleanOutput.js +1 -1
  19. package/dist/plugins/define.js +1 -1
  20. package/dist/plugins/devtool.js +1 -1
  21. package/dist/plugins/entry.js +1 -1
  22. package/dist/plugins/externals.js +1 -1
  23. package/dist/plugins/fileSize.js +1 -1
  24. package/dist/plugins/html.js +1 -1
  25. package/dist/plugins/inlineChunk.js +8 -12
  26. package/dist/plugins/moment.js +1 -1
  27. package/dist/plugins/nodeAddons.js +1 -1
  28. package/dist/plugins/performance.js +1 -1
  29. package/dist/plugins/splitChunks.js +1 -1
  30. package/dist/plugins/startUrl.js +1 -1
  31. package/dist/plugins/target.js +1 -1
  32. package/dist/plugins/toml.js +1 -1
  33. package/dist/plugins/wasm.js +1 -1
  34. package/dist/plugins/yaml.js +1 -1
  35. package/dist/rspack-provider/config.js +1 -0
  36. package/dist/rspack-provider/core/createContext.js +1 -1
  37. package/dist/rspack-provider/plugins/basic.js +1 -1
  38. package/dist/rspack-provider/plugins/css.js +1 -1
  39. package/dist/rspack-provider/plugins/hmr.js +1 -1
  40. package/dist/rspack-provider/plugins/less.js +1 -1
  41. package/dist/rspack-provider/plugins/minimize.js +1 -1
  42. package/dist/rspack-provider/plugins/output.js +1 -1
  43. package/dist/rspack-provider/plugins/progress.js +1 -1
  44. package/dist/rspack-provider/plugins/resolve.js +1 -1
  45. package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
  46. package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
  47. package/dist/rspack-provider/plugins/sass.js +1 -1
  48. package/dist/rspack-provider/plugins/swc.js +1 -1
  49. package/dist/rspack-provider/plugins/transition.js +1 -1
  50. package/dist/server/dev-middleware/index.js +1 -1
  51. package/dist/server/devServer.js +10 -10
  52. package/dist/server/middlewares.d.ts +2 -1
  53. package/dist/server/middlewares.js +23 -11
  54. package/dist/server/prodServer.d.ts +7 -3
  55. package/dist/server/prodServer.js +61 -10
  56. package/dist/server/proxy.d.ts +4 -3
  57. package/dist/server/restart.js +4 -1
  58. package/package.json +4 -4
  59. package/dist/server/https.d.ts +0 -6
  60. package/dist/server/https.js +0 -50
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(nodeAddons_exports);
24
24
  var import_path = require("path");
25
25
  var import_shared = require("@rsbuild/shared");
26
26
  const pluginNodeAddons = () => ({
27
- name: "plugin-node-addons",
27
+ name: "rsbuild:node-addons",
28
28
  setup(api) {
29
29
  api.modifyBundlerChain(
30
30
  async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
@@ -32,7 +32,7 @@ function applyProfile({
32
32
  chain.profile(profile);
33
33
  }
34
34
  const pluginPerformance = () => ({
35
- name: "plugin-performance",
35
+ name: "rsbuild:performance",
36
36
  setup(api) {
37
37
  api.modifyRsbuildConfig((rsbuildConfig) => {
38
38
  var _a, _b, _c;
@@ -172,7 +172,7 @@ const SPLIT_STRATEGY_DISPATCHER = {
172
172
  };
173
173
  function pluginSplitChunks() {
174
174
  return {
175
- name: "plugin-split-chunks",
175
+ name: "rsbuild:split-chunks",
176
176
  setup(api) {
177
177
  api.modifyBundlerChain(
178
178
  async (chain, { isServer, isWebWorker, isServiceWorker }) => {
@@ -93,7 +93,7 @@ const replacePlaceholder = (url, port) => url.replace(/<port>/g, String(port));
93
93
  const openedURLs = [];
94
94
  function pluginStartUrl() {
95
95
  return {
96
- name: "plugin-start-url",
96
+ name: "rsbuild:start-url",
97
97
  setup(api) {
98
98
  api.onAfterStartDevServer(async (params) => {
99
99
  const { port, routes } = params;
@@ -23,7 +23,7 @@ __export(target_exports, {
23
23
  module.exports = __toCommonJS(target_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginTarget = () => ({
26
- name: "plugin-target",
26
+ name: "rsbuild:target",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain(async (chain, { target }) => {
29
29
  if (target === "node") {
@@ -23,7 +23,7 @@ __export(toml_exports, {
23
23
  module.exports = __toCommonJS(toml_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginToml = () => ({
26
- name: "plugin-toml",
26
+ name: "rsbuild:toml",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
29
29
  chain.module.rule(CHAIN_ID.RULE.TOML).type("javascript/auto").test(/\.toml$/).use(CHAIN_ID.USE.TOML).loader((0, import_shared.getSharedPkgCompiledPath)("toml-loader"));
@@ -24,7 +24,7 @@ module.exports = __toCommonJS(wasm_exports);
24
24
  var import_path = require("path");
25
25
  var import_shared = require("@rsbuild/shared");
26
26
  const pluginWasm = () => ({
27
- name: "plugin-wasm",
27
+ name: "rsbuild:wasm",
28
28
  setup(api) {
29
29
  api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
30
30
  const config = api.getNormalizedConfig();
@@ -23,7 +23,7 @@ __export(yaml_exports, {
23
23
  module.exports = __toCommonJS(yaml_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginYaml = () => ({
26
- name: "plugin-yaml",
26
+ name: "rsbuild:yaml",
27
27
  setup(api) {
28
28
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
29
29
  chain.module.rule(CHAIN_ID.RULE.YAML).type("javascript/auto").test(/\.ya?ml$/).use(CHAIN_ID.USE.YAML).loader((0, import_shared.getSharedPkgCompiledPath)("yaml-loader"));
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(config_exports);
26
26
  var import_shared = require("@rsbuild/shared");
27
27
  const createDefaultConfig = () => ({
28
28
  dev: (0, import_shared.getDefaultDevConfig)(),
29
+ server: (0, import_shared.getDefaultServerConfig)(),
29
30
  html: (0, import_shared.getDefaultHtmlConfig)(),
30
31
  source: (0, import_shared.getDefaultSourceConfig)(),
31
32
  output: (0, import_shared.getDefaultOutputConfig)(),
@@ -64,7 +64,7 @@ function createContextByConfig(options, bundlerType, sourceConfig = {}, outputCo
64
64
  entry: sourceConfig.entry || // TODO: remove sourceConfig.entries in v0.2.0
65
65
  // compat with previous config
66
66
  sourceConfig.entries || getDefaultEntry(rootPath),
67
- version: "0.0.27",
67
+ version: "0.1.0",
68
68
  target,
69
69
  rootPath,
70
70
  distPath,
@@ -23,7 +23,7 @@ __export(basic_exports, {
23
23
  module.exports = __toCommonJS(basic_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginBasic = () => ({
26
- name: "plugin-basic",
26
+ name: "rsbuild:basic",
27
27
  setup(api) {
28
28
  (0, import_shared.applyBasicPlugin)(api);
29
29
  }
@@ -143,7 +143,7 @@ const applyCSSModuleRule = (rules, ruleTest, config) => {
143
143
  };
144
144
  const pluginCss = () => {
145
145
  return {
146
- name: "plugin-css",
146
+ name: "rsbuild:css",
147
147
  setup(api) {
148
148
  api.modifyBundlerChain(async (chain, utils) => {
149
149
  const config = api.getNormalizedConfig();
@@ -23,7 +23,7 @@ __export(hmr_exports, {
23
23
  module.exports = __toCommonJS(hmr_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginHMR = () => ({
26
- name: "plugin-hmr",
26
+ name: "rsbuild:hmr",
27
27
  setup(api) {
28
28
  api.modifyRspackConfig((rspackConfig, utils) => {
29
29
  const config = api.getNormalizedConfig();
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(less_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  function pluginLess() {
36
36
  return {
37
- name: "plugin-less",
37
+ name: "rsbuild:less",
38
38
  setup(api) {
39
39
  api.modifyBundlerChain(async (chain, utils) => {
40
40
  const config = api.getNormalizedConfig();
@@ -56,7 +56,7 @@ function applyCSSMinimizer(chain) {
56
56
  chain.optimization.minimizer(import_shared.CHAIN_ID.MINIMIZER.CSS).use(import_core.SwcCssMinimizerRspackPlugin, []).end();
57
57
  }
58
58
  const pluginMinimize = () => ({
59
- name: "plugin-minimize",
59
+ name: "rsbuild:minimize",
60
60
  setup(api) {
61
61
  api.modifyBundlerChain((chain, { isProd }) => {
62
62
  const config = api.getNormalizedConfig();
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(output_exports);
34
34
  var import_path = require("path");
35
35
  var import_shared = require("@rsbuild/shared");
36
36
  const pluginOutput = () => ({
37
- name: "plugin-output",
37
+ name: "rsbuild:output",
38
38
  setup(api) {
39
39
  (0, import_shared.applyOutputPlugin)(api);
40
40
  api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
@@ -33,7 +33,7 @@ __export(progress_exports, {
33
33
  module.exports = __toCommonJS(progress_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  const pluginProgress = () => ({
36
- name: "plugin-progress",
36
+ name: "rsbuild:progress",
37
37
  setup(api) {
38
38
  api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
39
39
  var _a;
@@ -23,7 +23,7 @@ __export(resolve_exports, {
23
23
  module.exports = __toCommonJS(resolve_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginResolve = () => ({
26
- name: "plugin-resolve",
26
+ name: "rsbuild:resolve",
27
27
  setup(api) {
28
28
  (0, import_shared.applyResolvePlugin)(api);
29
29
  api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { RsbuildPlugin } from '../../types';
2
3
  import inspector from 'inspector';
3
4
  export declare const stopProfiler: (output: string, profileSession?: inspector.Session) => void;
@@ -50,7 +50,7 @@ const stopProfiler = (output, profileSession) => {
50
50
  });
51
51
  };
52
52
  const pluginRspackProfile = () => ({
53
- name: "plugin-rspack-profile",
53
+ name: "rsbuild:rspack-profile",
54
54
  setup(api) {
55
55
  var _a;
56
56
  const RSPACK_PROFILE = (_a = process.env.RSPACK_PROFILE) == null ? void 0 : _a.toUpperCase();
@@ -34,7 +34,7 @@ module.exports = __toCommonJS(sass_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  function pluginSass() {
36
36
  return {
37
- name: "plugin-sass",
37
+ name: "rsbuild:sass",
38
38
  setup(api) {
39
39
  api.onAfterCreateCompiler(({ compiler }) => {
40
40
  (0, import_shared.patchCompilerGlobalLocation)(compiler);
@@ -60,7 +60,7 @@ async function getDefaultSwcConfig(config, rootPath, target) {
60
60
  };
61
61
  }
62
62
  const pluginSwc = () => ({
63
- name: "plugin-swc",
63
+ name: "rsbuild:swc",
64
64
  setup(api) {
65
65
  api.modifyBundlerChain(
66
66
  async (chain, { CHAIN_ID, target, isServer, isServiceWorker }) => {
@@ -23,7 +23,7 @@ __export(transition_exports, {
23
23
  module.exports = __toCommonJS(transition_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
25
  const pluginTransition = () => ({
26
- name: "plugin-transition",
26
+ name: "rsbuild:transition",
27
27
  setup(api) {
28
28
  process.env.RSPACK_CONFIG_VALIDATE = "loose-silent";
29
29
  api.modifyBundlerChain(async (chain, { isProd }) => {
@@ -84,7 +84,7 @@ class DevMiddleware extends import_events.EventEmitter {
84
84
  callbacks,
85
85
  hmrClientPath: enableHMR ? getHMRClientPath(devOptions.client) : void 0,
86
86
  serverSideRender: true,
87
- ...devOptions.devMiddleware
87
+ writeToDisk: devOptions.writeToDisk
88
88
  });
89
89
  return middleware;
90
90
  }
@@ -112,17 +112,19 @@ class RsbuildDevServer {
112
112
  }
113
113
  devMiddleware.init(app);
114
114
  devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
115
+ const { distPath } = this.output;
115
116
  this.middlewares.use(
116
117
  (0, import_middlewares.getHtmlFallbackMiddleware)({
117
- distPath: (0, import_path.join)(this.pwd, this.output.distPath),
118
+ distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
118
119
  publicPath: this.output.publicPath,
119
- callback: devMiddleware.middleware
120
+ callback: devMiddleware.middleware,
121
+ htmlFallback: this.dev.htmlFallback
120
122
  })
121
123
  );
122
124
  if (dev.historyApiFallback) {
123
125
  const { default: connectHistoryApiFallback } = await Promise.resolve().then(() => __toESM(require("../../compiled/connect-history-api-fallback")));
124
126
  const historyApiFallbackMiddleware = connectHistoryApiFallback(
125
- typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback
127
+ dev.historyApiFallback === true ? {} : dev.historyApiFallback
126
128
  );
127
129
  this.middlewares.use(historyApiFallbackMiddleware);
128
130
  devMiddleware.middleware && this.middlewares.use(devMiddleware.middleware);
@@ -134,9 +136,7 @@ class RsbuildDevServer {
134
136
  const { dev } = this;
135
137
  const devHttpsOption = typeof dev === "object" && dev.https;
136
138
  if (devHttpsOption) {
137
- const { genHttpsOptions } = require("./https");
138
- const httpsOptions = await genHttpsOptions(devHttpsOption, this.pwd);
139
- return (0, import_https.createServer)(httpsOptions, this.middlewares);
139
+ return (0, import_https.createServer)(devHttpsOption, this.middlewares);
140
140
  } else {
141
141
  return (0, import_http.createServer)(this.middlewares);
142
142
  }
@@ -164,7 +164,7 @@ async function startDevServer(options, createDevMiddleware, {
164
164
  logger: customLogger,
165
165
  getPortSilently
166
166
  } = {}) {
167
- var _a, _b, _c, _d, _e;
167
+ var _a, _b, _c, _d;
168
168
  if (!process.env.NODE_ENV) {
169
169
  process.env.NODE_ENV = "development";
170
170
  }
@@ -182,10 +182,10 @@ async function startDevServer(options, createDevMiddleware, {
182
182
  open
183
183
  };
184
184
  const protocol = https ? "https" : "http";
185
- 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);
186
186
  const routes = (0, import_shared.formatRoutes)(
187
187
  options.context.entry,
188
- (_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
189
189
  );
190
190
  (0, import_shared.debug)("create dev server");
191
191
  const { devMiddleware, compiler } = await createDevMiddleware(
@@ -198,7 +198,7 @@ async function startDevServer(options, createDevMiddleware, {
198
198
  devMiddleware,
199
199
  dev: devServerConfig,
200
200
  output: {
201
- distPath: ((_e = (_d = rsbuildConfig.output) == null ? void 0 : _d.distPath) == null ? void 0 : _e.root) || import_shared.ROOT_DIST_DIR,
201
+ distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
202
202
  publicPath
203
203
  }
204
204
  });
@@ -1,8 +1,9 @@
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
6
  publicPath: string;
7
7
  callback?: Middleware;
8
+ htmlFallback?: HtmlFallback;
8
9
  }) => 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, publicPath, 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,43 @@ 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
+ newUrl = (0, import_shared.urlJoin)(publicPath, newUrl);
72
+ (_a = import_shared.debug) == null ? void 0 : _a(`Rewriting ${req.method} ${req.url} to ${newUrl}`);
73
+ req.url = newUrl;
74
+ if (callback) {
75
75
  return callback(req, res, (...args) => {
76
- req.url = url;
77
76
  next(...args);
78
77
  });
78
+ } else {
79
+ return next();
79
80
  }
80
81
  };
81
82
  if (pathname.endsWith("/")) {
82
83
  const newUrl = url + "index.html";
83
84
  const filePath = import_path.default.join(distPath, pathname, "index.html");
84
- tryRewrite(filePath, newUrl);
85
+ if (outputFileSystem.existsSync(filePath)) {
86
+ return rewrite(newUrl);
87
+ }
85
88
  } else if (
86
89
  // '/main' => '/main.html'
87
90
  !pathname.endsWith(".html")
88
91
  ) {
89
92
  const newUrl = url + ".html";
90
93
  const filePath = import_path.default.join(distPath, pathname + ".html");
91
- tryRewrite(filePath, newUrl);
94
+ if (outputFileSystem.existsSync(filePath)) {
95
+ return rewrite(newUrl);
96
+ }
92
97
  } else {
93
- tryRewrite(import_path.default.join(distPath, pathname), url);
98
+ if (outputFileSystem.existsSync(import_path.default.join(distPath, pathname))) {
99
+ return rewrite(url);
100
+ }
101
+ }
102
+ if (htmlFallback === "index") {
103
+ if (outputFileSystem.existsSync(import_path.default.join(distPath, "index.html"))) {
104
+ return rewrite("/index.html");
105
+ }
94
106
  }
95
107
  next();
96
108
  };
@@ -1,15 +1,17 @@
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 } 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: {
10
11
  path: string;
11
12
  assetPrefix?: string;
12
13
  };
14
+ serverConfig: ServerConfig;
13
15
  };
14
16
  export declare class RsbuildProdServer {
15
17
  private app;
@@ -19,11 +21,13 @@ export declare class RsbuildProdServer {
19
21
  onInit(app: Server): Promise<void>;
20
22
  private applyDefaultMiddlewares;
21
23
  private applyStaticAssetMiddleware;
22
- 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>>;
23
25
  listen(options?: number | ListenOptions | undefined, listener?: () => void): void;
24
26
  close(): void;
25
27
  }
26
28
  export declare function startProdServer(context: Context, rsbuildConfig: RsbuildConfig, {
27
- printURLs
29
+ printURLs,
30
+ strictPort,
31
+ getPortSilently
28
32
  }?: PreviewServerOptions): Promise<StartServerResult>;
29
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,18 +51,52 @@ class RsbuildProdServer {
49
51
  await this.applyDefaultMiddlewares();
50
52
  }
51
53
  async applyDefaultMiddlewares() {
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
+ }
64
+ if (headers) {
65
+ this.middlewares.use((_req, res, next) => {
66
+ for (const [key, value] of Object.entries(headers)) {
67
+ res.setHeader(key, value);
68
+ }
69
+ next();
70
+ });
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
+ }
52
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
+ }
53
87
  this.middlewares.use(import_middlewares.faviconFallbackMiddleware);
54
88
  }
55
89
  applyStaticAssetMiddleware() {
56
90
  const {
57
91
  output: { path, assetPrefix },
92
+ serverConfig: { htmlFallback },
58
93
  pwd
59
94
  } = this.options;
60
95
  const assetMiddleware = (0, import_sirv.default)((0, import_path.join)(pwd, path), {
61
96
  etag: true,
62
97
  dev: true,
63
- ignores: false
98
+ ignores: ["favicon.ico"],
99
+ single: htmlFallback === "index"
64
100
  });
65
101
  this.middlewares.use((req, res, next) => {
66
102
  const url = req.url;
@@ -76,7 +112,13 @@ class RsbuildProdServer {
76
112
  });
77
113
  }
78
114
  async createHTTPServer() {
79
- 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
+ }
80
122
  }
81
123
  listen(options, listener) {
82
124
  const callback = () => {
@@ -92,30 +134,39 @@ class RsbuildProdServer {
92
134
  this.app.close();
93
135
  }
94
136
  }
95
- async function startProdServer(context, rsbuildConfig, { printURLs = true } = {}) {
96
- 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;
97
143
  if (!process.env.NODE_ENV) {
98
144
  process.env.NODE_ENV = "production";
99
145
  }
100
- 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
+ });
101
151
  const server = new RsbuildProdServer({
102
152
  pwd: context.rootPath,
103
153
  output: {
104
- path: ((_c = (_b = rsbuildConfig.output) == null ? void 0 : _b.distPath) == null ? void 0 : _c.root) || import_shared.ROOT_DIST_DIR,
105
- assetPrefix: (_d = rsbuildConfig.output) == null ? void 0 : _d.assetPrefix
106
- }
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
156
+ },
157
+ serverConfig
107
158
  });
108
159
  const httpServer = await server.createHTTPServer();
109
160
  await server.onInit(httpServer);
110
161
  return new Promise((resolve) => {
111
162
  server.listen(
112
163
  {
113
- host: import_shared.DEFAULT_DEV_HOST,
164
+ host,
114
165
  port
115
166
  },
116
167
  () => {
117
168
  var _a2, _b2;
118
- const urls = (0, import_shared.getAddressUrls)("http", port);
169
+ const urls = (0, import_shared.getAddressUrls)(https ? "https" : "http", port);
119
170
  if (printURLs) {
120
171
  const routes = (0, import_shared.formatRoutes)(
121
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.27",
3
+ "version": "0.1.0",
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.27"
67
+ "@rsbuild/shared": "0.1.0"
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
- }>;