@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.12

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 (121) hide show
  1. package/client/client/client.js +57 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/autoprefixer/browserslist/index.d.ts +6 -0
  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/declaration.d.ts +2 -2
  8. package/compiled/autoprefixer/postcss/lib/node.d.ts +2 -2
  9. package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
  10. package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
  11. package/compiled/babel-loader/index.js +2 -2
  12. package/compiled/copy-webpack-plugin/939.index.js +1171 -0
  13. package/compiled/copy-webpack-plugin/index.js +16 -10
  14. package/compiled/copy-webpack-plugin/package.json +1 -1
  15. package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
  16. package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
  17. package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
  18. package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
  19. package/compiled/cssnano/index.js +12 -11
  20. package/compiled/cssnano/package.json +1 -1
  21. package/compiled/express.d.ts +2 -0
  22. package/compiled/fork-ts-checker-webpack-plugin/index.js +8 -15
  23. package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
  24. package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
  25. package/compiled/http-proxy-middleware/index.js +10 -10
  26. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
  27. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
  28. package/compiled/mini-css-extract-plugin/index.js +4523 -4036
  29. package/compiled/mini-css-extract-plugin/loader.js +179 -54
  30. package/compiled/mini-css-extract-plugin/package.json +1 -1
  31. package/compiled/mini-css-extract-plugin/utils.js +79 -23
  32. package/compiled/react-refresh/LICENSE +21 -0
  33. package/compiled/react-refresh/index.js +9 -7
  34. package/compiled/react-refresh/package.json +1 -0
  35. package/compiled/sass-loader/index.js +1 -1
  36. package/compiled/terser/index.js +1 -1
  37. package/compiled/terser-webpack-plugin/index.js +296 -297
  38. package/compiled/terser-webpack-plugin/minify.js +4 -2
  39. package/compiled/terser-webpack-plugin/package.json +1 -1
  40. package/compiled/terser-webpack-plugin/types/index.d.ts +180 -146
  41. package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
  42. package/compiled/terser-webpack-plugin/types/utils.d.ts +1 -3
  43. package/compiled/terser-webpack-plugin/utils.js +9 -12
  44. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  45. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  46. package/compiled/webpack/index.js +11589 -4372
  47. package/compiled/webpack-dev-middleware/index.js +7 -7
  48. package/compiled/webpack-dev-middleware/package.json +1 -1
  49. package/compiled/webpack-manifest-plugin/index.js +1 -1
  50. package/compiled/webpack-sources/index.js +1 -1
  51. package/compiled/ws/index.d.ts +1 -2
  52. package/compiled/ws/index.js +1 -1
  53. package/dist/build.d.ts +2 -1
  54. package/dist/build.js +1 -1
  55. package/dist/client/client.js +15 -4
  56. package/dist/config/compressPlugin.js +15 -1
  57. package/dist/config/config.js +7 -3
  58. package/dist/config/cssRules.js +1 -1
  59. package/dist/config/detectDeadCode.d.ts +12 -0
  60. package/dist/config/detectDeadCode.js +120 -0
  61. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  62. package/dist/config/detectDeadCodePlugin.js +75 -0
  63. package/dist/config/javaScriptRules.js +7 -12
  64. package/dist/config/nodePolyfill.js +1 -1
  65. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  66. package/dist/config/nodePrefixPlugin.js +25 -0
  67. package/dist/constants.d.ts +4 -0
  68. package/dist/constants.js +10 -1
  69. package/dist/dev.d.ts +4 -0
  70. package/dist/dev.js +27 -8
  71. package/dist/index.d.ts +4 -1
  72. package/dist/index.js +5 -1
  73. package/dist/loader/swc.js +14 -18
  74. package/dist/plugins/ESBuildCSSMinifyPlugin.js +1 -3
  75. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  76. package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
  77. package/dist/plugins/ProgressPlugin.js +2 -2
  78. package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
  79. package/dist/requireHook.js +1 -1
  80. package/dist/schema.js +10 -6
  81. package/dist/server/https.d.ts +5 -0
  82. package/dist/server/https.js +73 -0
  83. package/dist/server/server.d.ts +2 -1
  84. package/dist/server/server.js +48 -11
  85. package/dist/server/ws.d.ts +3 -2
  86. package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
  87. package/dist/swcPlugins/autoCSSModules.js +14 -17
  88. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  89. package/dist/swcPlugins/changeImportFromString.js +10 -0
  90. package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
  91. package/dist/swcPlugins/lockCoreJS.js +3 -2
  92. package/dist/types.d.ts +16 -12
  93. package/dist/types.js +1 -0
  94. package/dist/utils/depMatch.js +1 -1
  95. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  96. package/dist/utils/getEsBuildTarget.js +12 -0
  97. package/package.json +40 -42
  98. package/compiled/css-loader/LICENSE +0 -20
  99. package/compiled/css-loader/api.js +0 -102
  100. package/compiled/css-loader/getUrl.js +0 -29
  101. package/compiled/css-loader/index.js +0 -2
  102. package/compiled/css-loader/noSourceMaps.js +0 -5
  103. package/compiled/css-loader/package.json +0 -1
  104. package/compiled/css-loader/sourceMaps.js +0 -22
  105. package/compiled/express/LICENSE +0 -24
  106. package/compiled/express/body-parser/index.d.ts +0 -104
  107. package/compiled/express/connect/index.d.ts +0 -93
  108. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  109. package/compiled/express/index.d.ts +0 -133
  110. package/compiled/express/index.js +0 -338
  111. package/compiled/express/mime/index.d.ts +0 -35
  112. package/compiled/express/package.json +0 -1
  113. package/compiled/express/qs/index.d.ts +0 -62
  114. package/compiled/express/range-parser/index.d.ts +0 -35
  115. package/compiled/express/serve-static/index.d.ts +0 -108
  116. package/compiled/less/index.js +0 -31
  117. package/compiled/less/package.json +0 -1
  118. package/dist/esbuildHandler/autoCssModules.d.ts +0 -2
  119. package/dist/esbuildHandler/autoCssModules.js +0 -23
  120. package/dist/loader/esbuild.d.ts +0 -5
  121. package/dist/loader/esbuild.js +0 -53
