@umijs/bundler-webpack 4.0.0-beta.7 → 4.0.0-canary.202200505.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 (197) hide show
  1. package/client/client/client.js +65 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/autoprefixer/browserslist/index.d.ts +13 -7
  4. package/compiled/autoprefixer/index.js +3 -3
  5. package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
  6. package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
  7. package/compiled/autoprefixer/postcss/lib/container.d.ts +2 -2
  8. package/compiled/autoprefixer/postcss/lib/css-syntax-error.d.ts +55 -8
  9. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
  10. package/compiled/autoprefixer/postcss/lib/input.d.ts +26 -6
  11. package/compiled/autoprefixer/postcss/lib/lazy-result.d.ts +11 -10
  12. package/compiled/autoprefixer/postcss/lib/no-work-result.d.ts +37 -0
  13. package/compiled/autoprefixer/postcss/lib/node.d.ts +38 -4
  14. package/compiled/autoprefixer/postcss/lib/postcss.d.ts +31 -30
  15. package/compiled/autoprefixer/postcss/lib/processor.d.ts +5 -4
  16. package/compiled/autoprefixer/postcss/lib/result.d.ts +3 -2
  17. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  18. package/compiled/autoprefixer/postcss/lib/warning.d.ts +37 -3
  19. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  20. package/compiled/babel-loader/index.js +2 -2
  21. package/compiled/copy-webpack-plugin/939.index.js +1171 -0
  22. package/compiled/copy-webpack-plugin/index.js +16 -10
  23. package/compiled/copy-webpack-plugin/package.json +1 -1
  24. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  25. package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
  26. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  27. package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
  28. package/compiled/cssnano/index.js +12 -11
  29. package/compiled/cssnano/package.json +1 -1
  30. package/compiled/express.d.ts +2 -0
  31. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +21 -0
  32. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  33. package/compiled/fork-ts-checker-webpack-plugin/index.js +42 -0
  34. package/compiled/fork-ts-checker-webpack-plugin/package.json +1 -0
  35. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  36. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  37. package/compiled/http-proxy-middleware/index.js +10 -10
  38. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  39. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  40. package/compiled/mini-css-extract-plugin/index.js +7970 -7445
  41. package/compiled/mini-css-extract-plugin/loader.js +179 -54
  42. package/compiled/mini-css-extract-plugin/package.json +1 -1
  43. package/compiled/mini-css-extract-plugin/utils.js +85 -24
  44. package/compiled/postcss-loader/index.js +1 -1
  45. package/compiled/react-refresh/LICENSE +21 -0
  46. package/compiled/react-refresh/index.js +9 -7
  47. package/compiled/react-refresh/package.json +1 -0
  48. package/compiled/sass-loader/index.js +1 -1
  49. package/compiled/schema-utils/ajv/dist/ajv.d.ts +16 -0
  50. package/compiled/schema-utils/ajv/dist/compile/codegen/code.d.ts +39 -0
  51. package/compiled/schema-utils/ajv/dist/compile/codegen/index.d.ts +79 -0
  52. package/compiled/schema-utils/ajv/dist/compile/codegen/scope.d.ts +79 -0
  53. package/compiled/schema-utils/ajv/dist/compile/errors.d.ts +13 -0
  54. package/compiled/schema-utils/ajv/dist/compile/index.d.ts +80 -0
  55. package/compiled/schema-utils/ajv/dist/compile/ref_error.d.ts +5 -0
  56. package/compiled/schema-utils/ajv/dist/compile/resolve.d.ts +12 -0
  57. package/compiled/schema-utils/ajv/dist/compile/rules.d.ts +28 -0
  58. package/compiled/schema-utils/ajv/dist/compile/util.d.ts +40 -0
  59. package/compiled/schema-utils/ajv/dist/compile/validate/index.d.ts +42 -0
  60. package/compiled/schema-utils/ajv/dist/compile/validate/subschema.d.ts +47 -0
  61. package/compiled/schema-utils/ajv/dist/core.d.ts +171 -0
  62. package/compiled/schema-utils/ajv/dist/runtime/validation_error.d.ts +7 -0
  63. package/compiled/schema-utils/ajv/dist/types/index.d.ts +177 -0
  64. package/compiled/schema-utils/ajv/dist/types/json-schema.d.ts +124 -0
  65. package/compiled/schema-utils/ajv/dist/types/jtd-schema.d.ts +168 -0
  66. package/compiled/schema-utils/declarations/validate.d.ts +4 -4
  67. package/compiled/schema-utils/index.js +8 -2
  68. package/compiled/schema-utils/uri-js/dist/es5/uri.all.d.ts +59 -0
  69. package/compiled/style-loader/index.js +1 -1
  70. package/compiled/terser/index.js +1 -1
  71. package/compiled/terser-webpack-plugin/index.js +393 -517
  72. package/compiled/terser-webpack-plugin/jest-worker/build/types.d.ts +1 -0
  73. package/compiled/terser-webpack-plugin/minify.js +10 -3
  74. package/compiled/terser-webpack-plugin/package.json +1 -1
  75. package/compiled/terser-webpack-plugin/types/index.d.ts +183 -149
  76. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  77. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -15
  78. package/compiled/terser-webpack-plugin/utils.js +118 -25
  79. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  80. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  81. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  82. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  83. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  84. package/compiled/webpack/RuleSetCompiler.js +1 -0
  85. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  86. package/compiled/webpack/deepImports.json +6 -1
  87. package/compiled/webpack/index.js +13409 -5746
  88. package/compiled/webpack/types.d.ts +606 -171
  89. package/compiled/webpack-dev-middleware/index.js +11 -5
  90. package/compiled/webpack-dev-middleware/package.json +1 -1
  91. package/compiled/{tapable → webpack-manifest-plugin}/LICENSE +2 -2
  92. package/compiled/webpack-manifest-plugin/index.js +1 -0
  93. package/compiled/webpack-manifest-plugin/package.json +1 -0
  94. package/compiled/webpack-sources/index.js +1 -1
  95. package/compiled/ws/index.d.ts +1 -2
  96. package/compiled/ws/index.js +1 -1
  97. package/dist/build.d.ts +6 -3
  98. package/dist/build.js +48 -56
  99. package/dist/cli.js +10 -22
  100. package/dist/client/client.js +57 -51
  101. package/dist/config/_sampleFeature.js +6 -17
  102. package/dist/config/assetRules.js +44 -51
  103. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  104. package/dist/config/compressPlugin.js +70 -64
  105. package/dist/config/config.d.ts +9 -2
  106. package/dist/config/config.js +184 -144
  107. package/dist/config/copyPlugin.js +29 -40
  108. package/dist/config/cssRules.js +93 -83
  109. package/dist/config/definePlugin.js +11 -19
  110. package/dist/config/detectDeadCode.d.ts +12 -0
  111. package/dist/config/detectDeadCode.js +120 -0
  112. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  113. package/dist/config/detectDeadCodePlugin.js +70 -0
  114. package/dist/config/fastRefreshPlugin.js +11 -22
  115. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  116. package/dist/config/forkTSCheckerPlugin.js +23 -0
  117. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  118. package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
  119. package/dist/config/ignorePlugin.js +10 -21
  120. package/dist/config/javaScriptRules.d.ts +2 -0
  121. package/dist/config/javaScriptRules.js +153 -131
  122. package/dist/config/manifestPlugin.d.ts +11 -0
  123. package/dist/config/manifestPlugin.js +17 -0
  124. package/dist/config/miniCSSExtractPlugin.d.ts +1 -0
  125. package/dist/config/miniCSSExtractPlugin.js +12 -24
  126. package/dist/config/nodePolyfill.js +14 -20
  127. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  128. package/dist/config/nodePrefixPlugin.js +14 -0
  129. package/dist/config/progressPlugin.js +7 -18
  130. package/dist/config/purgecssWebpackPlugin.js +15 -26
  131. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  132. package/dist/config/svgRules.d.ts +1 -0
  133. package/dist/config/svgRules.js +45 -48
  134. package/dist/constants.d.ts +4 -0
  135. package/dist/constants.js +10 -1
  136. package/dist/dev.d.ts +8 -2
  137. package/dist/dev.js +117 -66
  138. package/dist/index.d.ts +4 -1
  139. package/dist/index.js +5 -1
  140. package/dist/loader/svgr.d.ts +4 -0
  141. package/dist/loader/svgr.js +58 -0
  142. package/dist/loader/swc.d.ts +4 -0
  143. package/dist/loader/swc.js +74 -0
  144. package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -36
  145. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  146. package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
  147. package/dist/plugins/ProgressPlugin.js +2 -2
  148. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  149. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  150. package/dist/requireHook.js +1 -1
  151. package/dist/schema.js +23 -11
  152. package/dist/server/server.d.ts +2 -1
  153. package/dist/server/server.js +165 -130
  154. package/dist/server/ws.d.ts +6 -3
  155. package/dist/server/ws.js +1 -1
  156. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  157. package/dist/swcPlugins/autoCSSModules.js +16 -17
  158. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  159. package/dist/swcPlugins/changeImportFromString.js +10 -0
  160. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  161. package/dist/swcPlugins/lockCoreJS.js +24 -0
  162. package/dist/types.d.ts +19 -0
  163. package/dist/types.js +1 -0
  164. package/dist/utils/depMatch.js +1 -1
  165. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  166. package/dist/utils/getEsBuildTarget.js +12 -0
  167. package/package.json +68 -67
  168. package/compiled/@svgr/webpack/.svgo.yml +0 -75
  169. package/compiled/@svgr/webpack/LICENSE +0 -7
  170. package/compiled/@svgr/webpack/index.js +0 -343
  171. package/compiled/@svgr/webpack/package.json +0 -1
  172. package/compiled/css-loader/LICENSE +0 -20
  173. package/compiled/css-loader/api.js +0 -102
  174. package/compiled/css-loader/getUrl.js +0 -29
  175. package/compiled/css-loader/index.js +0 -2
  176. package/compiled/css-loader/noSourceMaps.js +0 -5
  177. package/compiled/css-loader/package.json +0 -1
  178. package/compiled/css-loader/sourceMaps.js +0 -22
  179. package/compiled/express/LICENSE +0 -24
  180. package/compiled/express/body-parser/index.d.ts +0 -104
  181. package/compiled/express/connect/index.d.ts +0 -93
  182. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  183. package/compiled/express/index.d.ts +0 -133
  184. package/compiled/express/index.js +0 -338
  185. package/compiled/express/mime/index.d.ts +0 -35
  186. package/compiled/express/package.json +0 -1
  187. package/compiled/express/qs/index.d.ts +0 -62
  188. package/compiled/express/range-parser/index.d.ts +0 -35
  189. package/compiled/express/serve-static/index.d.ts +0 -108
  190. package/compiled/less/index.js +0 -31
  191. package/compiled/less/package.json +0 -1
  192. package/compiled/swc-loader/LICENSE +0 -25
  193. package/compiled/swc-loader/index.js +0 -1
  194. package/compiled/swc-loader/package.json +0 -1
  195. package/compiled/tapable/index.js +0 -1
  196. package/compiled/tapable/package.json +0 -1
  197. package/compiled/tapable/tapable.d.ts +0 -116
