@modern-js/server 2.0.0-beta.2 → 2.0.0-beta.4

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 (62) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/dist/js/modern/constants.js +10 -9
  3. package/dist/js/modern/dev-tools/dev-middleware/dev-server-plugin.js +14 -20
  4. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +14 -19
  5. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/index.js +134 -184
  6. package/dist/js/modern/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
  7. package/dist/js/modern/dev-tools/dev-middleware/index.js +65 -60
  8. package/dist/js/modern/dev-tools/dev-middleware/socket-server.js +33 -59
  9. package/dist/js/modern/dev-tools/https/global.d.js +0 -0
  10. package/dist/js/modern/dev-tools/https/index.js +28 -5
  11. package/dist/js/modern/dev-tools/mock/getMockData.js +71 -45
  12. package/dist/js/modern/dev-tools/mock/index.js +34 -15
  13. package/dist/js/modern/dev-tools/register/index.js +71 -55
  14. package/dist/js/modern/dev-tools/watcher/dependency-tree.js +25 -34
  15. package/dist/js/modern/dev-tools/watcher/index.js +51 -33
  16. package/dist/js/modern/dev-tools/watcher/stats-cache.js +13 -20
  17. package/dist/js/modern/index.js +7 -4
  18. package/dist/js/modern/server/dev-server.js +194 -216
  19. package/dist/js/modern/server/index.js +7 -4
  20. package/dist/js/node/constants.js +27 -14
  21. package/dist/js/node/dev-tools/dev-middleware/dev-server-plugin.js +36 -24
  22. package/dist/js/node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +31 -24
  23. package/dist/js/node/dev-tools/dev-middleware/hmr-client/index.js +56 -98
  24. package/dist/js/node/dev-tools/dev-middleware/hmr-client/types.d.js +0 -0
  25. package/dist/js/node/dev-tools/dev-middleware/index.js +94 -72
  26. package/dist/js/node/dev-tools/dev-middleware/socket-server.js +57 -66
  27. package/dist/js/node/dev-tools/https/global.d.js +0 -0
  28. package/dist/js/node/dev-tools/https/index.js +52 -13
  29. package/dist/js/node/dev-tools/mock/getMockData.js +88 -51
  30. package/dist/js/node/dev-tools/mock/index.js +62 -28
  31. package/dist/js/node/dev-tools/register/index.js +98 -65
  32. package/dist/js/node/dev-tools/watcher/dependency-tree.js +50 -43
  33. package/dist/js/node/dev-tools/watcher/index.js +79 -47
  34. package/dist/js/node/dev-tools/watcher/stats-cache.js +40 -30
  35. package/dist/js/node/index.js +25 -15
  36. package/dist/js/node/server/dev-server.js +235 -236
  37. package/dist/js/node/server/index.js +26 -11
  38. package/dist/js/treeshaking/constants.js +21 -0
  39. package/dist/js/treeshaking/dev-tools/dev-middleware/dev-server-plugin.js +74 -0
  40. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +51 -0
  41. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/index.js +157 -0
  42. package/dist/js/treeshaking/dev-tools/dev-middleware/hmr-client/types.d.js +1 -0
  43. package/dist/js/treeshaking/dev-tools/dev-middleware/index.js +363 -0
  44. package/dist/js/treeshaking/dev-tools/dev-middleware/socket-server.js +209 -0
  45. package/dist/js/treeshaking/dev-tools/https/global.d.js +1 -0
  46. package/dist/js/treeshaking/dev-tools/https/index.js +161 -0
  47. package/dist/js/treeshaking/dev-tools/mock/getMockData.js +327 -0
  48. package/dist/js/treeshaking/dev-tools/mock/index.js +191 -0
  49. package/dist/js/treeshaking/dev-tools/register/index.js +153 -0
  50. package/dist/js/treeshaking/dev-tools/watcher/dependency-tree.js +150 -0
  51. package/dist/js/treeshaking/dev-tools/watcher/index.js +200 -0
  52. package/dist/js/treeshaking/dev-tools/watcher/stats-cache.js +128 -0
  53. package/dist/js/treeshaking/index.js +9 -0
  54. package/dist/js/treeshaking/server/dev-server.js +800 -0
  55. package/dist/js/treeshaking/server/index.js +92 -0
  56. package/dist/js/treeshaking/types.js +1 -0
  57. package/dist/types/dev-tools/mock/getMockData.d.ts +2 -0
  58. package/dist/types/dev-tools/watcher/dependency-tree.d.ts +2 -0
  59. package/dist/types/dev-tools/watcher/index.d.ts +1 -17
  60. package/dist/types/index.d.ts +2 -0
  61. package/package.json +19 -16
  62. package/temp-fix-hmr.js +483 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,153 @@
