@umijs/bundler-webpack 4.0.0-rc.8 → 4.0.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 (84) hide show
  1. package/client/client/client.js +65 -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/css-minimizer-webpack-plugin/index.js +7 -7
  7. package/compiled/cssnano/index.js +6 -6
  8. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  9. package/compiled/{tapable → react-refresh}/LICENSE +6 -6
  10. package/compiled/react-refresh/index.js +9 -7
  11. package/compiled/react-refresh/package.json +1 -0
  12. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  13. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  14. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  15. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  16. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  17. package/compiled/webpack/RuleSetCompiler.js +1 -0
  18. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  19. package/compiled/webpack/deepImports.json +6 -1
  20. package/compiled/webpack/index.js +3978 -3167
  21. package/compiled/webpack/types.d.ts +606 -171
  22. package/compiled/webpack-dev-middleware/index.js +8 -7
  23. package/compiled/webpack-manifest-plugin/index.js +1 -1
  24. package/dist/build.d.ts +1 -0
  25. package/dist/build.js +49 -56
  26. package/dist/cli.js +6 -15
  27. package/dist/client/client.js +52 -50
  28. package/dist/config/_sampleFeature.js +6 -17
  29. package/dist/config/assetRules.js +44 -55
  30. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  31. package/dist/config/compressPlugin.js +89 -70
  32. package/dist/config/config.d.ts +2 -0
  33. package/dist/config/config.js +181 -179
  34. package/dist/config/copyPlugin.js +29 -40
  35. package/dist/config/cssRules.js +114 -83
  36. package/dist/config/definePlugin.js +11 -19
  37. package/dist/config/detectDeadCodePlugin.js +16 -21
  38. package/dist/config/fastRefreshPlugin.js +11 -22
  39. package/dist/config/forkTSCheckerPlugin.js +11 -22
  40. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  41. package/dist/config/ignorePlugin.js +10 -21
  42. package/dist/config/javaScriptRules.d.ts +1 -0
  43. package/dist/config/javaScriptRules.js +152 -135
  44. package/dist/config/manifestPlugin.d.ts +1 -1
  45. package/dist/config/manifestPlugin.js +10 -18
  46. package/dist/config/miniCSSExtractPlugin.js +15 -23
  47. package/dist/config/nodePolyfill.js +14 -20
  48. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  49. package/dist/config/nodePrefixPlugin.js +14 -0
  50. package/dist/config/progressPlugin.js +7 -18
  51. package/dist/config/purgecssWebpackPlugin.js +15 -26
  52. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  53. package/dist/config/ssrPlugin.d.ts +11 -0
  54. package/dist/config/ssrPlugin.js +66 -0
  55. package/dist/config/svgRules.js +44 -47
  56. package/dist/constants.d.ts +1 -0
  57. package/dist/constants.js +7 -1
  58. package/dist/dev.d.ts +4 -0
  59. package/dist/dev.js +115 -94
  60. package/dist/index.d.ts +3 -0
  61. package/dist/index.js +16 -0
  62. package/dist/loader/svgr.js +4 -13
  63. package/dist/loader/swc.js +9 -14
  64. package/dist/plugins/ProgressPlugin.js +3 -3
  65. package/dist/plugins/RuntimePublicPathPlugin.js +4 -1
  66. package/dist/schema.js +24 -8
  67. package/dist/server/server.d.ts +3 -1
  68. package/dist/server/server.js +165 -150
  69. package/dist/server/ws.d.ts +7 -2
  70. package/dist/swcPlugins/autoCSSModules.js +3 -1
  71. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  72. package/dist/swcPlugins/changeImportFromString.js +10 -0
  73. package/dist/swcPlugins/lockCoreJS.js +3 -2
  74. package/dist/types.d.ts +3 -0
  75. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  76. package/dist/utils/getEsBuildTarget.js +12 -0
  77. package/package.json +23 -21
  78. package/compiled/tapable/index.js +0 -1
  79. package/compiled/tapable/package.json +0 -1
  80. package/compiled/tapable/tapable.d.ts +0 -116
  81. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  82. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
  83. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
  84. package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
@@ -1,18 +1,42 @@
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 getHost() {
17
+ if (process.env.SOCKET_SERVER) {
18
+ return new URL(process.env.SOCKET_SERVER);
19
+ }
20
+ return location;
21
+ }
22
+ function getSocketUrl() {
23
+ let h = getHost();
24
+ const host = h.host;
25
+ const isHttps = h.protocol === 'https:';
26
+ return `${isHttps ? 'wss' : 'ws'}://${host}`;
27
+ }
28
+ function getPingUrl() {
29
+ const h = getHost();
30
+ return `${h.protocol}//${h.host}/__umi_ping`;
31
+ }
7
32
  let pingTimer = null;
8
- const host = location.host;
9
- const wsUrl = `ws://${host}`;
10
33
  let isFirstCompilation = true;
11
34
  let mostRecentCompilationHash = null;
12
35
  let hasCompileErrors = false;
13
36
  let hadRuntimeError = false;
14
- const socket = new WebSocket(wsUrl, 'webpack-hmr');
15
- socket.addEventListener('message', async ({ data }) => {
37
+ const pingUrl = getPingUrl();
38
+ const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
39
+ socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
16
40
  data = JSON.parse(data);
17
41
  if (data.type === 'connected') {
18
42
  console.log(`[webpack] connected.`);
@@ -23,26 +47,28 @@ socket.addEventListener('message', async ({ data }) => {
23
47
  else {
24
48
  handleMessage(data).catch(console.error);
25
49
  }
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));
50
+ }));
51
+ function waitForSuccessfulPing(ms = 1000) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ // eslint-disable-next-line no-constant-condition
54
+ while (true) {
55
+ try {
56
+ yield fetch(pingUrl);
57
+ break;
58
+ }
59
+ catch (e) {
60
+ yield new Promise((resolve) => setTimeout(resolve, ms));
61
+ }
36
62
  }
37
- }
63
+ });
38
64
  }
39
- socket.addEventListener('close', async () => {
65
+ socket.addEventListener('close', () => __awaiter(void 0, void 0, void 0, function* () {
40
66
  if (pingTimer)
41
67
  clearInterval(pingTimer);
42
68
  console.info('[webpack] Dev server disconnected. Polling for restart...');
43
- await waitForSuccessfulPing();
69
+ yield waitForSuccessfulPing();
44
70
  location.reload();
45
- });
71
+ }));
46
72
  ErrorOverlay.startReportingRuntimeErrors({
47
73
  onError: function () {
48
74
  hadRuntimeError = true;
@@ -180,23 +206,25 @@ function tryApplyUpdates(onHotUpdateSuccess) {
180
206
  handleApplyUpdates(err, null);
181
207
  });
182
208
  }
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
- }
209
+ function handleMessage(payload) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ // console.log('[payload]', payload);
212
+ switch (payload.type) {
213
+ case MESSAGE_TYPE.hash:
214
+ handleAvailableHash(payload.data);
215
+ break;
216
+ case MESSAGE_TYPE.stillOk:
217
+ case MESSAGE_TYPE.ok:
218
+ handleSuccess();
219
+ break;
220
+ case MESSAGE_TYPE.errors:
221
+ handleErrors(payload.data);
222
+ break;
223
+ case MESSAGE_TYPE.warnings:
224
+ handleWarnings(payload.data);
225
+ break;
226
+ default:
227
+ // Do nothing
228
+ }
229
+ });
202
230
  }
@@ -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
+ ];