@rsbuild/core 0.0.20 → 0.0.22

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 (51) hide show
  1. package/compiled/connect-history-api-fallback/index.d.ts +1 -0
  2. package/compiled/connect-history-api-fallback/index.js +1 -0
  3. package/compiled/connect-history-api-fallback/license +21 -0
  4. package/compiled/connect-history-api-fallback/package.json +1 -0
  5. package/compiled/open/index.d.ts +153 -0
  6. package/compiled/open/index.js +1 -0
  7. package/compiled/open/license +9 -0
  8. package/compiled/open/package.json +1 -0
  9. package/compiled/open/xdg-open +1066 -0
  10. package/dist/cli/commands.js +2 -2
  11. package/dist/cli/config.js +19 -2
  12. package/dist/cli/index.d.ts +1 -5
  13. package/dist/cli/index.js +3 -21
  14. package/dist/cli/run.d.ts +7 -0
  15. package/dist/cli/run.js +49 -0
  16. package/dist/client/hmr.js +418 -0
  17. package/dist/index.d.ts +1 -1
  18. package/dist/plugins/cache.js +8 -8
  19. package/dist/plugins/cleanOutput.js +3 -3
  20. package/dist/plugins/fileSize.js +24 -24
  21. package/dist/plugins/html.js +6 -24
  22. package/dist/plugins/index.js +0 -1
  23. package/dist/plugins/startUrl.js +2 -4
  24. package/dist/rspack-provider/core/createCompiler.d.ts +1 -1
  25. package/dist/rspack-provider/core/createCompiler.js +3 -3
  26. package/dist/rspack-provider/core/initHooks.d.ts +2 -1
  27. package/dist/rspack-provider/plugins/css.js +3 -10
  28. package/dist/rspack-provider/plugins/rspack-profile.js +6 -6
  29. package/dist/rspack-provider/plugins/swc.js +2 -3
  30. package/dist/rspack-provider/provider.js +4 -4
  31. package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.d.ts +1 -1
  32. package/dist/rspack-provider/rspackLoader/css-modules-typescript-pre-loader/postcss-icss-extract-plugin.js +4 -4
  33. package/dist/rspack-provider/shared/fs.js +2 -2
  34. package/dist/rspack-provider/shared/plugin.js +1 -4
  35. package/dist/server/dev-middleware/index.d.ts +1 -0
  36. package/dist/server/dev-middleware/index.js +5 -4
  37. package/dist/server/devServer.d.ts +2 -2
  38. package/dist/server/devServer.js +26 -18
  39. package/dist/server/prodServer.d.ts +5 -3
  40. package/dist/server/prodServer.js +14 -4
  41. package/dist/server/restart.d.ts +11 -0
  42. package/dist/server/restart.js +64 -0
  43. package/package.json +8 -38
  44. package/dist/plugins/rem.d.ts +0 -2
  45. package/dist/plugins/rem.js +0 -103
  46. package/dist/rspack-provider/plugins/fallback.d.ts +0 -2
  47. package/dist/rspack-provider/plugins/fallback.js +0 -52
  48. package/dist/server/dev-middleware/hmr-client/createSocketUrl.js +0 -68
  49. package/dist/server/dev-middleware/hmr-client/index.js +0 -164
  50. /package/dist/{server/dev-middleware/hmr-client → client/hmr}/createSocketUrl.d.ts +0 -0
  51. /package/dist/{server/dev-middleware/hmr-client → client/hmr}/index.d.ts +0 -0
@@ -33,7 +33,7 @@ __export(prodServer_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(prodServer_exports);
35
35
  var import_http = require("http");
36
- var import_connect = __toESM(require("connect"));
36
+ var import_connect = __toESM(require("@rsbuild/shared/connect"));
37
37
  var import_path = require("path");
38
38
  var import_sirv = __toESM(require("sirv"));
39
39
  var import_shared = require("@rsbuild/shared");
@@ -92,7 +92,7 @@ class RsbuildProdServer {
92
92
  this.app.close();
93
93
  }
94
94
  }