1
1
  # @modern-js/server
2
2
 
3
+ ## 2.0.0-beta.4
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - b710adb843: feat: extract the data loader
12
+ feat: 提取 data loader
13
+
14
+ ### Patch Changes
15
+
16
+ - 7879e8f: refactor: remove enableModernMode config
17
+
18
+ refactor: 不再支持 enableModernMode 配置项
19
+
20
+ - d4e8e6fb90: fix: modernjs dev server can't start normaly
21
+ fix: modernjs dev 服务端不能正常启动
22
+ - 15bf09d9c8: feat: support completely custom server, export render() api for render single page
23
+ feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
24
+ - 61f21d1e77: fix: ignore the entire distPath for pia ssr bundle
25
+ fix: dist 目录的产物不应该被 ts-node 编译
26
+ - 4f277fe: fix(server): remove peer dependencies warning
27
+
28
+ fix(server): 修复 peer dependencies 出现 warning 提示的问题
29
+
30
+ - cce8ecee2d: fix: handle some `TODO` & `FIXME`, change some tests
31
+ fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
32
+ - ea7cf06: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
33
+
34
+ chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
35
+
36
+ - ebbeed1ece: chore: dev server default cross origin
37
+ chore: 开发环境 Server 默认跨域
38
+ - 14b712da84: fix: use consistent alias type and default value across packages
39
+
40
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
41
+
42
+ - Updated dependencies [9b915e0c10]
43
+ - Updated dependencies [7879e8f]
44
+ - Updated dependencies [c9e800d39a]
45
+ - Updated dependencies [d4e8e6fb90]
46
+ - Updated dependencies [d032d49e09]
47
+ - Updated dependencies [6aca875]
48
+ - Updated dependencies [15bf09d9c8]
49
+ - Updated dependencies [2e6031955e]
50
+ - Updated dependencies [7b7d12c]
51
+ - Updated dependencies [92f0eade39]
52
+ - Updated dependencies [edd1cfb1af]
53
+ - Updated dependencies [cc971eabfc]
54
+ - Updated dependencies [5b9049f2e9]
55
+ - Updated dependencies [6bda14ed71]
56
+ - Updated dependencies [a8642da58f]
57
+ - Updated dependencies [92004d1906]
58
+ - Updated dependencies [b8bbe036c7]
59
+ - Updated dependencies [40ed5874c6]
60
+ - Updated dependencies [87c1ff86b9]
61
+ - Updated dependencies [c2bb0f1745]
62
+ - Updated dependencies [d5a31df781]
63
+ - Updated dependencies [dda38c9c3e]
64
+ - Updated dependencies [102d32e4ba]
65
+ - Updated dependencies [8b8e1bb571]
66
+ - Updated dependencies [3bbea92b2a]
67
+ - Updated dependencies [73cd29dd9f]
68
+ - Updated dependencies [b710adb843]
69
+ - Updated dependencies [cce8ecee2d]
70
+ - Updated dependencies [18aaf42249]
71
+ - Updated dependencies [ea7cf06]
72
+ - Updated dependencies [bbe4c4a]
73
+ - Updated dependencies [e4558a0]
74
+ - Updated dependencies [abf3421a75]
75
+ - Updated dependencies [543be9558e]
76
+ - Updated dependencies [14b712da84]
77
+ - @modern-js/server-utils@2.0.0-beta.4
78
+ - @modern-js/prod-server@2.0.0-beta.4
79
+ - @modern-js/types@2.0.0-beta.4
80
+ - @modern-js/utils@2.0.0-beta.4
81
+
82
+ ## 2.0.0-beta.3
83
+
84
+ ### Major Changes
85
+
86
+ - dda38c9c3e: chore: v2
87
+
88
+ ### Minor Changes
89
+
90
+ - b710adb: feat: extract the data loader
91
+ feat: 提取 data loader
92
+
93
+ ### Patch Changes
94
+
95
+ - d4e8e6f: fix: modernjs dev server can't start normaly
96
+ fix: modernjs dev 服务端不能正常启动
97
+ - 15bf09d9c8: feat: support completely custom server, export render() api for render single page
98
+ feat: 支持完全自定义 Server,导出 render() 方法用来渲染单个页面
99
+ - 61f21d1e77: fix: ignore the entire distPath for pia ssr bundle
100
+ fix: dist 目录的产物不应该被 ts-node 编译
101
+ - cce8ece: fix: handle some `TODO` & `FIXME`, change some tests
102
+ fix: 处理一些 `TODO` 和 `FIXME`, 修改了一些 tests
103
+ - ea7cf06: chore: bump webpack/babel-loader/postcss-loader/tsconfig-paths
104
+
105
+ chore: 升级 webpack/babel-loader/postcss-loader/tsconfig-paths 版本
106
+
107
+ - ebbeed1ece: chore: dev server default cross origin
108
+ chore: 开发环境 Server 默认跨域
109
+ - 14b712da84: fix: use consistent alias type and default value across packages
110
+
111
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
112
+
113
+ - Updated dependencies [9b915e0c10]
114
+ - Updated dependencies [c9e800d39a]
115
+ - Updated dependencies [d4e8e6f]
116
+ - Updated dependencies [d032d49e09]
117
+ - Updated dependencies [6aca875]
118
+ - Updated dependencies [15bf09d9c8]
119
+ - Updated dependencies [2e60319]
120
+ - Updated dependencies [92f0eade39]
121
+ - Updated dependencies [edd1cfb1af]
122
+ - Updated dependencies [cc971eabfc]
123
+ - Updated dependencies [5b9049f2e9]
124
+ - Updated dependencies [6bda14ed71]
125
+ - Updated dependencies [a8642da58f]
126
+ - Updated dependencies [92004d1906]
127
+ - Updated dependencies [b8bbe036c7]
128
+ - Updated dependencies [40ed5874c6]
129
+ - Updated dependencies [87c1ff86b9]
130
+ - Updated dependencies [c2bb0f1]
131
+ - Updated dependencies [d5a31df781]
132
+ - Updated dependencies [dda38c9c3e]
133
+ - Updated dependencies [102d32e4ba]
134
+ - Updated dependencies [8b8e1bb571]
135
+ - Updated dependencies [3bbea92b2a]
136
+ - Updated dependencies [73cd29dd9f]
137
+ - Updated dependencies [b710adb]
138
+ - Updated dependencies [cce8ece]
139
+ - Updated dependencies [18aaf42249]
140
+ - Updated dependencies [ea7cf06]
141
+ - Updated dependencies [bbe4c4a]
142
+ - Updated dependencies [e4558a0]
143
+ - Updated dependencies [abf3421a75]
144
+ - Updated dependencies [543be9558e]
145
+ - Updated dependencies [14b712da84]
146
+ - @modern-js/server-utils@2.0.0-beta.3
147
+ - @modern-js/prod-server@2.0.0-beta.3
148
+ - @modern-js/utils@2.0.0-beta.3
149
+ - @modern-js/types@2.0.0-beta.3
150
+
3
151
  ## 2.0.0-beta.2
