@rsbuild/core 0.0.28 → 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 (59) 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/core/createContext.js +1 -1
  36. package/dist/rspack-provider/plugins/basic.js +1 -1
  37. package/dist/rspack-provider/plugins/css.js +1 -1
  38. package/dist/rspack-provider/plugins/hmr.js +1 -1
  39. package/dist/rspack-provider/plugins/less.js +1 -1
  40. package/dist/rspack-provider/plugins/minimize.js +1 -1
  41. package/dist/rspack-provider/plugins/output.js +1 -1
  42. package/dist/rspack-provider/plugins/progress.js +1 -1
  43. package/dist/rspack-provider/plugins/resolve.js +1 -1
  44. package/dist/rspack-provider/plugins/rspackProfile.d.ts +1 -0
  45. package/dist/rspack-provider/plugins/rspackProfile.js +1 -1
  46. package/dist/rspack-provider/plugins/sass.js +1 -1
  47. package/dist/rspack-provider/plugins/swc.js +1 -1
  48. package/dist/rspack-provider/plugins/transition.js +1 -1
  49. package/dist/server/dev-middleware/index.js +1 -1
  50. package/dist/server/devServer.js +8 -9
  51. package/dist/server/middlewares.d.ts +2 -1
  52. package/dist/server/middlewares.js +23 -11
  53. package/dist/server/prodServer.d.ts +6 -3
  54. package/dist/server/prodServer.js +52 -11
  55. package/dist/server/proxy.d.ts +4 -3
  56. package/dist/server/restart.js +4 -1
  57. package/package.json +4 -4
  58. package/dist/server/https.d.ts +0 -6
  59. 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"));
@@ -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.28",
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
  }
@@ -117,13 +117,14 @@ class RsbuildDevServer {
117
117
  (0, import_middlewares.getHtmlFallbackMiddleware)({
118
118
  distPath: (0, import_path.isAbsolute)(distPath) ? distPath : (0, import_path.join)(this.pwd, distPath),
119
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,10 +182,10 @@ 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(
@@ -199,7 +198,7 @@ async function startDevServer(options, createDevMiddleware, {
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,
201
+ distPath: ((_d = (_c = rsbuildConfig.output) == null ? void 0 : _c.distPath) == null ? void 0 : _d.root) || import_shared.ROOT_DIST_DIR,
203
202
  publicPath
204
203
  }
205
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,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.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.28"
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
- }>;
@@ -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
- });