@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,155 +1,177 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.addJavaScriptRules = void 0;
4
+ const mfsu_1 = require("@umijs/mfsu");
16
5
  const utils_1 = require("@umijs/utils");
6
+ const path_1 = require("path");
7
+ const webpack_1 = require("../../compiled/webpack");
17
8
  const constants_1 = require("../constants");
18
- const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
19
9
  const types_1 = require("../types");
20
10
  const depMatch_1 = require("../utils/depMatch");
21
- function addJavaScriptRules(opts) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const { config, userConfig, cwd, env, name } = opts;
24
- const isDev = opts.env === types_1.Env.development;
25
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name === constants_1.MFSU_NAME;
26
- const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
27
- const srcRules = [
28
- config.module
29
- .rule('src')
30
- .test(/\.(js|mjs)$/)
31
- .include.add([
32
- cwd,
33
- // import module out of cwd using APP_ROOT
34
- // issue: https://github.com/umijs/umi/issues/5594
35
- ...(process.env.APP_ROOT ? [process.cwd()] : []),
36
- ])
37
- .end()
38
- .exclude.add(/node_modules/)
39
- .end(),
40
- config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
41
- config.module
42
- .rule('extra-src')
43
- .test(/\.(js|mjs)$/)
44
- .include.add((path) => {
11
+ async function addJavaScriptRules(opts) {
12
+ var _a, _b;
13
+ const { config, userConfig, cwd, name } = opts;
14
+ const isDev = opts.env === types_1.Env.development;
15
+ const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
16
+ const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
17
+ const srcRules = [
18
+ config.module
19
+ .rule('src')
20
+ .test(/\.(js|mjs)$/)
21
+ .include.add([
22
+ cwd,
23
+ // import module out of cwd using APP_ROOT
24
+ // issue: https://github.com/umijs/umi/issues/5594
25
+ ...(process.env.APP_ROOT ? [process.cwd()] : []),
26
+ ])
27
+ .end()
28
+ .exclude.add(/node_modules/)
29
+ .end(),
30
+ config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
31
+ config.module
32
+ .rule('extra-src')
33
+ .test(/\.(js|mjs)$/)
34
+ .include.add([
35
+ // support extraBabelIncludes
36
+ ...opts.extraBabelIncludes.map((p) => {
37
+ // handle absolute path
38
+ if ((0, path_1.isAbsolute)(p)) {
39
+ return p;
40
+ }
41
+ // resolve npm package name
45
42
  try {
46
- if (path.includes('client/client'))
47
- return true;
48
- return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
43
+ if (p.startsWith('./')) {
44
+ return require.resolve(p, { paths: [cwd] });
45
+ }
46
+ return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
49
47
  }
50
48
  catch (e) {
51
- console.error(utils_1.chalk.red(e));
49
+ if (e.code === 'MODULE_NOT_FOUND') {
50
+ throw new Error('Cannot resolve extraBabelIncludes: ' + p);
51
+ }
52
52
  throw e;
53
53
  }
54
- })
55
- .end(),
56
- ];
57
- const depRules = [
58
- config.module
59
- .rule('dep')
60
- .test(/\.(js|mjs)$/)
61
- .include.add(/node_modules/)
62
- .end()
63
- .exclude.add((path) => {
54
+ }),
55
+ // support es5ImcompatibleVersions
56
+ (path) => {
64
57
  try {
58
+ // do src transform for bundler-webpack/client/client/client.js
59
+ if (path.includes('client/client/client'))
60
+ return true;
65
61
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
66
62
  }
67
63
  catch (e) {
68
64
  console.error(utils_1.chalk.red(e));
69
65
  throw e;
70
66
  }
71
- })
72
- .end(),
73
- ];
74
- // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
75
- const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
76
- srcRules.forEach((rule) => {
77
- if (srcTranspiler === types_1.Transpiler.babel) {
78
- rule
79
- .use('babel-loader')
80
- .loader(require.resolve('../../compiled/babel-loader'))
81
- .options({
82
- // Tell babel to guess the type, instead assuming all files are modules
83
- // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
84
- sourceType: 'unambiguous',
85
- babelrc: false,
86
- cacheDirectory: false,
87
- // process.env.BABEL_CACHE !== 'none'
88
- // ? join(cwd, `.umi/.cache/babel-loader`)
89
- // : false,
90
- targets: userConfig.targets,
91
- presets: [
92
- opts.babelPreset || [
93
- require.resolve('@umijs/babel-preset-umi'),
94
- {
95
- presetEnv: {},
96
- presetReact: {},
97
- presetTypeScript: {},
98
- pluginTransformRuntime: {},
99
- pluginLockCoreJS: {},
100
- pluginDynamicImportNode: false,
101
- pluginAutoCSSModules: userConfig.autoCSSModules,
102
- },
103
- ],
104
- ...opts.extraBabelPresets,
105
- ...(userConfig.extraBabelPresets || []).filter(Boolean),
106
- ],
107
- plugins: [
108
- useFastRefresh && require.resolve('react-refresh/babel'),
109
- ...opts.extraBabelPlugins,
110
- ...(userConfig.extraBabelPlugins || []),
111
- ].filter(Boolean),
112
- });
67
+ },
68
+ ])
69
+ .end(),
70
+ ];
71
+ if (userConfig.mdx) {
72
+ srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
73
+ }
74
+ const depRules = [
75
+ config.module
76
+ .rule('dep')
77
+ .test(/\.(js|mjs)$/)
78
+ .include.add(/node_modules/)
79
+ .end()
80
+ .exclude.add((path) => {
81
+ try {
82
+ return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
113
83
  }
114
- else if (srcTranspiler === types_1.Transpiler.swc) {
115
- // TODO: support javascript
116
- rule
117
- .use('swc-loader')
118
- .loader(require.resolve('../../compiled/swc-loader'))
119
- .options({
120
- jsc: {
121
- parser: {
122
- syntax: 'typescript',
123
- dynamicImport: true,
124
- tsx: true,
125
- },
126
- transform: {
127
- react: {
128
- runtime: 'automatic',
129
- pragma: 'React.createElement',
130
- pragmaFrag: 'React.Fragment',
131
- throwIfNamespace: true,
132
- development: env === types_1.Env.development,
133
- useBuiltins: true,
134
- },
135
- },
136
- },
137
- plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
138
- });
139
- }
140
- else {
141
- throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
142
- }
143
- });
144
- const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
145
- depRules.forEach((_rule) => {
146
- if (depTranspiler === types_1.Transpiler.none) {
147
- // noop
148
- }
149
- else {
150
- throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
84
+ catch (e) {
85
+ console.error(utils_1.chalk.red(e));
86
+ throw e;
151
87
  }
152
- });
88
+ })
89
+ .end(),
90
+ ];
91
+ // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
92
+ const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
93
+ srcRules.forEach((rule) => {
94
+ if (srcTranspiler === types_1.Transpiler.babel) {
95
+ rule
96
+ .use('babel-loader')
97
+ .loader(require.resolve('../../compiled/babel-loader'))
98
+ .options({
99
+ // Tell babel to guess the type, instead assuming all files are modules
100
+ // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
101
+ sourceType: 'unambiguous',
102
+ babelrc: false,
103
+ cacheDirectory: false,
104
+ // process.env.BABEL_CACHE !== 'none'
105
+ // ? join(cwd, `.umi/.cache/babel-loader`)
106
+ // : false,
107
+ targets: userConfig.targets,
108
+ presets: [
109
+ opts.babelPreset || [
110
+ require.resolve('@umijs/babel-preset-umi'),
111
+ {
112
+ presetEnv: {},
113
+ presetReact: {},
114
+ presetTypeScript: {},
115
+ pluginTransformRuntime: {},
116
+ pluginLockCoreJS: {},
117
+ pluginDynamicImportNode: false,
118
+ pluginAutoCSSModules: userConfig.autoCSSModules,
119
+ },
120
+ ],
121
+ ...opts.extraBabelPresets,
122
+ ...(userConfig.extraBabelPresets || []).filter(Boolean),
123
+ ],
124
+ plugins: [
125
+ useFastRefresh && require.resolve('react-refresh/babel'),
126
+ ...opts.extraBabelPlugins,
127
+ ...(userConfig.extraBabelPlugins || []),
128
+ ].filter(Boolean),
129
+ });
130
+ }
131
+ else if (srcTranspiler === types_1.Transpiler.swc) {
132
+ const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
133
+ rule
134
+ .use('swc-loader')
135
+ .loader(require.resolve('../loader/swc'))
136
+ .options({
137
+ plugin: (m) => new AutoCSSModule().visitProgram(m),
138
+ });
139
+ }
140
+ else if (srcTranspiler === types_1.Transpiler.esbuild) {
141
+ rule
142
+ .use('esbuild-loader')
143
+ .loader(mfsu_1.esbuildLoader)
144
+ .options({
145
+ target: isDev ? 'esnext' : 'es2015',
146
+ handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
147
+ });
148
+ // esbuild loader can not auto import `React`
149
+ config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
150
+ {
151
+ React: 'react',
152
+ },
153
+ ]);
154
+ }
155
+ else {
156
+ throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
157
+ }
158
+ });
159
+ if (userConfig.mdx) {
160
+ config.module
161
+ .rule('mdx')
162
+ .test(/\.mdx?$/)
163
+ .use('mdx-loader')
164
+ .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
165
+ .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
166
+ }
167
+ const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
168
+ depRules.forEach((_rule) => {
169
+ if (depTranspiler === types_1.Transpiler.none) {
170
+ // noop
171
+ }
172
+ else {
173
+ throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
174
+ }
153
175
  });
154
176
  }