4
152
 
5
153
  ### Major Changes
@@ -1,18 +1,19 @@
1
- import { getIpv4Interfaces, HMR_SOCK_PATH } from '@modern-js/utils';
2
- export const getDefaultDevOptions = () => {
3
- const network = getIpv4Interfaces().find(item => !item.internal);
1
+ import { getIpv4Interfaces, HMR_SOCK_PATH } from "@modern-js/utils";
2
+ const getDefaultDevOptions = () => {
3
+ const network = getIpv4Interfaces().find((item) => !item.internal);
4
4
  return {
5
5
  client: {
6
- port: '8080',
6
+ port: "8080",
7
7
  path: HMR_SOCK_PATH,
8
- host: (network === null || network === void 0 ? void 0 : network.address) || 'localhost'
8
+ host: (network == null ? void 0 : network.address) || "localhost"
9
9
  },
10
10
  https: false,
11
- devMiddleware: {
12
- writeToDisk: true
13
- },
11
+ devMiddleware: { writeToDisk: true },
14
12
  watch: true,
15
13
  hot: true,
16
14
  liveReload: true
17
15
  };
18
- };
16
+ };
17
+ export {
18
+ getDefaultDevOptions
19
+ };
@@ -1,38 +1,32 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- export default class DevServerPlugin {
1
+ class DevServerPlugin {
3
2
  constructor(options) {
4
- _defineProperty(this, "options", void 0);
5
3
  this.options = options;
6
4
  }
7
5
  injectHMRClient(compiler) {
8
- const {
9
- client
10
- } = this.options;
11
- const host = client !== null && client !== void 0 && client.host ? `&host=${client.host}` : '';
12
- const path = client !== null && client !== void 0 && client.path ? `&path=${client.path}` : '';
13
- const port = client !== null && client !== void 0 && client.port ? `&port=${client.port}` : '';
6
+ const { client } = this.options;
7
+ const host = (client == null ? void 0 : client.host) ? `&host=${client.host}` : "";
8
+ const path = (client == null ? void 0 : client.path) ? `&path=${client.path}` : "";
9
+ const port = (client == null ? void 0 : client.port) ? `&port=${client.port}` : "";
14
10
  const clientEntry = `${require.resolve("./hmr-client")}?${host}${path}${port}`;
15
-
16
- // use a hook to add entries if available
17
11
  new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
18
- name: undefined
12
+ name: void 0
19
13
  }).apply(compiler);
20
14
  }
