@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
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addDefinePlugin = exports.resolveDefine = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
@@ -29,17 +20,18 @@ function resolveDefine(opts) {
29
20
  define[key] = JSON.stringify(opts.define[key]);
30
21
  }
31
22
  }
32
- return Object.assign({ 'process.env': env }, define);
23
+ return {
24
+ 'process.env': env,
25
+ ...define,
26
+ };
33
27
  }
34
28
  exports.resolveDefine = resolveDefine;
35
- function addDefinePlugin(opts) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const { config, userConfig } = opts;
38
- config.plugin('define').use(webpack_1.DefinePlugin, [
39
- resolveDefine({
40
- define: userConfig.define || {},
41
- }),
42
- ]);
43
- });
29
+ async function addDefinePlugin(opts) {
30
+ const { config, userConfig } = opts;
31
+ config.plugin('define').use(webpack_1.DefinePlugin, [
32
+ resolveDefine({
33
+ define: userConfig.define || {},
34
+ }),
35
+ ]);
44
36
  }
45
37
  exports.addDefinePlugin = addDefinePlugin;
@@ -0,0 +1,12 @@
1
+ import { Compilation } from '@umijs/bundler-webpack/compiled/webpack';
2
+ import { DeadCodeParams } from '../types';
3
+ export interface Options extends DeadCodeParams {
4
+ patterns: string[];
5
+ exclude: string[];
6
+ failOnHint: boolean;
7
+ detectUnusedFiles: boolean;
8
+ detectUnusedExport: boolean;
9
+ }
10
+ export declare const disabledFolders: string[];
11
+ declare const detectDeadCode: (compilation: Compilation, options: Options) => void;
12
+ export default detectDeadCode;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.disabledFolders = void 0;
7
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
8
+ const utils_1 = require("@umijs/utils");
9
+ const path_1 = __importDefault(require("path"));
10
+ exports.disabledFolders = [
11
+ 'node_modules',
12
+ '.umi',
13
+ '.umi-production',
14
+ 'dist',
15
+ ];
16
+ const detectDeadCode = (compilation, options) => {
17
+ const assets = getWebpackAssets(compilation);
18
+ const compiledFilesDictionary = convertFilesToDict(assets);
19
+ const includedFiles = getPattern(options)
20
+ .map((pattern) => utils_1.glob.sync(pattern))
21
+ .flat();
22
+ const unusedFiles = options.detectUnusedFiles
23
+ ? includedFiles.filter((file) => !compiledFilesDictionary[file])
24
+ : [];
25
+ const unusedExportMap = options.detectUnusedExport
26
+ ? getUnusedExportMap(convertFilesToDict(includedFiles), compilation)
27
+ : {};
28
+ logUnusedFiles(unusedFiles);
29
+ logUnusedExportMap(unusedExportMap);
30
+ const hasUnusedThings = unusedFiles.length || Object.keys(unusedExportMap).length;
31
+ if (hasUnusedThings && options.failOnHint) {
32
+ process.exit(2);
33
+ }
34
+ };
35
+ const getPattern = (options) => {
36
+ return options.patterns
37
+ .map((pattern) => path_1.default.resolve(options.context || '', pattern))
38
+ .concat(options.exclude.map((pattern) => path_1.default.resolve(options.context || '', `!${pattern}`)))
39
+ .map(convertToUnixPath);
40
+ };
41
+ const getUnusedExportMap = (includedFileMap, compilation) => {
42
+ const unusedExportMap = {};
43
+ compilation.chunks.forEach((chunk) => {
44
+ compilation.chunkGraph.getChunkModules(chunk).forEach((module) => {
45
+ outputUnusedExportMap(compilation, chunk, module, includedFileMap, unusedExportMap);
46
+ });
47
+ });
48
+ return unusedExportMap;
49
+ };
50
+ const outputUnusedExportMap = (compilation, chunk, module, includedFileMap, unusedExportMap) => {
51
+ if (!(module instanceof webpack_1.NormalModule) || !module.resource) {
52
+ return;
53
+ }
54
+ const path = convertToUnixPath(module.resource);
55
+ if (!/^((?!(node_modules)).)*$/.test(path))
56
+ return;
57
+ const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module);
58
+ const usedExports = compilation.chunkGraph.moduleGraph.getUsedExports(module, chunk.runtime);
59
+ if (usedExports !== true &&
60
+ providedExports !== true &&
61
+ includedFileMap[path]) {
62
+ if (usedExports === false) {
63
+ if (providedExports === null || providedExports === void 0 ? void 0 : providedExports.length) {
64
+ unusedExportMap[path] = providedExports;
65
+ }
66
+ }
67
+ else if (providedExports instanceof Array) {
68
+ const unusedExports = providedExports.filter((item) => usedExports && !usedExports.has(item));
69
+ if (unusedExports.length) {
70
+ unusedExportMap[path] = unusedExports;
71
+ }
72
+ }
73
+ }
74
+ };
75
+ const logUnusedExportMap = (unusedExportMap) => {
76
+ if (!Object.keys(unusedExportMap).length) {
77
+ return;
78
+ }
79
+ let numberOfUnusedExport = 0;
80
+ let logStr = '';
81
+ Object.keys(unusedExportMap).forEach((filePath, fileIndex) => {
82
+ const unusedExports = unusedExportMap[filePath];
83
+ logStr += [
84
+ `\n${fileIndex + 1}. `,
85
+ utils_1.chalk.yellow(`${filePath}\n`),
86
+ ' >>> ',
87
+ utils_1.chalk.yellow(`${unusedExports.join(', ')}`),
88
+ ].join('');
89
+ numberOfUnusedExport += unusedExports.length;
90
+ });
91
+ console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${numberOfUnusedExport} unused exports in ${Object.keys(unusedExportMap).length} files:`), logStr, utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
92
+ };
93
+ const getWebpackAssets = (compilation) => {
94
+ const outputPath = compilation.getPath(compilation.compiler.outputPath);
95
+ const assets = [
96
+ ...Array.from(compilation.fileDependencies),
97
+ ...compilation
98
+ .getAssets()
99
+ .map((asset) => path_1.default.join(outputPath, asset.name)),
100
+ ];
101
+ return assets;
102
+ };
103
+ const convertFilesToDict = (assets) => {
104
+ return assets
105
+ .filter((file) => Boolean(file) &&
106
+ exports.disabledFolders.every((disabledPath) => !file.includes(disabledPath)))
107
+ .reduce((fileDictionary, file) => {
108
+ const unixFile = convertToUnixPath(file);
109
+ fileDictionary[unixFile] = true;
110
+ return fileDictionary;
111
+ }, {});
112
+ };
113
+ const logUnusedFiles = (unusedFiles) => {
114
+ if (!(unusedFiles === null || unusedFiles === void 0 ? void 0 : unusedFiles.length)) {
115
+ return;
116
+ }
117
+ console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `\n${index + 1}. ${utils_1.chalk.yellow(file)}`), utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
118
+ };
119
+ const convertToUnixPath = (path) => path.replace(/\\+/g, '/');
120
+ exports.default = detectDeadCode;
@@ -0,0 +1,9 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ userConfig: IConfig;
5
+ config: Config;
6
+ env: Env;
7
+ }
8
+ export declare function addDetectDeadCodePlugin(opts: IOpts): Promise<void>;
9
+ export {};
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.addDetectDeadCodePlugin = void 0;
27
+ const types_1 = require("../types");
28
+ const detectDeadCode_1 = __importStar(require("./detectDeadCode"));
29
+ const defaultOptions = {
30
+ patterns: [`!(${detectDeadCode_1.disabledFolders.join('|')})/**/*.*`],
31
+ exclude: [],
32
+ failOnHint: false,
33
+ detectUnusedFiles: true,
34
+ detectUnusedExport: true,
35
+ };
36
+ class DetectDeadCodePlugin {
37
+ constructor(options) {
38
+ this.options = defaultOptions;
39
+ this.handleAfterEmit = (compilation, callback) => {
40
+ (0, detectDeadCode_1.default)(compilation, this.options);
41
+ callback();
42
+ };
43
+ if (!options) {
44
+ return;
45
+ }
46
+ this.options = {
47
+ ...this.options,
48
+ ...options,
49
+ };
50
+ }
51
+ apply(compiler) {
52
+ if (!this.options.context) {
53
+ this.options = {
54
+ ...this.options,
55
+ context: compiler.context,
56
+ };
57
+ }
58
+ compiler.hooks.afterEmit.tapAsync('DetectDeadCodePlugin', this.handleAfterEmit);
59
+ }
60
+ }
61
+ async function addDetectDeadCodePlugin(opts) {
62
+ const { config, userConfig } = opts;
63
+ const isDev = opts.env === types_1.Env.development;
64
+ if (userConfig.deadCode && !isDev) {
65
+ config
66
+ .plugin('detect-dead-code-plugin')
67
+ .use(DetectDeadCodePlugin, [userConfig.deadCode]);
68
+ }
69
+ }
70
+ exports.addDetectDeadCodePlugin = addDetectDeadCodePlugin;
@@ -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,18 +8,16 @@ exports.addFastRefreshPlugin = void 0;
17
8
  const lib_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin/lib"));
18
9
  const constants_1 = require("../constants");
19
10
  const types_1 = require("../types");
20
- function addFastRefreshPlugin(opts) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { config, userConfig, name } = opts;
23
- const isDev = opts.env === types_1.Env.development;
24
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
25
- // TODO: Should only run in react csr
26
- if (useFastRefresh) {
27
- config
28
- .plugin('fastRefresh')
29
- .after('hmr')
30
- .use(lib_1.default, [{ overlay: false }]);
31
- }
32
- });
11
+ async function addFastRefreshPlugin(opts) {
12
+ const { config, userConfig, name } = opts;
13
+ const isDev = opts.env === types_1.Env.development;
14
+ const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
15
+ // TODO: Should only run in react csr
16
+ if (useFastRefresh) {
17
+ config
18
+ .plugin('fastRefresh')
19
+ .after('hmr')
20
+ .use(lib_1.default, [{ overlay: false }]);
21
+ }
33
22
  }
34
23
  exports.addFastRefreshPlugin = addFastRefreshPlugin;
@@ -0,0 +1,11 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export declare function addForkTSCheckerPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addForkTSCheckerPlugin = void 0;
7
+ // @ts-ignore
8
+ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/fork-ts-checker-webpack-plugin"));
9
+ async function addForkTSCheckerPlugin(opts) {
10
+ var _a;
11
+ const { config, userConfig } = opts;
12
+ if (userConfig.forkTSChecker) {
13
+ // use user's typescript
14
+ if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
15
+ userConfig.forkTSChecker.typescript.typescriptPath =
16
+ require.resolve('typescript');
17
+ }
18
+ config
19
+ .plugin('fork-ts-checker-plugin')
20
+ .use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
21
+ }
22
+ }
23
+ exports.addForkTSCheckerPlugin = addForkTSCheckerPlugin;
@@ -0,0 +1,6 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ interface IOpts {
3
+ config: Config;
4
+ }
5
+ export declare function addHarmonyLinkingErrorPlugin(opts: IOpts): Promise<void>;
6
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addHarmonyLinkingErrorPlugin = void 0;
4
+ // ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
5
+ const LINKING_ERROR_TAG = 'was not found in';
6
+ // build 时会出现 css modules 的引用警告,但这应该是需要忽略的
7
+ const CSS_NO_EXPORTS = /\.(css|sass|scss|styl|less)' \(module has no exports\)/;
8
+ class HarmonyLinkingErrorPlugin {
9
+ apply(compiler) {
10
+ compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
11
+ if (!compilation.warnings.length) {
12
+ return;
13
+ }
14
+ const harmonyLinkingErrors = compilation.warnings.filter((w) => {
15
+ return (w.name === 'ModuleDependencyWarning' &&
16
+ !w.module.resource.includes('node_modules') &&
17
+ w.message.includes(LINKING_ERROR_TAG) &&
18
+ !CSS_NO_EXPORTS.test(w.message));
19
+ });
20
+ if (!harmonyLinkingErrors.length) {
21
+ return;
22
+ }
23
+ compilation.errors.push(...harmonyLinkingErrors);
24
+ });
25
+ }
26
+ }
27
+ async function addHarmonyLinkingErrorPlugin(opts) {
28
+ const { config } = opts;
29
+ config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
30
+ }
31
+ exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
@@ -1,27 +1,16 @@
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.addIgnorePlugin = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
- function addIgnorePlugin(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config, userConfig } = opts;
17
- if (userConfig.ignoreMomentLocale) {
18
- config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
19
- {
20
- resourceRegExp: /^\.\/locale$/,
21
- contextRegExp: /moment$/,
22
- },
23
- ]);
24
- }
25
- });
5
+ async function addIgnorePlugin(opts) {
6
+ const { config, userConfig } = opts;
7
+ if (userConfig.ignoreMomentLocale) {
8
+ config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
9
+ {
10
+ resourceRegExp: /^\.\/locale$/,
11
+ contextRegExp: /moment$/,
12
+ },
13
+ ]);
14
+ }
26
15
  }
27
16
  exports.addIgnorePlugin = addIgnorePlugin;
@@ -7,6 +7,8 @@ interface IOpts {
7
7
  env: Env;
8
8
  extraBabelPlugins: any[];
9
9
  extraBabelPresets: any[];
10
+ extraBabelIncludes: string[];
11
+ extraEsbuildLoaderHandler: any[];
10
12
  babelPreset: any;
11
13
  name?: string;
12
14
  }