155
177
  exports.addJavaScriptRules = addJavaScriptRules;
@@ -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 addManifestPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addManifestPlugin = void 0;
4
+ // @ts-ignore
5
+ const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
6
+ async function addManifestPlugin(opts) {
7
+ const { config, userConfig } = opts;
8
+ if (userConfig.manifest) {
9
+ config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
10
+ {
11
+ fileName: 'asset-manifest.json',
12
+ ...userConfig.manifest,
13
+ },
14
+ ]);
15
+ }
16
+ }
17
+ exports.addManifestPlugin = addManifestPlugin;
@@ -5,6 +5,7 @@ interface IOpts {
5
5
  userConfig: IConfig;
6
6
  cwd: string;
7
7
  env: Env;
8
+ useHash: boolean;
8
9
  }
9
10
  export declare function addMiniCSSExtractPlugin(opts: IOpts): Promise<void>;
10
11
  export {};
@@ -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
  };
@@ -15,20 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.addMiniCSSExtractPlugin = void 0;
16
7
  // @ts-ignore
17
8
  const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
18
- const types_1 = require("../types");
19
- function addMiniCSSExtractPlugin(opts) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const { config, userConfig, env } = opts;
22
- const hash = env !== types_1.Env.development && userConfig.hash ? '.[contenthash:8]' : '';
23
- if (!userConfig.styleLoader) {
24
- config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
25
- {
26
- filename: `[name]${hash}.css`,
27
- chunkFilename: `[name]${hash}.chunk.css`,
28
- ignoreOrder: true,
29
- },
30
- ]);
31
- }
32
- });
9
+ async function addMiniCSSExtractPlugin(opts) {
10
+ const { config, userConfig, useHash } = opts;
11
+ const hash = useHash ? '.[contenthash:8]' : '';
12
+ if (!userConfig.styleLoader) {
13
+ config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
14
+ {
15
+ filename: `[name]${hash}.css`,
16
+ chunkFilename: `[name]${hash}.chunk.css`,
17
+ ignoreOrder: true,
18
+ },
19
+ ]);
20
+ }
33
21
  }
