@umijs/bundler-webpack 4.0.0-canary.20220318.1 → 4.0.0-canary.20220412.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/client/client/client.js +57 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/babel-loader/index.js +2 -2
  4. package/compiled/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
  5. package/compiled/copy-webpack-plugin/index.js +12 -12
  6. package/compiled/cssnano/index.js +6 -6
  7. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  8. package/compiled/react-refresh/LICENSE +21 -0
  9. package/compiled/react-refresh/index.js +9 -7
  10. package/compiled/react-refresh/package.json +1 -0
  11. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  12. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  13. package/compiled/webpack/index.js +4430 -2883
  14. package/dist/client/client.js +10 -3
  15. package/dist/config/compressPlugin.js +9 -1
  16. package/dist/config/config.js +3 -0
  17. package/dist/config/nodePolyfill.js +1 -1
  18. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  19. package/dist/config/nodePrefixPlugin.js +25 -0
  20. package/dist/constants.d.ts +1 -0
  21. package/dist/constants.js +7 -1
  22. package/dist/dev.d.ts +2 -0
  23. package/dist/dev.js +12 -4
  24. package/dist/schema.js +4 -2
  25. package/dist/server/https.d.ts +5 -0
  26. package/dist/server/https.js +73 -0
  27. package/dist/server/server.d.ts +2 -1
  28. package/dist/server/server.js +43 -9
  29. package/dist/server/ws.d.ts +3 -2
  30. package/dist/swcPlugins/autoCSSModules.js +3 -1
  31. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  32. package/dist/swcPlugins/changeImportFromString.js +10 -0
  33. package/dist/swcPlugins/lockCoreJS.js +3 -2
  34. package/dist/types.d.ts +6 -0
  35. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  36. package/dist/utils/getEsBuildTarget.js +12 -0
  37. package/package.json +15 -13
@@ -1,18 +1,34 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import stripAnsi from '@umijs/utils/compiled/strip-ansi';
2
11
  // @ts-ignore
3
12
  import * as ErrorOverlay from 'react-error-overlay';
4
13
  import { MESSAGE_TYPE } from '../constants';
5
14
  import { formatWebpackMessages } from '../utils/formatWebpackMessages';
6
15
  console.log('[webpack] connecting...');
16
+ function getSocketHost() {
17
+ let l = location;
18
+ if (process.env.SOCKET_SERVER) {
19
+ l = new URL(process.env.SOCKET_SERVER);
20
+ }
21
+ const host = l.host;
22
+ const isHttps = l.protocol === 'https:';
23
+ return `${isHttps ? 'wss' : 'ws'}://${host}`;
24
+ }
7
25
  let pingTimer = null;
8
- const host = location.host;
9
- const wsUrl = `ws://${host}`;
10
26
  let isFirstCompilation = true;
11
27
  let mostRecentCompilationHash = null;
12
28
  let hasCompileErrors = false;
13
29
  let hadRuntimeError = false;
14
- const socket = new WebSocket(wsUrl, 'webpack-hmr');
15
- socket.addEventListener('message', async ({ data }) => {
30
+ const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
31
+ socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
16
32
  data = JSON.parse(data);
17
33
  if (data.type === 'connected') {
18
34
  console.log(`[webpack] connected.`);
@@ -23,26 +39,28 @@ socket.addEventListener('message', async ({ data }) => {
23
39
  else {
24
40
  handleMessage(data).catch(console.error);
25
41
  }
26
- });
27
- async function waitForSuccessfulPing(ms = 1000) {
28
- // eslint-disable-next-line no-constant-condition
29
- while (true) {
30
- try {
31
- await fetch(`/__umi_ping`);
32
- break;
33
- }
34
- catch (e) {
35
- await new Promise((resolve) => setTimeout(resolve, ms));
42
+ }));
43
+ function waitForSuccessfulPing(ms = 1000) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ // eslint-disable-next-line no-constant-condition
46
+ while (true) {
47
+ try {
48
+ yield fetch(`/__umi_ping`);
49
+ break;
50
+ }
51
+ catch (e) {
52
+ yield new Promise((resolve) => setTimeout(resolve, ms));
53
+ }
36
54
  }
37
- }
55
+ });
38
56
  }
39
- socket.addEventListener('close', async () => {
57
+ socket.addEventListener('close', () => __awaiter(void 0, void 0, void 0, function* () {
40
58
  if (pingTimer)
41
59
  clearInterval(pingTimer);
42
60
  console.info('[webpack] Dev server disconnected. Polling for restart...');
43
- await waitForSuccessfulPing();
61
+ yield waitForSuccessfulPing();
44
62
  location.reload();
45
- });
63
+ }));
46
64
  ErrorOverlay.startReportingRuntimeErrors({
47
65
  onError: function () {
48
66
  hadRuntimeError = true;
@@ -180,23 +198,25 @@ function tryApplyUpdates(onHotUpdateSuccess) {
180
198
  handleApplyUpdates(err, null);
181
199
  });
182
200
  }
183
- async function handleMessage(payload) {
184
- // console.log('[payload]', payload);
185
- switch (payload.type) {
186
- case MESSAGE_TYPE.hash:
187
- handleAvailableHash(payload.data);
188
- break;
189
- case MESSAGE_TYPE.stillOk:
190
- case MESSAGE_TYPE.ok:
191
- handleSuccess();
192
- break;
193
- case MESSAGE_TYPE.errors:
194
- handleErrors(payload.data);
195
- break;
196
- case MESSAGE_TYPE.warnings:
197
- handleWarnings(payload.data);
198
- break;
199
- default:
200
- // Do nothing
201
- }
201
+ function handleMessage(payload) {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ // console.log('[payload]', payload);
204
+ switch (payload.type) {
205
+ case MESSAGE_TYPE.hash:
206
+ handleAvailableHash(payload.data);
207
+ break;
208
+ case MESSAGE_TYPE.stillOk:
209
+ case MESSAGE_TYPE.ok:
210
+ handleSuccess();
211
+ break;
212
+ case MESSAGE_TYPE.errors:
213
+ handleErrors(payload.data);
214
+ break;
215
+ case MESSAGE_TYPE.warnings:
216
+ handleWarnings(payload.data);
217
+ break;
218
+ default:
219
+ // Do nothing
220
+ }
221
+ });
202
222
  }
@@ -10,3 +10,12 @@ export var MESSAGE_TYPE;
10
10
  MESSAGE_TYPE["stillOk"] = "still-ok";
11
11
  MESSAGE_TYPE["invalid"] = "invalid";
12
12
  })(MESSAGE_TYPE || (MESSAGE_TYPE = {}));
13
+ export const DEFAULT_BROWSER_TARGETS = {
14
+ chrome: 80,
15
+ };
16
+ export const DEFAULT_ESBUILD_TARGET_KEYS = [
17
+ 'chrome',
18
+ 'firefox',
19
+ 'edge',
20
+ 'safari',
21
+ ];