package/dist/cli.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -22,7 +13,7 @@ const dev_1 = require("./dev");
22
13
  const args = (0, utils_1.yParser)(process.argv.slice(2), {});
23
14
  const command = args._[0];
24
15
  const cwd = process.cwd();
25
- const entry = tryPaths([
16
+ const entry = (0, utils_1.tryPaths)([
26
17
  (0, path_1.join)(cwd, 'src/index.tsx'),
27
18
  (0, path_1.join)(cwd, 'src/index.ts'),
28
19
  (0, path_1.join)(cwd, 'index.tsx'),
@@ -40,11 +31,11 @@ if ((0, fs_1.existsSync)(configFile)) {
40
31
  }
41
32
  Object.assign(config, args);
42
33
  if (command === 'build') {
43
- (() => __awaiter(void 0, void 0, void 0, function* () {
34
+ (async () => {
44
35
  process.env.NODE_ENV = 'production';
45
36
  (0, assert_1.default)(entry, `Build failed: entry not found.`);
46
37
  try {
47
- yield (0, build_1.build)({
38
+ await (0, build_1.build)({
48
39
  config,
49
40
  cwd,
50
41
  entry: {
@@ -55,26 +46,29 @@ if (command === 'build') {
55
46
  catch (e) {
56
47
  console.error(e);
57
48
  }
58
- }))();
49
+ })();
59
50
  }
60
51
  else if (command === 'dev') {
61
- (() => __awaiter(void 0, void 0, void 0, function* () {
52
+ (async () => {
62
53
  process.env.NODE_ENV = 'development';
63
54
  try {
64
55
  (0, assert_1.default)(entry, `Build failed: entry not found.`);
65
- yield (0, dev_1.dev)({
56
+ await (0, dev_1.dev)({
66
57
  config,
67
58
  cwd,
68
59
  port: process.env.PORT,
69
60
  entry: {
70
61
  [getEntryKey(entry)]: entry,
71
62
  },
63
+ cache: {
64
+ buildDependencies: [].filter(Boolean),
65
+ },
72
66
  });
73
67
  }
74
68
  catch (e) {
75
69
  console.error(e);
76
70
  }
77
- }))();
71
+ })();
78
72
  }
79
73
  else {
80
74
  error(`Unsupported command ${command}.`);
@@ -82,12 +76,6 @@ else {
82
76
  function error(msg) {
83
77
  console.error(utils_1.chalk.red(msg));
84
78
  }
85
- function tryPaths(paths) {
86
- for (const path of paths) {
87
- if ((0, fs_1.existsSync)(path))
88
- return path;
89
- }
90
- }
91
79
  function getEntryKey(path) {
92
80
  return (0, path_1.basename)(path, (0, path_1.extname)(path));
93
81
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -18,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
22
  __setModuleDefault(result, mod);
19
23
  return result;
20
24
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
31
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
27
  };
@@ -37,15 +32,30 @@ const ErrorOverlay = __importStar(require("react-error-overlay"));
37
32
  const constants_1 = require("../constants");
38
33
  const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
39
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
+ }
40
51
  let pingTimer = null;
41
- const host = location.host;
42
- const wsUrl = `ws://${host}`;
43
52
  let isFirstCompilation = true;
44
53
  let mostRecentCompilationHash = null;
45
54
  let hasCompileErrors = false;
46
55
  let hadRuntimeError = false;
47
- const socket = new WebSocket(wsUrl, 'webpack-hmr');
48
- socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
56
+ const pingUrl = getPingUrl();
57
+ const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
58
+ socket.addEventListener('message', async ({ data }) => {
49
59
  data = JSON.parse(data);
50
60
  if (data.type === 'connected') {
51
61
  console.log(`[webpack] connected.`);
@@ -56,28 +66,26 @@ socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void
56
66
  else {
57
67
  handleMessage(data).catch(console.error);
58
68
  }
59
- }));
60
- function waitForSuccessfulPing(ms = 1000) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- // eslint-disable-next-line no-constant-condition
63
- while (true) {
64
- try {
65
- yield fetch(`/__umi_ping`);
66
- break;
67
- }
68
- catch (e) {
69
- yield new Promise((resolve) => setTimeout(resolve, ms));
70
- }
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;
71
76
  }
72
- });
77
+ catch (e) {
78
+ await new Promise((resolve) => setTimeout(resolve, ms));
79
+ }
80
+ }
73
81
  }
74
- socket.addEventListener('close', () => __awaiter(void 0, void 0, void 0, function* () {
82
+ socket.addEventListener('close', async () => {
75
83
  if (pingTimer)
76
84
  clearInterval(pingTimer);
77
85
  console.info('[webpack] Dev server disconnected. Polling for restart...');
78
- yield waitForSuccessfulPing();
86
+ await waitForSuccessfulPing();
79
87
  location.reload();
80
- }));
88
+ });
81
89
  ErrorOverlay.startReportingRuntimeErrors({
82
90
  onError: function () {
83
91
  hadRuntimeError = true;
@@ -215,25 +223,23 @@ function tryApplyUpdates(onHotUpdateSuccess) {
215
223
  handleApplyUpdates(err, null);
216
224
  });
217
225
  }
218
- function handleMessage(payload) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- // console.log('[payload]', payload);
221
- switch (payload.type) {
222
- case constants_1.MESSAGE_TYPE.hash:
223
- handleAvailableHash(payload.data);
224
- break;
225
- case constants_1.MESSAGE_TYPE.stillOk:
226
- case constants_1.MESSAGE_TYPE.ok:
227
- handleSuccess();
228
- break;
229
- case constants_1.MESSAGE_TYPE.errors:
230
- handleErrors(payload.data);
231
- break;
232
- case constants_1.MESSAGE_TYPE.warnings:
233
- handleWarnings(payload.data);
234
- break;
235
- default:
236
- // Do nothing
237
- }
238
- });
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
+ }
239
245
  }
@@ -1,22 +1,11 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addSampleFeature = void 0;
13
- function addSampleFeature(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig, cwd, env } = opts;
16
- config;
17
- userConfig;
18
- cwd;
19
- env;
20
- });
4
+ async function addSampleFeature(opts) {
5
+ const { config, userConfig, cwd, env } = opts;
6
+ config;
7
+ userConfig;
8
+ cwd;
9
+ env;
21
10
  }
22
11
  exports.addSampleFeature = addSampleFeature;
@@ -1,57 +1,50 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addAssetRules = void 0;
13
- function addAssetRules(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig } = opts;
16
- const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
17
- const rule = config.module.rule('asset');
18
- rule
19
- .oneOf('avif')
20
- .test(/\.avif$/)
21
- .type('asset')
22
- .mimetype('image/avif')
23
- .parser({
24
- dataUrlCondition: {
25
- maxSize: inlineLimit,
26
- },
27
- })
28
- .generator({
29
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
30
- });
31
- rule
32
- .oneOf('image')
33
- .test(/\.(bmp|gif|jpg|jpeg|png)$/)
34
- .type('asset')
35
- .parser({
36
- dataUrlCondition: {
37
- maxSize: inlineLimit,
38
- },
39
- })
40
- .generator({
41
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
42
- });
43
- rule
44
- .oneOf('fallback')
45
- .exclude.add(/^$/) /* handle data: resources */
46
- .add(/\.(js|mjs|jsx|ts|tsx)$/)
47
- .add(/\.(css|less|sass|scss|stylus)$/)
48
- .add(/\.html$/)
49
- .add(/\.json$/)
50
- .end()
51
- .type('asset/resource')
52
- .generator({
53
- filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
54
- });
4
+ async function addAssetRules(opts) {
5
+ const { config, userConfig } = opts;
6
+ const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
7
+ const rule = config.module.rule('asset');
8
+ rule
9
+ .oneOf('avif')
10
+ .test(/\.avif$/)
11
+ .type('asset')
12
+ .mimetype('image/avif')
13
+ .parser({
14
+ dataUrlCondition: {
15
+ maxSize: inlineLimit,
16
+ },
17
+ })
18
+ .generator({
19
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
20
+ });
21
+ rule
22
+ .oneOf('image')
23
+ .test(/\.(bmp|gif|jpg|jpeg|png)$/)
24
+ .type('asset')
25
+ .parser({
26
+ dataUrlCondition: {
27
+ maxSize: inlineLimit,
28
+ },
29
+ })
30
+ .generator({
31
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
32
+ });
33
+ const fallback = rule
34
+ .oneOf('fallback')
35
+ .exclude.add(/^$/) /* handle data: resources */
36
+ .add(/\.(js|mjs|jsx|ts|tsx)$/)
37
+ .add(/\.(css|less|sass|scss|stylus)$/)
38
+ .add(/\.html$/)
39
+ .add(/\.json$/);
40
+ if (userConfig.mdx) {
41
+ fallback.add(/\.mdx?$/);
42
+ }
43
+ fallback
44
+ .end()
45
+ .type('asset/resource')
46
+ .generator({
47
+ filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
55
48
  });
56
49
  }
57
50
  exports.addAssetRules = addAssetRules;
@@ -1,30 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addBundleAnalyzerPlugin = void 0;
13
4
  // @ts-ignore
14
5
  const webpack_bundle_analyzer_1 = require("@umijs/bundler-webpack/compiled/webpack-bundle-analyzer");
15
- function addBundleAnalyzerPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config } = opts;
18
- config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
19
- // https://github.com/webpack-contrib/webpack-bundle-analyzer
20
- {
21
- analyzerMode: 'server',
22
- analyzerPort: process.env.ANALYZE_PORT || 8888,
23
- openAnalyzer: false,
24
- logLevel: 'info',
25
- defaultSizes: 'parsed',
26
- },
27
- ]);
28
- });
6
+ async function addBundleAnalyzerPlugin(opts) {
7
+ const { config } = opts;
8
+ config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
9
+ // https://github.com/webpack-contrib/webpack-bundle-analyzer
10
+ {
11
+ analyzerMode: 'server',
12
+ analyzerPort: process.env.ANALYZE_PORT || 8888,
13
+ openAnalyzer: false,
14
+ logLevel: 'info',
15
+ defaultSizes: 'parsed',
16
+ },
17
+ ]);
29
18
  }