34
22
  exports.addMiniCSSExtractPlugin = addMiniCSSExtractPlugin;
@@ -1,26 +1,18 @@
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.addNodePolyfill = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
- function addNodePolyfill(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config } = opts;
17
- const nodeLibs = require('node-libs-browser');
18
- config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
19
- {
20
- Buffer: ['buffer', 'Buffer'],
21
- },
22
- ]);
23
- config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
5
+ async function addNodePolyfill(opts) {
6
+ const { config } = opts;
7
+ const nodeLibs = require('node-libs-browser');
8
+ config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
9
+ {
10
+ Buffer: ['buffer', 'Buffer'],
11
+ process: nodeLibs['process'],
12
+ },
13
+ ]);
14
+ config.resolve.fallback.merge({
15
+ ...Object.keys(nodeLibs).reduce((memo, key) => {
24
16
  if (nodeLibs[key]) {
25
17
  memo[key] = nodeLibs[key];
26
18
  }
@@ -28,7 +20,9 @@ function addNodePolyfill(opts) {
28
20
  memo[key] = false;
29
21
  }
30
22
  return memo;
31
- }, {})), { http: false, https: false }));
23
+ }, {}),
24
+ http: false,
25
+ https: false,
32
26
  });
33
27
  }
34
28
  exports.addNodePolyfill = addNodePolyfill;