@@ -26,6 +26,7 @@ const compressPlugin_1 = require("./compressPlugin");
26
26
  const copyPlugin_1 = require("./copyPlugin");
27
27
  const cssRules_1 = require("./cssRules");
28
28
  const definePlugin_1 = require("./definePlugin");
29
+ const detectDeadCodePlugin_1 = require("./detectDeadCodePlugin");
29
30
  const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
30
31
  const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
31
32
  const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
@@ -34,6 +35,7 @@ const javaScriptRules_1 = require("./javaScriptRules");
34
35
  const manifestPlugin_1 = require("./manifestPlugin");
35
36
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
36
37
  const nodePolyfill_1 = require("./nodePolyfill");
38
+ const nodePrefixPlugin_1 = require("./nodePrefixPlugin");
37
39
  const progressPlugin_1 = require("./progressPlugin");
38
40
  const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
39
41
  const svgRules_1 = require("./svgRules");
@@ -42,9 +44,7 @@ function getConfig(opts) {
42
44
  const { userConfig } = opts;
43
45
  const isDev = opts.env === types_1.Env.development;
44
46
  const config = new webpack_5_chain_1.default();
45
- userConfig.targets = userConfig.targets || {
46
- chrome: 80,
47
- };
47
+ userConfig.targets || (userConfig.targets = constants_1.DEFAULT_BROWSER_TARGETS);
48
48
  const useHash = !!(opts.hash || (userConfig.hash && !isDev));
49
49
  const applyOpts = {
50
50
  name: opts.name,
@@ -136,6 +136,8 @@ function getConfig(opts) {
136
136
  yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
137
137
  // progress
138
138
  yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
139
+ // detect-dead-code-plugin
140
+ yield (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
139
141
  // fork-ts-checker
140
142
  yield (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
141
143
  // copy
@@ -152,6 +154,8 @@ function getConfig(opts) {
152
154
  // await applyPurgeCSSWebpackPlugin(applyOpts);
153
155
  // handle HarmonyLinkingError
154
156
  yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
157
+ // remove node: prefix
158
+ yield (0, nodePrefixPlugin_1.addNodePrefixPlugin)(applyOpts);
155
159
  // runtimePublicPath
156
160
  if (userConfig.runtimePublicPath) {
157
161
  config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
@@ -20,7 +20,7 @@ function addCSSRules(opts) {
20
20
  test: /\.less(\?.*)?$/,
21
21
  loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
22
22
  loaderOptions: {
23
- implementation: require.resolve('@umijs/bundler-webpack/compiled/less'),
23
+ implementation: require.resolve('@umijs/bundler-utils/compiled/less'),
24
24
  lessOptions: Object.assign({ modifyVars: userConfig.theme, javascriptEnabled: true }, userConfig.lessLoader),
25
25
  },
26
26
  },
@@ -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,75 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.addDetectDeadCodePlugin = void 0;
36
+ const types_1 = require("../types");
37
+ const detectDeadCode_1 = __importStar(require("./detectDeadCode"));
38
+ const defaultOptions = {
39
+ patterns: [`!(${detectDeadCode_1.disabledFolders.join('|')})/**/*.*`],
40
+ exclude: [],
41
+ failOnHint: false,
42
+ detectUnusedFiles: true,
43
+ detectUnusedExport: true,
44
+ };
45
+ class DetectDeadCodePlugin {
46
+ constructor(options) {
47
+ this.options = defaultOptions;
48
+ this.handleAfterEmit = (compilation, callback) => {
49
+ (0, detectDeadCode_1.default)(compilation, this.options);
50
+ callback();
51
+ };
52
+ if (!options) {
53
+ return;
54
+ }
55
+ this.options = Object.assign(Object.assign({}, this.options), options);
56
+ }
57
+ apply(compiler) {
58
+ if (!this.options.context) {
59
+ this.options = Object.assign(Object.assign({}, this.options), { context: compiler.context });
60
+ }
61
+ compiler.hooks.afterEmit.tapAsync('DetectDeadCodePlugin', this.handleAfterEmit);
62
+ }
63
+ }
64
+ function addDetectDeadCodePlugin(opts) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ const { config, userConfig } = opts;
67
+ const isDev = opts.env === types_1.Env.development;
68
+ if (userConfig.deadCode && !isDev) {
69
+ config
70
+ .plugin('detect-dead-code-plugin')
71
+ .use(DetectDeadCodePlugin, [userConfig.deadCode]);
72
+ }
73
+ });
74
+ }
75
+ exports.addDetectDeadCodePlugin = addDetectDeadCodePlugin;
@@ -8,17 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.addJavaScriptRules = void 0;
13
+ const mfsu_1 = require("@umijs/mfsu");
16
14
  const utils_1 = require("@umijs/utils");
17
15
  const webpack_1 = require("../../compiled/webpack");
18
16
  const constants_1 = require("../constants");
19
- const autoCssModules_1 = __importDefault(require("../esbuildHandler/autoCssModules"));
20
- const esbuild_1 = require("../loader/esbuild");
21
- const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
22
17
  const types_1 = require("../types");
23
18
  const depMatch_1 = require("../utils/depMatch");
24
19
  function addJavaScriptRules(opts) {
@@ -47,7 +42,8 @@ function addJavaScriptRules(opts) {
47
42
  .test(/\.(js|mjs)$/)
48
43
  .include.add((path) => {
49
44
  try {
50
- if (path.includes('client/client'))
45
+ // do src transform for bundler-webpack/client/client/client.js
46
+ if (path.includes('client/client/client'))
51
47
  return true;
52
48
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
53
49
  }
@@ -119,22 +115,21 @@ function addJavaScriptRules(opts) {
119
115
  });
120
116
  }
121
117
  else if (srcTranspiler === types_1.Transpiler.swc) {
122
- // TODO: support javascript
118
+ const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
123
119
  rule
124
120
  .use('swc-loader')
125
121
  .loader(require.resolve('../loader/swc'))
126
122
  .options({
127
- plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
128
- targets: userConfig.targets,
123
+ plugin: (m) => new AutoCSSModule().visitProgram(m),
129
124
  });
130
125
  }
131
126
  else if (srcTranspiler === types_1.Transpiler.esbuild) {
132
127
  rule
133
128
  .use('esbuild-loader')
134
- .loader(esbuild_1.esbuildLoaderPath)
129
+ .loader(mfsu_1.esbuildLoader)
135
130
  .options({
136
131
  target: isDev ? 'esnext' : 'es2015',
137
- handler: [autoCssModules_1.default, ...opts.extraEsbuildLoaderHandler],
132
+ handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
138
133
  });
139
134
  // esbuild loader can not auto import `React`
140
135
  config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
@@ -14,12 +14,12 @@ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
14
  function addNodePolyfill(opts) {
15
15
  return __awaiter(this, void 0, void 0, function* () {
16
16
  const { config } = opts;
17
- const nodeLibs = require('node-libs-browser');
18
17
  config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
19
18
  {
20
19
  Buffer: ['buffer', 'Buffer'],
21
20
  },
22
21
  ]);
22
+ const nodeLibs = require('node-libs-browser');
23
23
  config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
24
24
  if (nodeLibs[key]) {
25
25
  memo[key] = nodeLibs[key];
@@ -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 addNodePrefixPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,25 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addNodePrefixPlugin = void 0;
13
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
+ function addNodePrefixPlugin(opts) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const { config } = opts;
17
+ config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
18
+ /^node:/,
19
+ (resource) => {
20
+ resource.request = resource.request.replace(/^node:/, '');
21
+ },
22
+ ]);
23
+ });
24
+ }
25
+ exports.addNodePrefixPlugin = addNodePrefixPlugin;
@@ -9,3 +9,7 @@ export declare enum MESSAGE_TYPE {
9
9
  stillOk = "still-ok",
10
10
  invalid = "invalid"
11
11
  }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
3
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
4
4
  exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
5
5
  exports.DEFAULT_OUTPUT_PATH = 'dist';
6
6
  exports.MFSU_NAME = 'MFSU';
@@ -13,3 +13,12 @@ var MESSAGE_TYPE;
13
13
  MESSAGE_TYPE["stillOk"] = "still-ok";
14
14
  MESSAGE_TYPE["invalid"] = "invalid";
15
15
  })(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
16
+ exports.DEFAULT_BROWSER_TARGETS = {
17
+ chrome: 80,
18
+ };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];
package/dist/dev.d.ts CHANGED
@@ -4,8 +4,11 @@ declare type IOpts = {
4
4
  afterMiddlewares?: any[];
5
5
  beforeMiddlewares?: any[];
6
6
  onDevCompileDone?: Function;
7
+ onProgress?: Function;
8
+ onMFSUProgress?: Function;
7
9
  port?: number;
8
10
  host?: string;
11
+ babelPreset?: any;
9
12
  chainWebpack?: Function;
10
13
  modifyWebpackConfig?: Function;
11
14
  beforeBabelPlugins?: any[];
@@ -16,5 +19,6 @@ declare type IOpts = {
16
19
  config: IConfig;
17
20
  entry: Record<string, string>;
18
21
  } & Pick<IConfigOpts, 'cache'>;
22
+ export declare function stripUndefined(obj: any): any;
19
23
  export declare function dev(opts: IOpts): Promise<void>;
20
24
  export {};
package/dist/dev.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.dev = void 0;
15
+ exports.dev = exports.stripUndefined = void 0;
16
16
  const mfsu_1 = require("@umijs/mfsu");
17
17
  const utils_1 = require("@umijs/utils");
18
18
  const path_1 = require("path");
@@ -21,9 +21,18 @@ const config_1 = require("./config/config");
21
21
  const constants_1 = require("./constants");
22
22
  const server_1 = require("./server/server");
23
23
  const types_1 = require("./types");
24
+ function stripUndefined(obj) {
25
+ Object.keys(obj).forEach((key) => {
26
+ if (obj[key] === undefined) {
27
+ delete obj[key];
28
+ }
29
+ });
30
+ return obj;
31
+ }
32
+ exports.stripUndefined = stripUndefined;
24
33
  function dev(opts) {
25
- var _a, _b, _c, _d;
26
- var _e;
34
+ var _a, _b, _c, _d, _e, _f;
35
+ var _g;
27
36
  return __awaiter(this, void 0, void 0, function* () {
28
37
  const enableMFSU = opts.config.mfsu !== false;
29
38
  let mfsu = null;
@@ -39,13 +48,20 @@ function dev(opts) {
39
48
  },
40
49
  mfName: (_c = opts.config.mfsu) === null || _c === void 0 ? void 0 : _c.mfName,
41
50
  runtimePublicPath: opts.config.runtimePublicPath,
42
- tmpBase: (0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
51
+ tmpBase: ((_d = opts.config.mfsu) === null || _d === void 0 ? void 0 : _d.cacheDirectory) ||
52
+ (0, path_1.join)(opts.cwd, 'node_modules/.cache/mfsu'),
53
+ onMFSUProgress: opts.onMFSUProgress,
43
54
  getCacheDependency() {
44
55
  var _a;
45
- return {
56
+ return stripUndefined({
46
57
  version: require('../package.json').version,
47
58
  esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
48
- };
59
+ alias: opts.config.alias,
60
+ externals: opts.config.externals,
61
+ theme: opts.config.theme,
62
+ runtimePublicPath: opts.config.runtimePublicPath,
63
+ publicPath: opts.config.publicPath,
64
+ });
49
65
  },
50
66
  });
51
67
  }
@@ -54,6 +70,7 @@ function dev(opts) {
54
70
  env: types_1.Env.development,
55
71
  entry: opts.entry,
56
72
  userConfig: opts.config,
73
+ babelPreset: opts.babelPreset,
57
74
  extraBabelPlugins: [
58
75
  ...(opts.beforeBabelPlugins || []),
59
76
  ...((mfsu === null || mfsu === void 0 ? void 0 : mfsu.getBabelPlugins()) || []),
@@ -78,12 +95,13 @@ function dev(opts) {
78
95
  hash: true,
79
96
  staticPathPrefix: mfsu_1.MF_DEP_PREFIX,
80
97
  name: constants_1.MFSU_NAME,
98
+ chainWebpack: (_e = opts.config.mfsu) === null || _e === void 0 ? void 0 : _e.chainWebpack,
81
99
  cache: {
82
- buildDependencies: (_d = opts.cache) === null || _d === void 0 ? void 0 : _d.buildDependencies,
100
+ buildDependencies: (_f = opts.cache) === null || _f === void 0 ? void 0 : _f.buildDependencies,
83
101
  cacheDirectory: (0, path_1.join)(opts.cwd, 'node_modules', '.cache', 'mfsu-deps'),
84
102
  },
85
103
  });
86
- (_e = webpackConfig.resolve).alias || (_e.alias = {});
104
+ (_g = webpackConfig.resolve).alias || (_g.alias = {});
87
105
  // TODO: REMOVE ME
88
106
  ['@umijs/utils/compiled/strip-ansi', 'react-error-overlay'].forEach((dep) => {
89
107
  // @ts-ignore
@@ -105,6 +123,7 @@ function dev(opts) {
105
123
  host: opts.host,
106
124
  afterMiddlewares: [...(opts.afterMiddlewares || [])],
107
125
  onDevCompileDone: opts.onDevCompileDone,
126
+ onProgress: opts.onProgress,
108
127
  });
109
128
  });
110
129
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- export type { RequestHandler } from '../compiled/express';
1
+ import type webpack from '../compiled/webpack';
2
+ export type { RequestHandler } from '@umijs/bundler-utils/compiled/express';
3
+ export type { Compiler, Stats } from '../compiled/webpack';
2
4
  export * from './build';
3
5
  export * from './config/config';
4
6
  export * from './dev';
5
7
  export * from './schema';
8
+ export { webpack };
package/dist/index.js CHANGED
@@ -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];
@@ -13,27 +13,23 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  const core_1 = require("@swc/core");
15
15
  const types_1 = require("../types");
16
- function getBaseOpts({ filename, targets = { chrome: '61' }, }) {
16
+ function getBaseOpts({ filename }) {
17
17
  const isTSFile = filename.endsWith('.ts');
18
18
  const isTypeScript = isTSFile || filename.endsWith('.tsx');
19
19
  const isDev = process.env.NODE_ENV === types_1.Env.development;
20
- const polyfillOpts = isDev
21
- ? {}
22
- : {
23
- env: {
24
- /**
25
- * need `@umijs/preset-umi/src/features/polyfill/swcPolyfill` config alias and provide polyfill
26
- */
27
- mode: 'usage',
28
- coreJs: 3,
29
- targets,
30
- },
31
- };
32
- const swcOpts = Object.assign(Object.assign({ module: {
20
+ /**
21
+ * Not use swc auto polyfill , depend on `preset-umi/features/polyfill/polyfill` imported polyfill file
22
+ *
23
+ * @issue https://github.com/swc-project/swc/issues/2607
24
+ * https://github.com/swc-project/swc/issues/1604
25
+ */
26
+ const swcOpts = {
27
+ module: {
33
28
  // @ts-ignore
34
29
  type: 'es6',
35
30
  ignoreDynamic: true,
36
- } }, polyfillOpts), { jsc: {
31
+ },
32
+ jsc: {
37
33
  parser: {
38
34
  syntax: isTypeScript ? 'typescript' : 'ecmascript',
39
35
  [isTypeScript ? 'tsx' : 'jsx']: !isTSFile,
@@ -50,18 +46,18 @@ function getBaseOpts({ filename, targets = { chrome: '61' }, }) {
50
46
  useBuiltins: true,
51
47
  },
52
48
  },
53
- } });
49
+ },
50
+ };
54
51
  return swcOpts;
55
52
  }
56
53
  function swcLoader(contents) {
57
54
  // 启用异步模式
58
55
  const callback = this.async();
59
56
  const loaderOpts = this.getOptions();
60
- const { sync = false, parseMap = false, targets } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap", "targets"]);
57
+ const { sync = false, parseMap = false } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap"]);
61
58
  const filename = this.resourcePath;
62
59
  const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
63
60
  filename,
64
- targets,
65
61
  })), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
66
62
  try {
67
63
  if (sync) {
@@ -38,9 +38,7 @@ class ESBuildCSSMinifyPlugin {
38
38
  transformAssets(compilation) {
39
39
  return __awaiter(this, void 0, void 0, function* () {
40
40
  const { options: { devtool }, } = compilation.compiler;
41
- const sourcemap = this.options.sourcemap === undefined
42
- ? devtool && devtool
43
- : this.options.sourcemap;
41
+ const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
44
42
  const assets = compilation.getAssets().filter((asset) => {
45
43
  return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
46
44
  });
@@ -0,0 +1,10 @@
1
+ import type { TransformOptions } from '@parcel/css';
2
+ import type { Compiler } from '../../compiled/webpack/types';
3
+ declare type MinifyPluginOpts = Omit<TransformOptions, 'filename' | 'code' | 'minify'>;
4
+ export declare class ParcelCSSMinifyPlugin {
5
+ private readonly options;
6
+ constructor(opts?: MinifyPluginOpts);
7
+ apply(compiler: Compiler): void;
8
+ private transformAssets;
9
+ }
10
+ export {};