21
15
  apply(compiler) {
22
16
  if (this.options.hot || this.options.liveReload) {
23
17
  this.injectHMRClient(compiler);
24
18
  }
25
-
26
- // Todo remove, client must inject.
27
19
  const compilerOptions = compiler.options;
28
- const {
29
- HotModuleReplacementPlugin
30
- } = compiler.webpack;
20
+ const { HotModuleReplacementPlugin } = compiler.webpack;
31
21
  compilerOptions.plugins = compilerOptions.plugins || [];
32
- if (!compilerOptions.plugins.find(p => p.constructor === HotModuleReplacementPlugin)) {
33
- // apply the HMR plugin, if it didn't exist before.
22
+ if (!compilerOptions.plugins.find(
23
+ (p) => p.constructor === HotModuleReplacementPlugin
24
+ )) {
34
25
  const plugin = new HotModuleReplacementPlugin();
35
26
  plugin.apply(compiler);
36
27
  }
37
28
  }
38
- }
29
+ }
30
+ export {
31
+ DevServerPlugin as default
32
+ };
@@ -1,46 +1,41 @@
1
- import { HMR_SOCK_PATH } from '@modern-js/utils/constants';
2
- export function createSocketUrl(resourceQuery) {
3
- // ?host=localhost&port=8080&path=modern_js_hmr_ws
4
- const searchParams = resourceQuery.substr(1).split('&');
1
+ import { HMR_SOCK_PATH } from "@modern-js/utils/constants";
2
+ function createSocketUrl(resourceQuery) {
3
+ const searchParams = resourceQuery.substr(1).split("&");
5
4
  const options = {};
6
5
  for (const pair of searchParams) {
7
- const ary = pair.split('=');
6
+ const ary = pair.split("=");
8
7
  options[ary[0]] = decodeURIComponent(ary[1]);
9
8
  }
10
9
  const currentLocation = self.location;
11
10
  return getSocketUrl(options, currentLocation);
12
11
  }
13
- export function formatURL({
12
+ function formatURL({
14
13
  port,
15
14
  protocol,
16
15
  hostname,
17
16
  pathname
18
17
  }) {
19
18
  if (window.URL) {
20
- // eslint-disable-next-line node/prefer-global/url, node/no-unsupported-features/node-builtins
21
- const url = new URL('http://localhost');
19
+ const url = new URL("http://localhost");
22
20
  url.port = port;
23
21
  url.hostname = hostname;
24
22
  url.protocol = protocol;
25
23
  url.pathname = pathname;
26
24
  return url.toString();
27
25
  }
28
-
29
- // compatible with IE11
30
- const colon = protocol.indexOf(':') === -1 ? ':' : '';
26
+ const colon = protocol.indexOf(":") === -1 ? ":" : "";
31
27
  return `${protocol}${colon}//${hostname}:${port}${pathname}`;
32
28
  }
33
29
  function getSocketUrl(urlParts, location) {
34
- const {
35
- host,
36
- port,
37
- path,
38
- protocol
39
- } = urlParts;
30
+ const { host, port, path, protocol } = urlParts;
40
31
  return formatURL({
41
- protocol: protocol || location.protocol === 'https:' ? 'wss' : 'ws',
32
+ protocol: protocol || location.protocol === "https:" ? "wss" : "ws",
42
33
  hostname: host || location.hostname,
43
34
  port: port || location.port,
44
35
  pathname: path || HMR_SOCK_PATH
45
36
  });
46
- }
37
+ }
38
+ export {
39
+ createSocketUrl,
40
+ formatURL
41
+ };
@@ -1,193 +1,143 @@
1
- /**
2
- * This has been adapted from `create-react-app`, authored by Facebook, Inc.
3
- * see: https://github.com/facebookincubator/create-react-app/tree/master/packages/react-dev-utils
4
- *
5
- * Tips: this package will be bundled and running in the browser, do not import from the entry of @modern-js/utils.
6
- */
7
- import stripAnsi from '@modern-js/utils/strip-ansi';
8
- import { formatWebpackMessages } from '@modern-js/utils/format';
9
- import { createSocketUrl } from "./createSocketUrl";
10
-
11
- // declare any to fix the type of `module.hot`
12
-
13
- // TODO hadRuntimeError should be fixed.
14
- // We need to keep track of if there has been a runtime error.
15
- // Essentially, we cannot guarantee application state was not corrupted by the
16
- // runtime error. To prevent confusing behavior, we forcibly reload the entire
17
- // application. This is handled below when we are notified of a compile (code
18
- // change).
19
- // See https://github.com/facebook/create-react-app/issues/3096
20
- const hadRuntimeError = false;
21
-
22
- // Connect to Dev Server
23
- const socketUrl = createSocketUrl(__resourceQuery);
24
- const connection = new WebSocket(socketUrl);
25
-
26
- // Unlike WebpackDevServer client, we won't try to reconnect
27
- // to avoid spamming the console. Disconnect usually happens
28
- // when developer stops the server.
29
- connection.onclose = function () {
30
- if (typeof console !== 'undefined' && typeof console.info === 'function') {
31
- console.info('The development server has disconnected.\nRefresh the page if necessary.');
32
- }
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
33
4
  };
34
-
35
- // Remember some state related to hot module replacement.
36
- let isFirstCompilation = true;
37
- let mostRecentCompilationHash = null;
38
- let hasCompileErrors = false;
39
- function clearOutdatedErrors() {
40
- // Clean up outdated compile errors, if any.
41
- // eslint-disable-next-line node/no-unsupported-features/node-builtins, no-console
42
- if (typeof console !== 'undefined' && typeof console.clear === 'function') {
43
- if (hasCompileErrors) {
44
- // eslint-disable-next-line node/no-unsupported-features/node-builtins, no-console
45
- console.clear();
5
+ import stripAnsi from "@modern-js/utils/strip-ansi";
6
+ import { formatWebpackMessages } from "@modern-js/utils/format";
7
+ import { createSocketUrl } from "./createSocketUrl";
8
+ var require_hmr_client = __commonJS({
9
+ "src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
10
+ const hadRuntimeError = false;
11
+ const socketUrl = createSocketUrl(__resourceQuery);
12
+ const connection = new WebSocket(socketUrl);
13
+ connection.onclose = function() {
14
+ if (typeof console !== "undefined" && typeof console.info === "function") {
15
+ console.info(
16
+ "The development server has disconnected. Refresh the page if necessary."
17
+ );
18
+ }
19
+ };
20
+ let isFirstCompilation = true;
21
+ let mostRecentCompilationHash = null;
22
+ let hasCompileErrors = false;
23
+ function clearOutdatedErrors() {
24
+ if (typeof console !== "undefined" && typeof console.clear === "function") {
25
+ if (hasCompileErrors) {
26
+ console.clear();
27
+ }
28
+ }
46
29
  }
47
- }
48
- }
49
-
50
- // Successful compilation.
51
- function handleSuccess() {
52
- clearOutdatedErrors();
53
- const isHotUpdate = !isFirstCompilation;
54
- isFirstCompilation = false;
55
- hasCompileErrors = false;
56
-
57
- // Attempt to apply hot updates or reload.
58
- if (isHotUpdate) {
59
- tryApplyUpdates();
60
- }
61
- }
62
-
63
- // Compilation with warnings (e.g. ESLint).
64
- function handleWarnings(warnings) {
65
- clearOutdatedErrors();
66
- const isHotUpdate = !isFirstCompilation;
67
- isFirstCompilation = false;
68
- hasCompileErrors = false;
69
- function printWarnings() {
70
- // Print warnings to the console.
71
- const formatted = formatWebpackMessages({
72
- warnings,
73
- errors: []
74
- });
75
- if (typeof console !== 'undefined' && typeof console.warn === 'function') {
76
- for (let i = 0; i < formatted.warnings.length; i++) {
77
- if (i === 5) {
78
- console.warn('There were more warnings in other files.\n' + 'You can find a complete log in the terminal.');
79
- break;
30
+ function handleSuccess() {
31
+ clearOutdatedErrors();
32
+ const isHotUpdate = !isFirstCompilation;
33
+ isFirstCompilation = false;
34
+ hasCompileErrors = false;
35
+ if (isHotUpdate) {
36
+ tryApplyUpdates();
37
+ }
38
+ }
39
+ function handleWarnings(warnings) {
40
+ clearOutdatedErrors();
41
+ const isHotUpdate = !isFirstCompilation;
42
+ isFirstCompilation = false;
43
+ hasCompileErrors = false;
44
+ function printWarnings() {
45
+ const formatted = formatWebpackMessages({
46
+ warnings,
47
+ errors: []
48
+ });
49
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
50
+ for (let i = 0; i < formatted.warnings.length; i++) {
51
+ if (i === 5) {
52
+ console.warn(
53
+ "There were more warnings in other files. You can find a complete log in the terminal."
54
+ );
55
+ break;
56
+ }
57
+ console.warn(stripAnsi(formatted.warnings[i]));
58
+ }
80
59
  }
81
- console.warn(stripAnsi(formatted.warnings[i]));
60
+ }
61
+ printWarnings();
62
+ if (isHotUpdate) {
63
+ tryApplyUpdates();
82
64
  }
83
65
  }
84
- }
85
- printWarnings();
86
-
87
- // Attempt to apply hot updates or reload.
88
- if (isHotUpdate) {
89
- tryApplyUpdates();
90
- }
91
- }
92
-
93
- // Compilation with errors (e.g. syntax error or missing modules).
94
- function handleErrors(errors) {
95
- clearOutdatedErrors();
96
- isFirstCompilation = false;
97
- hasCompileErrors = true;
98
-
99
- // "Massage" webpack messages.
100
- const formatted = formatWebpackMessages({
101
- errors,
102
- warnings: []
103
- });
104
-
105
- // Also log them to the console.
106
- if (typeof console !== 'undefined' && typeof console.error === 'function') {
107
- for (const error of formatted.errors) {
108
- console.error(stripAnsi(error));
66
+ function handleErrors(errors) {
67
+ clearOutdatedErrors();
68
+ isFirstCompilation = false;
69
+ hasCompileErrors = true;
70
+ const formatted = formatWebpackMessages({
71
+ errors,
72
+ warnings: []
73
+ });
74
+ if (typeof console !== "undefined" && typeof console.error === "function") {
75
+ for (const error of formatted.errors) {
76
+ console.error(stripAnsi(error));
77
+ }
78
+ }
109
79
  }
110
- }
111
-
112
- // Do not attempt to reload now.
113
- // We will reload on next success instead.
114
- }
115
-
116
- // There is a newer version of the code available.
117
- function handleAvailableHash(hash) {
118
- // Update last known compilation hash.
119
- mostRecentCompilationHash = hash;
120
- }
121
-
122
- // Handle messages from the server.
123
- connection.onmessage = function (e) {
124
- const message = JSON.parse(e.data);
125
- switch (message.type) {
126
- case 'hash':
127
- handleAvailableHash(message.data);
128
- break;
129
- case 'still-ok':
130
- case 'ok':
131
- handleSuccess();
132
- break;
133
- case 'content-changed':
134
- // Triggered when a file from `contentBase` changed.
135
- window.location.reload();
136
- break;
137
- case 'warnings':
138
- handleWarnings(message.data);
139
- break;
140
- case 'errors':
141
- handleErrors(message.data);
142
- break;
143
- default:
144
- // Do nothing.
145
- }
146
- };
147
-
148
- // Is there a newer version of this code available?
149
- function isUpdateAvailable() {
150
- // __webpack_hash__ is the hash of the current compilation.
151
- // It's a global variable injected by webpack.
152
- return mostRecentCompilationHash !== __webpack_hash__;
153
- }
154
-
155
- // webpack disallows updates in other states.
156
- function canApplyUpdates() {
157
- return module.hot.status() === 'idle';
158
- }
159
-
160
- // Attempt to update code on the fly, fall back to a hard reload.
161
- function tryApplyUpdates() {
162
- if (!module.hot) {
163
- // HotModuleReplacementPlugin is not in webpack configuration.
164
- window.location.reload();
165
- return;
166
- }
167
- if (!isUpdateAvailable() || !canApplyUpdates()) {
168
- return;
169
- }
170
- function handleApplyUpdates(err, updatedModules) {
171
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
172
- if (wantsForcedReload) {
173
- window.location.reload();
174
- return;
80
+ function handleAvailableHash(hash) {
81
+ mostRecentCompilationHash = hash;
82
+ }
83
+ connection.onmessage = function(e) {
84
+ const message = JSON.parse(e.data);
85
+ switch (message.type) {
86
+ case "hash":
87
+ handleAvailableHash(message.data);
88
+ break;
89
+ case "still-ok":
90
+ case "ok":
91
+ handleSuccess();
92
+ break;
93
+ case "content-changed":
94
+ window.location.reload();
95
+ break;
96
+ case "warnings":
97
+ handleWarnings(message.data);
98
+ break;
99
+ case "errors":
100
+ handleErrors(message.data);
101
+ break;
102
+ default:
103
+ }
104
+ };
105
+ function isUpdateAvailable() {
106
+ return mostRecentCompilationHash !== __webpack_hash__;
175
107
  }
176
- if (isUpdateAvailable()) {
177
- // While we were updating, there was a new update! Do it again.
178
- tryApplyUpdates();
108
+ function canApplyUpdates() {
109
+ return module.hot.status() === "idle";
110
+ }
111
+ function tryApplyUpdates() {
112
+ if (!module.hot) {
113
+ window.location.reload();
114
+ return;
115
+ }
116
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
117
+ return;
118
+ }
119
+ function handleApplyUpdates(err, updatedModules) {
120
+ const wantsForcedReload = err || !updatedModules || hadRuntimeError;
121
+ if (wantsForcedReload) {
122
+ window.location.reload();
123
+ return;
124
+ }
125
+ if (isUpdateAvailable()) {
126
+ tryApplyUpdates();
127
+ }
128
+ }
129
+ const result = module.hot.check(true, handleApplyUpdates);
130
+ if (result == null ? void 0 : result.then) {
131
+ result.then(
132
+ (updatedModules) => {
133
+ handleApplyUpdates(null, updatedModules);
134
+ },
135
+ (err) => {
136
+ handleApplyUpdates(err, null);
137
+ }
138
+ );
139
+ }
179
140
  }
180
141
  }
181
-
182
- // https://webpack.github.io/docs/hot-module-replacement.html#check
183
- const result = module.hot.check( /* autoApply */true, handleApplyUpdates);
184
-
185
- // // webpack 2 returns a Promise instead of invoking a callback
186
- if (result !== null && result !== void 0 && result.then) {
187
- result.then(updatedModules => {
188
- handleApplyUpdates(null, updatedModules);
189
- }, err => {
190
- handleApplyUpdates(err, null);
191
- });
192
- }
193
- }
142
+ });
143
+ export default require_hmr_client();