@umijs/bundler-webpack 4.0.7 → 4.0.8

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 (64) hide show
  1. package/{dist → client}/client/client.d.ts +0 -0
  2. package/client/client/client.js +172 -192
  3. package/client/constants.d.ts +15 -0
  4. package/client/constants.js +28 -19
  5. package/client/utils/formatWebpackMessages.d.ts +12 -0
  6. package/client/utils/formatWebpackMessages.js +68 -86
  7. package/dist/build.d.ts +1 -1
  8. package/dist/build.js +105 -68
  9. package/dist/cli.js +77 -69
  10. package/dist/config/_sampleFeature.js +33 -9
  11. package/dist/config/assetRules.js +45 -36
  12. package/dist/config/bundleAnalyzerPlugin.js +39 -17
  13. package/dist/config/compressPlugin.js +113 -95
  14. package/dist/config/config.d.ts +1 -0
  15. package/dist/config/config.js +204 -215
  16. package/dist/config/copyPlugin.js +58 -40
  17. package/dist/config/cssRules.js +136 -131
  18. package/dist/config/definePlugin.js +71 -35
  19. package/dist/config/detectDeadCode.js +120 -108
  20. package/dist/config/detectDeadCodePlugin.js +78 -63
  21. package/dist/config/fastRefreshPlugin.js +39 -20
  22. package/dist/config/forkTSCheckerPlugin.js +38 -19
  23. package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
  24. package/dist/config/ignorePlugin.js +38 -14
  25. package/dist/config/javaScriptRules.js +146 -173
  26. package/dist/config/manifestPlugin.js +51 -15
  27. package/dist/config/miniCSSExtractPlugin.js +42 -22
  28. package/dist/config/nodePolyfill.js +65 -26
  29. package/dist/config/nodePrefixPlugin.js +36 -12
  30. package/dist/config/progressPlugin.js +37 -13
  31. package/dist/config/purgecssWebpackPlugin.js +41 -19
  32. package/dist/config/speedMeasureWebpackPlugin.js +41 -20
  33. package/dist/config/ssrPlugin.js +83 -63
  34. package/dist/config/svgRules.js +74 -46
  35. package/dist/constants.js +57 -22
  36. package/dist/dev.d.ts +1 -1
  37. package/dist/dev.js +170 -134
  38. package/dist/index.js +22 -20
  39. package/dist/loader/svgr.js +73 -54
  40. package/dist/loader/swc.js +110 -69
  41. package/dist/parcelCSS.js +31 -27
  42. package/dist/plugins/ProgressPlugin.js +66 -43
  43. package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
  44. package/dist/plugins/_SamplePlugin.js +39 -14
  45. package/dist/requireHook.js +37 -27
  46. package/dist/schema.js +119 -96
  47. package/dist/server/server.d.ts +0 -1
  48. package/dist/server/server.js +214 -184
  49. package/dist/server/ws.d.ts +0 -2
  50. package/dist/server/ws.js +63 -38
  51. package/dist/swcPlugins/autoCSSModules.js +50 -31
  52. package/dist/swcPlugins/changeImportFromString.js +31 -9
  53. package/dist/swcPlugins/lockCoreJS.js +44 -20
  54. package/dist/types.js +61 -30
  55. package/dist/utils/browsersList.js +31 -8
  56. package/dist/utils/depMatch.js +63 -39
  57. package/dist/utils/formatWebpackMessages.js +93 -91
  58. package/dist/utils/getEsBuildTarget.js +32 -10
  59. package/package.json +9 -11
  60. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +0 -21
  61. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  62. package/compiled/fork-ts-checker-webpack-plugin/index.js +0 -42
  63. package/compiled/fork-ts-checker-webpack-plugin/package.json +0 -1
  64. package/dist/client/client.js +0 -245