30
19
  exports.addBundleAnalyzerPlugin = addBundleAnalyzerPlugin;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,61 +8,76 @@ exports.addCompressPlugin = void 0;
17
8
  const css_minimizer_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/css-minimizer-webpack-plugin"));
18
9
  const terser_webpack_plugin_1 = __importDefault(require("../../compiled/terser-webpack-plugin"));
19
10
  const ESBuildCSSMinifyPlugin_1 = __importDefault(require("../plugins/ESBuildCSSMinifyPlugin"));
11
+ const ParcelCSSMinifyPlugin_1 = require("../plugins/ParcelCSSMinifyPlugin");
20
12
  const types_1 = require("../types");
21
- function addCompressPlugin(opts) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { config, userConfig, env } = opts;
24
- const jsMinifier = userConfig.jsMinifier || types_1.JSMinifier.esbuild;
25
- const cssMinifier = userConfig.cssMinifier || types_1.CSSMinifier.esbuild;
26
- if (env === types_1.Env.development ||
27
- process.env.COMPRESS === 'none' ||
28
- (jsMinifier === types_1.JSMinifier.none && cssMinifier === types_1.CSSMinifier.none)) {
29
- config.optimization.minimize(false);
30
- return;
31
- }
32
- config.optimization.minimize(true);
33
- let minify;
34
- if (jsMinifier === types_1.JSMinifier.esbuild) {
35
- minify = terser_webpack_plugin_1.default.esbuildMinify;
36
- }
37
- else if (jsMinifier === types_1.JSMinifier.terser) {
38
- minify = terser_webpack_plugin_1.default.terserMinify;
39
- }
40
- else if (jsMinifier === types_1.JSMinifier.swc) {
41
- minify = terser_webpack_plugin_1.default.swcMinify;
42
- }
43
- else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
44
- minify = terser_webpack_plugin_1.default.uglifyJsMinify;
45
- }
46
- else if (jsMinifier !== types_1.JSMinifier.none) {
47
- throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
48
- }
49
- if (jsMinifier !== types_1.JSMinifier.none) {
50
- config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
51
- {
52
- minify,
53
- terserOptions: userConfig.jsMinifierOptions,
54
- },
55
- ]);
56
- }
57
- if (cssMinifier === types_1.CSSMinifier.esbuild) {
58
- config.optimization
59
- .minimizer(`css-${cssMinifier}`)
60
- .use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
61
- }
62
- else if (cssMinifier === types_1.CSSMinifier.cssnano) {
63
- config.optimization
64
- .minimizer(`css-${cssMinifier}`)
65
- .use(css_minimizer_webpack_plugin_1.default, [
66
- {
67
- minimizerOptions: userConfig.cssMinifierOptions,
68
- parallel: true,
69
- },
70
- ]);
71
- }
72
- else if (cssMinifier !== types_1.CSSMinifier.none) {
73
- throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
74
- }
75
- });
13
+ const getEsBuildTarget_1 = require("../utils/getEsBuildTarget");
14
+ async function addCompressPlugin(opts) {
15
+ const { config, userConfig, env } = opts;
16
+ const jsMinifier = userConfig.jsMinifier || types_1.JSMinifier.esbuild;
17
+ const cssMinifier = userConfig.cssMinifier || types_1.CSSMinifier.esbuild;
18
+ if (env === types_1.Env.development ||
19
+ process.env.COMPRESS === 'none' ||
20
+ (jsMinifier === types_1.JSMinifier.none && cssMinifier === types_1.CSSMinifier.none)) {
21
+ config.optimization.minimize(false);
22
+ return;
23
+ }
24
+ config.optimization.minimize(true);
25
+ let minify;
26
+ let terserOptions;
27
+ if (jsMinifier === types_1.JSMinifier.esbuild) {
28
+ minify = terser_webpack_plugin_1.default.esbuildMinify;
29
+ terserOptions = {
30
+ target: (0, getEsBuildTarget_1.getEsBuildTarget)({
31
+ targets: userConfig.targets || {},
32
+ }),
33
+ };
34
+ }
35
+ else if (jsMinifier === types_1.JSMinifier.terser) {
36
+ minify = terser_webpack_plugin_1.default.terserMinify;
37
+ }
38
+ else if (jsMinifier === types_1.JSMinifier.swc) {
39
+ minify = terser_webpack_plugin_1.default.swcMinify;
40
+ }
41
+ else if (jsMinifier === types_1.JSMinifier.uglifyJs) {
42
+ minify = terser_webpack_plugin_1.default.uglifyJsMinify;
43
+ }
44
+ else if (jsMinifier !== types_1.JSMinifier.none) {
45
+ throw new Error(`Unsupported jsMinifier ${userConfig.jsMinifier}.`);
46
+ }
47
+ terserOptions = {
48
+ ...terserOptions,
49
+ ...userConfig.jsMinifierOptions,
50
+ };
51
+ if (jsMinifier !== types_1.JSMinifier.none) {
52
+ config.optimization.minimizer(`js-${jsMinifier}`).use(terser_webpack_plugin_1.default, [
53
+ {
54
+ minify,
55
+ terserOptions,
56
+ },
57
+ ]);
58
+ }
59
+ if (cssMinifier === types_1.CSSMinifier.esbuild) {
60
+ config.optimization
61
+ .minimizer(`css-${cssMinifier}`)
62
+ .use(ESBuildCSSMinifyPlugin_1.default, [userConfig.cssMinifierOptions]);
63
+ }
64
+ else if (cssMinifier === types_1.CSSMinifier.cssnano) {
65
+ config.optimization
66
+ .minimizer(`css-${cssMinifier}`)
67
+ .use(css_minimizer_webpack_plugin_1.default, [
68
+ {
69
+ minimizerOptions: userConfig.cssMinifierOptions,
70
+ parallel: true,
71
+ },
72
+ ]);
73
+ }
74
+ else if (cssMinifier === types_1.CSSMinifier.parcelCSS) {
75
+ config.optimization
76
+ .minimizer(`css-${cssMinifier}`)
77
+ .use(ParcelCSSMinifyPlugin_1.ParcelCSSMinifyPlugin);
78
+ }
79
+ else if (cssMinifier !== types_1.CSSMinifier.none) {
80
+ throw new Error(`Unsupported cssMinifier ${userConfig.cssMinifier}.`);
81
+ }
76
82
  }
77
83
  exports.addCompressPlugin = addCompressPlugin;
@@ -1,11 +1,14 @@
1
1
  import { Configuration } from '../../compiled/webpack';
2
2
  import { Env, IConfig } from '../types';
3
- interface IOpts {
3
+ export interface IOpts {
4
4
  cwd: string;
5
+ rootDir?: string;
5
6
  env: Env;
6
7
  entry: Record<string, string>;
7
8
  extraBabelPresets?: any[];
8
9
  extraBabelPlugins?: any[];
10
+ extraBabelIncludes?: string[];
11
+ extraEsbuildLoaderHandler?: any[];
9
12
  babelPreset?: any;
10
13
  chainWebpack?: Function;
11
14
  modifyWebpackConfig?: Function;
@@ -15,6 +18,10 @@ interface IOpts {
15
18
  userConfig: IConfig;
16
19
  analyze?: any;
17
20
  name?: string;
21
+ cache?: {
22
+ absNodeModulesPath?: string;
23
+ buildDependencies?: string[];
24
+ cacheDirectory?: string;
25
+ };
18
26
  }
19
27
  export declare function getConfig(opts: IOpts): Promise<Configuration>;
20
- export {};