95
- async function startProdServer(context, rsbuildConfig) {
95
+ async function startProdServer(context, rsbuildConfig, { printURLs = true } = {}) {
96
96
  var _a, _b, _c, _d;
97
97
  if (!process.env.NODE_ENV) {
98
98
  process.env.NODE_ENV = "production";
@@ -114,13 +114,23 @@ async function startProdServer(context, rsbuildConfig) {
114
114
  port
115
115
  },
116
116
  () => {
117
+ var _a2, _b2;
117
118
  const urls = (0, import_shared.getAddressUrls)("http", port);
118
- (0, import_shared.printServerURLs)(urls, context.entry);
119
+ if (printURLs) {
120
+ const routes = (0, import_shared.formatRoutes)(
121
+ context.entry,
122
+ (_b2 = (_a2 = rsbuildConfig.output) == null ? void 0 : _a2.distPath) == null ? void 0 : _b2.html
123
+ );
124
+ (0, import_shared.printServerURLs)(
125
+ (0, import_shared.isFunction)(printURLs) ? printURLs(urls) : urls,
126
+ routes
127
+ );
128
+ }
119
129
  resolve({
120
130
  port,
121
131
  urls: urls.map((item) => item.url),
122
132
  server: {
123
- close: () => {
133
+ close: async () => {
124
134
  server.close();
125
135
  }
126
136
  }
@@ -0,0 +1,11 @@
1
+ type Cleaner = () => Promise<unknown> | unknown;
2
+ /**
3
+ * Add a cleaner to handle side effects
4
+ */
5
+ export declare const registerCleaner: (cleaner: Cleaner) => void;
6
+ export declare const restartDevServer: ({
7
+ filePath
8
+ }: {
9
+ filePath: string;
10
+ }) => Promise<void>;
11
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var restart_exports = {};
30
+ __export(restart_exports, {
31
+ registerCleaner: () => registerCleaner,
32
+ restartDevServer: () => restartDevServer
33
+ });
34
+ module.exports = __toCommonJS(restart_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_shared = require("@rsbuild/shared");
37
+ var import_run = require("../cli/run");
38
+ const cleaners = [];
39
+ const registerCleaner = (cleaner) => {
40
+ cleaners.push(cleaner);
41
+ };
42
+ const clearConsole = () => {
43
+ if (process.stdout.isTTY && !process.env.DEBUG) {
44
+ process.stdout.write("\x1B[H\x1B[2J");
45
+ }
46
+ };
47
+ const restartDevServer = async ({ filePath }) => {
48
+ clearConsole();
49
+ const filename = import_path.default.basename(filePath);
50
+ import_shared.logger.info(`Restart because ${import_shared.color.yellow(filename)} is changed.
51
+ `);
52
+ for (const cleaner of cleaners) {
53
+ await cleaner();
54
+ }
55
+ const rsbuild = await (0, import_run.runCli)({
56
+ isRestart: true
57
+ });
58
+ await rsbuild.startDevServer();
59
+ };
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ registerCleaner,
63
+ restartDevServer
64
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
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": {
@@ -21,9 +21,9 @@
21
21
  "types": "./dist/server/index.d.ts",
22
22
  "default": "./dist/server/index.js"
23
23
  },
24
- "./hmr-client": {
25
- "types": "./dist/server/dev-middleware/hmr-client/index.d.ts",
26
- "default": "./dist/server/dev-middleware/hmr-client/index.js"
24
+ "./client/*": {
25
+ "types": "./dist/client/*.d.ts",
26
+ "default": "./dist/client/*.js"
27
27
  },
28
28
  "./cli": {
29
29
  "types": "./dist/cli/index.d.ts",
@@ -47,28 +47,6 @@
47
47
  },
48
48
  "main": "./dist/index.js",
49
49
  "types": "./dist/index.d.ts",
50
- "typesVersions": {
51
- "*": {
52
- "cli": [
53
- "./dist/cli/index.d.ts"
54
- ],
55
- "server": [
56
- "./dist/server/index.d.ts"
57
- ],
58
- "hmr-client": [
59
- "./dist/server/dev-middleware/hmr-client/index.d.ts"
60
- ],
61
- "plugins/*": [
62
- "./dist/plugins/*.d.ts"
63
- ],
64
- "rspack-plugin-css": [
65
- "./dist/rspack-provider/plugins/css.d.ts"
66
- ],
67
- "rspack-provider": [
68
- "./dist/rspack-provider/index.d.ts"
69
- ]
70
- }
71
- },
72
50
  "bin": {
73
51
  "rsbuild": "./bin/rsbuild.js"
74
52
  },
@@ -76,34 +54,26 @@
76
54
  "bin",
77
55
  "dist",
78
56
  "static",
57
+ "compiled",
79
58
  "types.d.ts"
80
59
  ],
81
60
  "dependencies": {
82
- "@rspack/core": "0.3.11",
83
- "connect": "3.7.0",
84
- "connect-history-api-fallback": "^2.0.0",
61
+ "@rspack/core": "0.3.12",
85
62
  "commander": "^10.0.1",
86
63
  "core-js": "~3.32.2",
87
- "filesize": "^8.0.7",
88
64
  "gzip-size": "^6.0.0",
89
- "html-webpack-plugin": "npm:html-rspack-plugin@5.5.4",
65
+ "html-webpack-plugin": "npm:html-rspack-plugin@5.5.5",
90
66
  "http-compression": "1.0.6",
91
67
  "http-proxy-middleware": "^2.0.1",
92
68
  "jiti": "^1.20.0",
93
- "lodash": "^4.17.21",
94
- "open": "^8.4.0",
95
69
  "postcss": "8.4.31",
96
70
  "rslog": "^1.1.0",
97
71
  "semver": "^7.5.4",
98
72
  "sirv": "^2.0.3",
99
- "strip-ansi": "^6.0.1",
100
73
  "ws": "^8.2.0",
101
- "@rsbuild/shared": "0.0.20"
74
+ "@rsbuild/shared": "0.0.22"
102
75
  },
103
76
  "devDependencies": {
104
- "@types/connect": "3.4.35",
105
- "@types/connect-history-api-fallback": "^1.3.5",
106
- "@types/lodash": "^4.14.200",
107
77
  "@types/node": "^16",
108
78
  "@types/ws": "^8.2.0",
109
79
  "@types/semver": "^7.5.4",
@@ -1,2 +0,0 @@
1
- import { type DefaultRsbuildPlugin } from '@rsbuild/shared';
2
- export declare const pluginRem: () => DefaultRsbuildPlugin;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var rem_exports = {};
30
- __export(rem_exports, {
31
- pluginRem: () => pluginRem
32
- });
33
- module.exports = __toCommonJS(rem_exports);
34
- var import_lodash = __toESM(require("lodash"));
35
- var import_shared = require("@rsbuild/shared");
36
- const defaultOptions = {
37
- enableRuntime: true,
38
- rootFontSize: 50
39
- };
40
- const pluginRem = () => ({
41
- name: "plugin-rem",
42
- pre: ["plugin-css", "plugin-less", "plugin-sass", "plugin-stylus"],
43
- setup(api) {
44
- api.modifyBundlerChain(
45
- async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
46
- const config = api.getNormalizedConfig();
47
- const {
48
- output: { convertToRem }
49
- } = config;
50
- if (!convertToRem || isServer || isWebWorker) {
51
- return;
52
- }
53
- const userOptions = {
54
- ...defaultOptions,
55
- ...typeof convertToRem === "boolean" ? {} : convertToRem
56
- };
57
- const { default: PxToRemPlugin } = await Promise.resolve().then(() => __toESM(require((0, import_shared.getSharedPkgCompiledPath)("postcss-pxtorem"))));
58
- const applyRules = [
59
- CHAIN_ID.RULE.CSS,
60
- CHAIN_ID.RULE.LESS,
61
- CHAIN_ID.RULE.SASS,
62
- CHAIN_ID.RULE.STYLUS
63
- ];
64
- const getPxToRemPlugin = () => PxToRemPlugin({
65
- rootValue: userOptions.rootFontSize,
66
- unitPrecision: 5,
67
- propList: ["*"],
68
- ...import_lodash.default.cloneDeep(userOptions.pxtorem || {})
69
- });
70
- applyRules.forEach((name) => {
71
- chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
72
- var _a;
73
- return {
74
- ...options,
75
- postcssOptions: {
76
- ...options.postcssOptions || {},
77
- plugins: [
78
- ...((_a = options.postcssOptions) == null ? void 0 : _a.plugins) || [],
79
- getPxToRemPlugin()
80
- ]
81
- }
82
- };
83
- });
84
- });
85
- if (!userOptions.enableRuntime) {
86
- return;
87
- }
88
- const entries = Object.keys(chain.entryPoints.entries() || {});
89
- const distDir = (0, import_shared.getDistPath)(config.output, "js");
90
- chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(import_shared.AutoSetRootFontSizePlugin, [
91
- userOptions,
92
- entries,
93
- HtmlPlugin,
94
- distDir
95
- ]);
96
- }
97
- );
98
- }
99
- });
100
- // Annotate the CommonJS export names for ESM import in node:
101
- 0 && (module.exports = {
102
- pluginRem
103
- });
@@ -1,2 +0,0 @@
1
- import type { RsbuildPlugin } from '../types';
2
- export declare const pluginFallback: () => RsbuildPlugin;
@@ -1,52 +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 fallback_exports = {};
20
- __export(fallback_exports, {
21
- pluginFallback: () => pluginFallback
22
- });
23
- module.exports = __toCommonJS(fallback_exports);
24
- var import_path = require("path");
25
- var import_shared = require("@rsbuild/shared");
26
- const pluginFallback = () => ({
27
- name: "plugin-fallback",
28
- setup(api) {
29
- api.modifyRspackConfig((config, { isProd }) => {
30
- var _a;
31
- const rsbuildConfig = api.getNormalizedConfig();
32
- if (!rsbuildConfig.output.enableAssetFallback) {
33
- return;
34
- }
35
- const distDir = (0, import_shared.getDistPath)(rsbuildConfig.output, "media");
36
- const filename = (0, import_shared.getFilename)(rsbuildConfig.output, "media", isProd);
37
- (0, import_shared.setConfig)(config, "output.assetModuleFilename", (0, import_path.join)(distDir, filename));
38
- if (!config.module) {
39
- return;
40
- }
41
- (0, import_shared.setConfig)(
42
- config,
43
- "module.rules",
44
- (0, import_shared.resourceRuleFallback)((_a = config.module) == null ? void 0 : _a.rules)
45
- );
46
- });
47
- }
48
- });
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- pluginFallback
52
- });
@@ -1,68 +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 createSocketUrl_exports = {};
20
- __export(createSocketUrl_exports, {
21
- HMR_SOCK_PATH: () => HMR_SOCK_PATH,
22
- createSocketUrl: () => createSocketUrl,
23
- formatURL: () => formatURL
24
- });
25
- module.exports = __toCommonJS(createSocketUrl_exports);
26
- const HMR_SOCK_PATH = "/rsbuild-hmr";
27
- function createSocketUrl(resourceQuery) {
28
- const searchParams = resourceQuery.substr(1).split("&");
29
- const options = {};
30
- for (const pair of searchParams) {
31
- const ary = pair.split("=");
32
- options[ary[0]] = decodeURIComponent(ary[1]);
33
- }
34
- const currentLocation = self.location;
35
- return getSocketUrl(options, currentLocation);
36
- }
37
- function formatURL({
38
- port,
39
- protocol,
40
- hostname,
41
- pathname
42
- }) {
43
- if (window.URL) {
44
- const url = new URL("http://localhost");
45
- url.port = port;
46
- url.hostname = hostname;
47
- url.protocol = protocol;
48
- url.pathname = pathname;
49
- return url.toString();
50
- }
51
- const colon = protocol.indexOf(":") === -1 ? ":" : "";
52
- return `${protocol}${colon}//${hostname}:${port}${pathname}`;
53
- }
54
- function getSocketUrl(urlParts, location) {
55
- const { host, port, path, protocol } = urlParts;
56
- return formatURL({
57
- protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
58
- hostname: host || location.hostname,
59
- port: port || location.port,
60
- pathname: path || HMR_SOCK_PATH
61
- });
62
- }
63
- // Annotate the CommonJS export names for ESM import in node:
64
- 0 && (module.exports = {
65
- HMR_SOCK_PATH,
66
- createSocketUrl,
67
- formatURL
68
- });
@@ -1,164 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (let key of __getOwnPropNames(from))
11
- if (!__hasOwnProp.call(to, key) && key !== except)
12
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- }
14
- return to;
15
- };
16
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
- // If the importer is in node compatibility mode or this is not an ESM
18
- // file that has been converted to a CommonJS file using a Babel-
19
- // compatible transform (i.e. "__esModule" has not been set), then set
20
- // "default" to the CommonJS "module.exports" for node compatibility.
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
- var import_strip_ansi = __toESM(require("strip-ansi"));
25
- var import_format_stats = require("@rsbuild/shared/format-stats");
26
- var import_createSocketUrl = require("./createSocketUrl");
27
- const hadRuntimeError = false;
28
- const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
29
- const connection = new WebSocket(socketUrl);
30
- connection.onopen = function() {
31
- if (typeof console !== "undefined" && typeof console.info === "function") {
32
- console.info("[HMR] connected.");
33
- }
34
- };
35
- connection.onclose = function() {
36
- if (typeof console !== "undefined" && typeof console.info === "function") {
37
- console.info("[HMR] disconnected. Refresh the page if necessary.");
38
- }
39
- };
40
- let isFirstCompilation = true;
41
- let mostRecentCompilationHash = null;
42
- let hasCompileErrors = false;
43
- function clearOutdatedErrors() {
44
- if (typeof console !== "undefined" && typeof console.clear === "function") {
45
- if (hasCompileErrors) {
46
- console.clear();
47
- }
48
- }
49
- }
50
- function handleSuccess() {
51
- clearOutdatedErrors();
52
- const isHotUpdate = !isFirstCompilation;
53
- isFirstCompilation = false;
54
- hasCompileErrors = false;
55
- if (isHotUpdate) {
56
- tryApplyUpdates();
57
- }
58
- }
59
- function handleWarnings(warnings) {
60
- clearOutdatedErrors();
61
- const isHotUpdate = !isFirstCompilation;
62
- isFirstCompilation = false;
63
- hasCompileErrors = false;
64
- function printWarnings() {
65
- const formatted = (0, import_format_stats.formatStatsMessages)({
66
- warnings,
67
- errors: []
68
- });
69
- if (typeof console !== "undefined" && typeof console.warn === "function") {
70
- for (let i = 0; i < formatted.warnings.length; i++) {
71
- if (i === 5) {
72
- console.warn(
73
- "There were more warnings in other files.\nYou can find a complete log in the terminal."
74
- );
75
- break;
76
- }
77
- console.warn((0, import_strip_ansi.default)(formatted.warnings[i]));
78
- }
79
- }
80
- }
81
- printWarnings();
82
- if (isHotUpdate) {
83
- tryApplyUpdates();
84
- }
85
- }
86
- function handleErrors(errors) {
87
- clearOutdatedErrors();
88
- isFirstCompilation = false;
89
- hasCompileErrors = true;
90
- const formatted = (0, import_format_stats.formatStatsMessages)({
91
- errors,
92
- warnings: []
93
- });
94
- if (typeof console !== "undefined" && typeof console.error === "function") {
95
- for (const error of formatted.errors) {
96
- console.error((0, import_strip_ansi.default)(error));
97
- }
98
- }
99
- }
100
- function handleAvailableHash(hash) {
101
- mostRecentCompilationHash = hash;
102
- }
103
- connection.onmessage = function(e) {
104
- const message = JSON.parse(e.data);
105
- switch (message.type) {
106
- case "hash":
107
- handleAvailableHash(message.data);
108
- break;
109
- case "still-ok":
110
- case "ok":
111
- handleSuccess();
112
- break;
113
- case "content-changed":
114
- window.location.reload();
115
- break;
116
- case "warnings":
117
- handleWarnings(message.data);
118
- break;
119
- case "errors":
120
- handleErrors(message.data);
121
- break;
122
- default:
123
- }
124
- };
125
- function isUpdateAvailable() {
126
- return mostRecentCompilationHash !== __webpack_hash__;
127
- }
128
- function canApplyUpdates() {
129
- return module.hot.status() === "idle";
130
- }
131
- function tryApplyUpdates() {
132
- if (!module.hot) {
133
- window.location.reload();
134
- return;
135
- }
136
- if (!isUpdateAvailable() || !canApplyUpdates()) {
137
- return;
138
- }
139
- function handleApplyUpdates(err, updatedModules) {
140
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
141
- if (wantsForcedReload) {
142
- window.location.reload();
143
- return;
144
- }
145
- if (isUpdateAvailable()) {
146
- tryApplyUpdates();
147
- }
148
- }
149
- const result = module.hot.check(
150
- /* autoApply */
151
- true,
152
- handleApplyUpdates
153
- );
154
- if (result == null ? void 0 : result.then) {
155
- result.then(
156
- (updatedModules) => {
157
- handleApplyUpdates(null, updatedModules);
158
- },
159
- (err) => {
160
- handleApplyUpdates(err, null);
161
- }
162
- );
163
- }
164
- }