@@ -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,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addNodePrefixPlugin = void 0;
4
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
5
+ async function addNodePrefixPlugin(opts) {
6
+ const { config } = opts;
7
+ config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
8
+ /^node:/,
9
+ (resource) => {
10
+ resource.request = resource.request.replace(/^node:/, '');
11
+ },
12
+ ]);
13
+ }
14
+ exports.addNodePrefixPlugin = addNodePrefixPlugin;
@@ -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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.addProgressPlugin = void 0;
16
7
  const ProgressPlugin_1 = __importDefault(require("../plugins/ProgressPlugin"));
17
- function addProgressPlugin(opts) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const { config, name } = opts;
20
- config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
21
- {
22
- name,
23
- },
24
- ]);
25
- });
8
+ async function addProgressPlugin(opts) {
9
+ const { config, name } = opts;
10
+ config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
11
+ {
12
+ name,
13
+ },
14
+ ]);
26
15
  }
27
16
  exports.addProgressPlugin = addProgressPlugin;
@@ -1,32 +1,21 @@
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.applyPurgeCSSWebpackPlugin = void 0;
13
4
  const types_1 = require("../types");
14
- function applyPurgeCSSWebpackPlugin(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config, userConfig, cwd, env } = opts;
17
- config;
18
- userConfig;
19
- cwd;
20
- env;
21
- if (userConfig.purgeCSS && env === types_1.Env.production) {
22
- config
23
- .plugin('purgecss-webpack-plugin')
24
- .use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
25
- {
26
- paths: [],
27
- },
28
- ]);
29
- }
30
- });
5
+ async function applyPurgeCSSWebpackPlugin(opts) {
6
+ const { config, userConfig, cwd, env } = opts;
7
+ config;
8
+ userConfig;
9
+ cwd;
10
+ env;
11
+ if (userConfig.purgeCSS && env === types_1.Env.production) {
12
+ config
13
+ .plugin('purgecss-webpack-plugin')
14
+ .use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
15
+ {
16
+ paths: [],
17
+ },
18
+ ]);
19
+ }
31
20
  }
32
21
  exports.applyPurgeCSSWebpackPlugin = applyPurgeCSSWebpackPlugin;
@@ -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
  };
@@ -16,19 +7,17 @@ exports.addSpeedMeasureWebpackPlugin = void 0;
16
7
  // @ts-ignore
17
8
  const speed_measure_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/speed-measure-webpack-plugin"));
18
9
  const path_1 = require("path");
19
- function addSpeedMeasureWebpackPlugin(opts) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- let webpackConfig = opts.webpackConfig;
22
- if (process.env.SPEED_MEASURE) {
23
- const smpOption = process.env.SPEED_MEASURE === 'JSON'
24
- ? {
25
- outputFormat: 'json',
26
- outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
27
- }
28
- : { outputFormat: 'human', outputTarget: console.log };
29
- webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
30
- }
31
- return webpackConfig;
32
- });
10
+ async function addSpeedMeasureWebpackPlugin(opts) {
11
+ let webpackConfig = opts.webpackConfig;
12
+ if (process.env.SPEED_MEASURE) {
13
+ const smpOption = process.env.SPEED_MEASURE === 'JSON'
14
+ ? {
15
+ outputFormat: 'json',
16
+ outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
17
+ }
18
+ : { outputFormat: 'human', outputTarget: console.log };
19
+ webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
20
+ }
21
+ return webpackConfig;
33
22
  }
34
23
  exports.addSpeedMeasureWebpackPlugin = addSpeedMeasureWebpackPlugin;
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  cwd: string;
7
7
  env: Env;
8
8
  browsers: any;
9
+ staticPathPrefix: string;
9
10
  }
10
11
  export declare function addSVGRules(opts: IOpts): Promise<void>;
11
12
  export {};