@@ -1 +0,0 @@
1
- {"name":"fork-ts-checker-webpack-plugin","author":"Piotr Oleś <piotrek.oles@gmail.com>","license":"MIT","types":"lib/index.d.ts"}
@@ -1,245 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const strip_ansi_1 = __importDefault(require("@umijs/utils/compiled/strip-ansi"));
30
- // @ts-ignore
31
- const ErrorOverlay = __importStar(require("react-error-overlay"));
32
- const constants_1 = require("../constants");
33
- const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
34
- console.log('[webpack] connecting...');
35
- function getHost() {
36
- if (process.env.SOCKET_SERVER) {
37
- return new URL(process.env.SOCKET_SERVER);
38
- }
39
- return location;
40
- }
41
- function getSocketUrl() {
42
- let h = getHost();
43
- const host = h.host;
44
- const isHttps = h.protocol === 'https:';
45
- return `${isHttps ? 'wss' : 'ws'}://${host}`;
46
- }
47
- function getPingUrl() {
48
- const h = getHost();
49
- return `${h.protocol}//${h.host}/__umi_ping`;
50
- }
51
- let pingTimer = null;
52
- let isFirstCompilation = true;
53
- let mostRecentCompilationHash = null;
54
- let hasCompileErrors = false;
55
- let hadRuntimeError = false;
56
- const pingUrl = getPingUrl();
57
- const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
58
- socket.addEventListener('message', async ({ data }) => {
59
- data = JSON.parse(data);
60
- if (data.type === 'connected') {
61
- console.log(`[webpack] connected.`);
62
- // proxy(nginx, docker) hmr ws maybe caused timeout,
63
- // so send ping package let ws keep alive.
64
- pingTimer = setInterval(() => socket.send('ping'), 30000);
65
- }
66
- else {
67
- handleMessage(data).catch(console.error);
68
- }
69
- });
70
- async function waitForSuccessfulPing(ms = 1000) {
71
- // eslint-disable-next-line no-constant-condition
72
- while (true) {
73
- try {
74
- await fetch(pingUrl);
75
- break;
76
- }
77
- catch (e) {
78
- await new Promise((resolve) => setTimeout(resolve, ms));
79
- }
80
- }
81
- }
82
- socket.addEventListener('close', async () => {
83
- if (pingTimer)
84
- clearInterval(pingTimer);
85
- console.info('[webpack] Dev server disconnected. Polling for restart...');
86
- await waitForSuccessfulPing();
87
- location.reload();
88
- });
89
- ErrorOverlay.startReportingRuntimeErrors({
90
- onError: function () {
91
- hadRuntimeError = true;
92
- },
93
- filename: '/static/js/bundle.js',
94
- });
95
- // @ts-ignore
96
- if (module.hot && typeof module.hot.dispose === 'function') {
97
- // @ts-ignore
98
- module.hot.dispose(function () {
99
- // TODO: why do we need this?
100
- ErrorOverlay.stopReportingRuntimeErrors();
101
- });
102
- }
103
- // There is a newer version of the code available.
104
- function handleAvailableHash(hash) {
105
- // Update last known compilation hash.
106
- mostRecentCompilationHash = hash;
107
- }
108
- function handleSuccess() {
109
- const isHotUpdate = !isFirstCompilation;
110
- isFirstCompilation = false;
111
- hasCompileErrors = false;
112
- // Attempt to apply hot updates or reload.
113
- if (isHotUpdate) {
114
- tryApplyUpdates(function onHotUpdateSuccess() {
115
- // Only dismiss it when we're sure it's a hot update.
116
- // Otherwise it would flicker right before the reload.
117
- tryDismissErrorOverlay();
118
- });
119
- }
120
- }
121
- function handleWarnings(warnings) {
122
- const isHotUpdate = !isFirstCompilation;
123
- isFirstCompilation = false;
124
- hasCompileErrors = false;
125
- const formatted = (0, formatWebpackMessages_1.formatWebpackMessages)({
126
- warnings,
127
- errors: [],
128
- });
129
- // print warnings
130
- if (typeof console !== 'undefined' && typeof console.warn === 'function') {
131
- for (let i = 0; i < formatted.warnings.length; i++) {
132
- if (i === 5) {
133
- console.warn('There were more warnings in other files.\n' +
134
- 'You can find a complete log in the terminal.');
135
- break;
136
- }
137
- console.warn((0, strip_ansi_1.default)(formatted.warnings[i]));
138
- }
139
- }
140
- // Attempt to apply hot updates or reload.
141
- if (isHotUpdate) {
142
- tryApplyUpdates(function onSuccessfulHotUpdate() {
143
- // Only dismiss it when we're sure it's a hot update.
144
- // Otherwise it would flicker right before the reload.
145
- tryDismissErrorOverlay();
146
- });
147
- }
148
- }
149
- function handleErrors(errors) {
150
- isFirstCompilation = false;
151
- hasCompileErrors = true;
152
- const formatted = (0, formatWebpackMessages_1.formatWebpackMessages)({
153
- warnings: [],
154
- errors,
155
- });
156
- // Only show the first error.
157
- ErrorOverlay.reportBuildError(formatted.errors[0]);
158
- // Also log them to the console.
159
- if (typeof console !== 'undefined' && typeof console.error === 'function') {
160
- for (let i = 0; i < formatted.errors.length; i++) {
161
- console.error((0, strip_ansi_1.default)(formatted.errors[i]));
162
- }
163
- }
164
- }
165
- function tryDismissErrorOverlay() {
166
- if (!hasCompileErrors) {
167
- ErrorOverlay.dismissBuildError();
168
- }
169
- }
170
- // Is there a newer version of this code available?
171
- function isUpdateAvailable() {
172
- // @ts-ignore
173
- return mostRecentCompilationHash !== __webpack_hash__;
174
- }
175
- function canApplyUpdates() {
176
- // @ts-ignore
177
- return module.hot.status() === 'idle';
178
- }
179
- function canAcceptErrors() {
180
- // NOTE: This var is injected by Webpack's DefinePlugin, and is a boolean instead of string.
181
- const hasReactRefresh = process.env.FAST_REFRESH;
182
- // @ts-ignore
183
- const status = module.hot.status();
184
- // React refresh can handle hot-reloading over errors.
185
- // However, when hot-reload status is abort or fail,
186
- // it indicates the current update cannot be applied safely,
187
- // and thus we should bail out to a forced reload for consistency.
188
- return hasReactRefresh && ['abort', 'fail'].indexOf(status) === -1;
189
- }
190
- function tryApplyUpdates(onHotUpdateSuccess) {
191
- // @ts-ignore
192
- if (!module.hot) {
193
- window.location.reload();
194
- return;
195
- }
196
- if (!isUpdateAvailable() || !canApplyUpdates()) {
197
- return;
198
- }
199
- function handleApplyUpdates(err, updatedModules) {
200
- const haveErrors = err || hadRuntimeError;
201
- // When there is no error but updatedModules is unavailable,
202
- // it indicates a critical failure in hot-reloading,
203
- // e.g. server is not ready to serve new bundle,
204
- // and hence we need to do a forced reload.
205
- const needsForcedReload = !err && !updatedModules;
206
- if ((haveErrors && !canAcceptErrors()) || needsForcedReload) {
207
- window.location.reload();
208
- }
209
- if (onHotUpdateSuccess)
210
- onHotUpdateSuccess();
211
- // While we were updating, there was a new update! Do it again.
212
- if (isUpdateAvailable()) {
213
- tryApplyUpdates();
214
- }
215
- }
216
- // @ts-ignore
217
- module.hot
218
- .check(/* autoApply */ true)
219
- .then((updatedModules) => {
220
- handleApplyUpdates(null, updatedModules);
221
- })
222
- .catch((err) => {
223
- handleApplyUpdates(err, null);
224
- });
225
- }
226
- async function handleMessage(payload) {
227
- // console.log('[payload]', payload);
228
- switch (payload.type) {
229
- case constants_1.MESSAGE_TYPE.hash:
230
- handleAvailableHash(payload.data);
231
- break;
232
- case constants_1.MESSAGE_TYPE.stillOk:
233
- case constants_1.MESSAGE_TYPE.ok:
234
- handleSuccess();
235
- break;
236
- case constants_1.MESSAGE_TYPE.errors:
237
- handleErrors(payload.data);
238
- break;
239
- case constants_1.MESSAGE_TYPE.warnings:
240
- handleWarnings(payload.data);
241
- break;
242
- default:
243
- // Do nothing
244
- }
245
- }