@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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,6 +8,7 @@ const path_1 = require("path");
17
8
  const webpack_1 = __importDefault(require("../../compiled/webpack"));
18
9
  const webpack_5_chain_1 = __importDefault(require("../../compiled/webpack-5-chain"));
19
10
  const constants_1 = require("../constants");
11
+ const RuntimePublicPathPlugin_1 = require("../plugins/RuntimePublicPathPlugin");
20
12
  const types_1 = require("../types");
21
13
  const browsersList_1 = require("../utils/browsersList");
22
14
  const assetRules_1 = require("./assetRules");
@@ -25,154 +17,202 @@ const compressPlugin_1 = require("./compressPlugin");
25
17
  const copyPlugin_1 = require("./copyPlugin");
26
18
  const cssRules_1 = require("./cssRules");
27
19
  const definePlugin_1 = require("./definePlugin");
20
+ const detectDeadCodePlugin_1 = require("./detectDeadCodePlugin");
28
21
  const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
22
+ const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
23
+ const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
29
24
  const ignorePlugin_1 = require("./ignorePlugin");
30
25
  const javaScriptRules_1 = require("./javaScriptRules");
26
+ const manifestPlugin_1 = require("./manifestPlugin");
31
27
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
32
28
  const nodePolyfill_1 = require("./nodePolyfill");
33
29
  const progressPlugin_1 = require("./progressPlugin");
34
30
  const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
35
31
  const svgRules_1 = require("./svgRules");
36
- function getConfig(opts) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const { userConfig } = opts;
39
- const isDev = opts.env === types_1.Env.development;
40
- const config = new webpack_5_chain_1.default();
41
- userConfig.targets = userConfig.targets || {
42
- chrome: 80,
43
- };
44
- const applyOpts = {
45
- name: opts.name,
46
- config,
47
- userConfig,
48
- cwd: opts.cwd,
49
- env: opts.env,
50
- babelPreset: opts.babelPreset,
51
- extraBabelPlugins: opts.extraBabelPlugins || [],
52
- extraBabelPresets: opts.extraBabelPresets || [],
53
- browsers: (0, browsersList_1.getBrowsersList)({
54
- targets: userConfig.targets,
55
- }),
56
- staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
57
- };
58
- // mode
59
- config.mode(opts.env);
60
- config.stats('none');
61
- // entry
62
- Object.keys(opts.entry).forEach((key) => {
63
- const entry = config.entry(key);
64
- // TODO: runtimePublicPath
65
- if (isDev && opts.hmr) {
66
- entry.add(require.resolve('../../client/client/client'));
67
- }
68
- entry.add(opts.entry[key]);
69
- });
70
- // devtool
71
- config.devtool(isDev
72
- ? userConfig.devtool === false
73
- ? false
74
- : userConfig.devtool || constants_1.DEFAULT_DEVTOOL
75
- : userConfig.devtool);
76
- // output
77
- const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
78
- const useHash = opts.hash || (userConfig.hash && !isDev);
79
- const disableCompress = process.env.COMPRESS === 'none';
80
- config.output
81
- .path(absOutputPath)
82
- .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
83
- .chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].js`)
84
- .publicPath(userConfig.publicPath || '/')
85
- .pathinfo(isDev || disableCompress);
86
- // resolve
87
- // prettier-ignore
88
- config.resolve
89
- .set('symlinks', true)
90
- .modules
91
- .add('node_modules')
92
- .end()
93
- .alias
94
- .merge(userConfig.alias || {})
95
- .end()
96
- .extensions
97
- .merge([
98
- '.wasm',
99
- '.mjs',
100
- '.js',
101
- '.jsx',
102
- '.ts',
103
- '.tsx',
104
- '.json'
105
- ])
106
- .end();
107
- // externals
108
- config.externals(userConfig.externals || []);
109
- // target
110
- config.target(['web', 'es5']);
111
- // experiments
112
- config.experiments({
113
- topLevelAwait: true,
114
- outputModule: !!userConfig.esm,
115
- });
116
- // node polyfill
117
- yield (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
118
- // rules
119
- yield (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
120
- yield (0, cssRules_1.addCSSRules)(applyOpts);
121
- yield (0, assetRules_1.addAssetRules)(applyOpts);
122
- yield (0, svgRules_1.addSVGRules)(applyOpts);
123
- // plugins
124
- // mini-css-extract-plugin
125
- yield (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
126
- // ignoreMomentLocale
127
- yield (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
128
- // define
129
- yield (0, definePlugin_1.addDefinePlugin)(applyOpts);
130
- // fast refresh
131
- yield (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
132
- // progress
133
- yield (0, progressPlugin_1.addProgressPlugin)(applyOpts);
134
- // copy
135
- yield (0, copyPlugin_1.addCopyPlugin)(applyOpts);
136
- // TODO: friendly-error
137
- // TODO: manifest
138
- // hmr
32
+ async function getConfig(opts) {
33
+ const { userConfig } = opts;
34
+ const isDev = opts.env === types_1.Env.development;
35
+ const config = new webpack_5_chain_1.default();
36
+ userConfig.targets || (userConfig.targets = constants_1.DEFAULT_BROWSER_TARGETS);
37
+ const useHash = !!(opts.hash || (userConfig.hash && !isDev));
38
+ const applyOpts = {
39
+ name: opts.name,
40
+ config,
41
+ userConfig,
42
+ cwd: opts.cwd,
43
+ env: opts.env,
44
+ babelPreset: opts.babelPreset,
45
+ extraBabelPlugins: opts.extraBabelPlugins || [],
46
+ extraBabelPresets: opts.extraBabelPresets || [],
47
+ extraBabelIncludes: opts.extraBabelIncludes || [],
48
+ extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
49
+ browsers: (0, browsersList_1.getBrowsersList)({
50
+ targets: userConfig.targets,
51
+ }),
52
+ useHash,
53
+ staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
54
+ };
55
+ // mode
56
+ config.mode(opts.env);
57
+ config.stats('none');
58
+ // entry
59
+ Object.keys(opts.entry).forEach((key) => {
60
+ const entry = config.entry(key);
139
61
  if (isDev && opts.hmr) {
140
- config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
141
- }
142
- // compress
143
- yield (0, compressPlugin_1.addCompressPlugin)(applyOpts);
144
- // purgecss
145
- // await applyPurgeCSSWebpackPlugin(applyOpts);
146
- // analyzer
147
- if (opts.analyze) {
148
- yield (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
149
- }
150
- // chain webpack
151
- if (opts.chainWebpack) {
152
- yield opts.chainWebpack(config, {
153
- env: opts.env,
154
- webpack: webpack_1.default,
155
- });
156
- }
157
- if (userConfig.chainWebpack) {
158
- yield userConfig.chainWebpack(config, {
159
- env: opts.env,
160
- webpack: webpack_1.default,
161
- });
62
+ entry.add(require.resolve('../../client/client/client'));
162
63
  }
163
- let webpackConfig = config.toConfig();
164
- // speed measure
165
- // TODO: mini-css-extract-plugin 报错
166
- webpackConfig = yield (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
167
- webpackConfig,
64
+ entry.add(opts.entry[key]);
65
+ });
66
+ // devtool
67
+ config.devtool(isDev
68
+ ? userConfig.devtool === false
69
+ ? false
70
+ : userConfig.devtool || constants_1.DEFAULT_DEVTOOL
71
+ : userConfig.devtool);
72
+ // output
73
+ const absOutputPath = (0, path_1.join)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
74
+ const disableCompress = process.env.COMPRESS === 'none';
75
+ config.output
76
+ .path(absOutputPath)
77
+ .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
78
+ .chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].js`)
79
+ .publicPath(userConfig.publicPath || 'auto')
80
+ .pathinfo(isDev || disableCompress);
81
+ // resolve
82
+ // prettier-ignore
83
+ config.resolve
84
+ .set('symlinks', true)
85
+ .modules
86
+ .add('node_modules')
87
+ .end()
88
+ .alias
89
+ .merge(userConfig.alias || {})
90
+ .end()
91
+ .extensions
92
+ .merge([
93
+ '.wasm',
94
+ '.mjs',
95
+ '.js',
96
+ '.jsx',
97
+ '.ts',
98
+ '.tsx',
99
+ '.json'
100
+ ])
101
+ .end();
102
+ // externals
103
+ config.externals(userConfig.externals || []);
104
+ // target
105
+ config.target(['web', 'es5']);
106
+ // experiments
107
+ config.experiments({
108
+ topLevelAwait: true,
109
+ outputModule: !!userConfig.esm,
110
+ });
111
+ // node polyfill
112
+ await (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
113
+ // rules
114
+ await (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
115
+ await (0, cssRules_1.addCSSRules)(applyOpts);
116
+ await (0, assetRules_1.addAssetRules)(applyOpts);
117
+ await (0, svgRules_1.addSVGRules)(applyOpts);
118
+ // plugins
119
+ // mini-css-extract-plugin
120
+ await (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
121
+ // ignoreMomentLocale
122
+ await (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
123
+ // define
124
+ await (0, definePlugin_1.addDefinePlugin)(applyOpts);
125
+ // fast refresh
126
+ await (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
127
+ // progress
128
+ await (0, progressPlugin_1.addProgressPlugin)(applyOpts);
129
+ // detect-dead-code-plugin
130
+ await (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
131
+ // fork-ts-checker
132
+ await (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
133
+ // copy
134
+ await (0, copyPlugin_1.addCopyPlugin)(applyOpts);
135
+ // manifest
136
+ await (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
137
+ // hmr
138
+ if (isDev && opts.hmr) {
139
+ config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
140
+ }
141
+ // compress
142
+ await (0, compressPlugin_1.addCompressPlugin)(applyOpts);
143
+ // purgecss
144
+ // await applyPurgeCSSWebpackPlugin(applyOpts);
145
+ // handle HarmonyLinkingError
146
+ await (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
147
+ // remove node: prefix
148
+ // disable for performance
149
+ // await addNodePrefixPlugin(applyOpts);
150
+ // runtimePublicPath
151
+ if (userConfig.runtimePublicPath) {
152
+ config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
153
+ }
154
+ // cache
155
+ if (opts.cache) {
156
+ config.cache({
157
+ type: 'filesystem',
158
+ version: require('../../package.json').version,
159
+ buildDependencies: {
160
+ config: opts.cache.buildDependencies || [],
161
+ },
162
+ cacheDirectory: opts.cache.cacheDirectory ||
163
+ // 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
164
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'bundler-webpack'),
168
165
  });
169
- if (opts.modifyWebpackConfig) {
170
- webpackConfig = yield opts.modifyWebpackConfig(webpackConfig, {
171
- env: opts.env,
172
- webpack: webpack_1.default,
166
+ // tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
167
+ // 使用 immutablePaths 避免 node_modules 的内容被写入缓存
168
+ // tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
169
+ // ref: smallfish
170
+ if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
171
+ config.snapshot({
172
+ immutablePaths: [
173
+ opts.cache.absNodeModulesPath ||
174
+ (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules'),
175
+ ],
173
176
  });
174
177
  }
175
- return webpackConfig;
178
+ config.infrastructureLogging({
179
+ level: 'error',
180
+ ...(process.env.WEBPACK_FS_CACHE_DEBUG
181
+ ? {
182
+ debug: /webpack\.cache/,
183
+ }
184
+ : {}),
185
+ });
186
+ }
187
+ // analyzer
188
+ if (opts.analyze) {
189
+ await (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
190
+ }
191
+ // chain webpack
192
+ if (opts.chainWebpack) {
193
+ await opts.chainWebpack(config, {
194
+ env: opts.env,
195
+ webpack: webpack_1.default,
196
+ });
197
+ }
198
+ if (userConfig.chainWebpack) {
199
+ await userConfig.chainWebpack(config, {
200
+ env: opts.env,
201
+ webpack: webpack_1.default,
202
+ });
203
+ }
204
+ let webpackConfig = config.toConfig();
205
+ // speed measure
206
+ // TODO: mini-css-extract-plugin 报错
207
+ webpackConfig = await (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
208
+ webpackConfig,
176
209
  });
210
+ if (opts.modifyWebpackConfig) {
211
+ webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
212
+ env: opts.env,
213
+ webpack: webpack_1.default,
214
+ });
215
+ }
216
+ return webpackConfig;
177
217
  }
178
218
  exports.getConfig = getConfig;
@@ -1,49 +1,38 @@
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.addCopyPlugin = void 0;
13
4
  const fs_1 = require("fs");
14
5
  const path_1 = require("path");
15
- function addCopyPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config, userConfig, cwd } = opts;
18
- const copyPatterns = [
19
- (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
20
- from: (0, path_1.join)(cwd, 'public'),
21
- },
22
- ...(userConfig.copy
23
- ? userConfig.copy.map((item) => {
24
- if (typeof item === 'string') {
25
- return {
26
- from: (0, path_1.join)(cwd, item),
27
- to: item,
28
- };
29
- }
6
+ async function addCopyPlugin(opts) {
7
+ const { config, userConfig, cwd } = opts;
8
+ const copyPatterns = [
9
+ (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
10
+ from: (0, path_1.join)(cwd, 'public'),
11
+ },
12
+ ...(userConfig.copy
13
+ ? userConfig.copy.map((item) => {
14
+ if (typeof item === 'string') {
30
15
  return {
31
- // 相对于 process.cwd,所以这里需要使用绝对路径
32
- from: (0, path_1.join)(cwd, item.from),
33
- to: item.to,
16
+ from: (0, path_1.join)(cwd, item),
17
+ to: item,
34
18
  };
35
- })
36
- : []),
37
- ].filter(Boolean);
38
- if (copyPatterns.length) {
39
- config
40
- .plugin('copy')
41
- .use(require('@umijs/bundler-webpack/compiled/copy-webpack-plugin'), [
42
- {
43
- patterns: copyPatterns,
44
- },
45
- ]);
46
- }
47
- });
19
+ }
20
+ return {
21
+ // 相对于 process.cwd,所以这里需要使用绝对路径
22
+ from: (0, path_1.join)(cwd, item.from),
23
+ to: item.to,
24
+ };
25
+ })
26
+ : []),
27
+ ].filter(Boolean);
28
+ if (copyPatterns.length) {
29
+ config
30
+ .plugin('copy')
31
+ .use(require('@umijs/bundler-webpack/compiled/copy-webpack-plugin'), [
32
+ {
33
+ patterns: copyPatterns,
34
+ },
35
+ ]);
36
+ }
48
37
  }
49
38
  exports.addCopyPlugin = addCopyPlugin;
@@ -1,98 +1,108 @@
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.addCSSRules = void 0;
13
- function addCSSRules(opts) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { config, userConfig } = opts;
16
- const rulesConfig = [
17
- { name: 'css', test: /\.css(\?.*)?$/ },
18
- {
19
- name: 'less',
20
- test: /\.less(\?.*)?$/,
21
- loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
22
- loaderOptions: {
23
- implementation: require.resolve('@umijs/bundler-webpack/compiled/less'),
24
- lessOptions: Object.assign({ modifyVars: userConfig.theme, javascriptEnabled: true }, userConfig.lessLoader),
4
+ async function addCSSRules(opts) {
5
+ const { config, userConfig } = opts;
6
+ const rulesConfig = [
7
+ { name: 'css', test: /\.css(\?.*)?$/ },
8
+ {
9
+ name: 'less',
10
+ test: /\.less(\?.*)?$/,
11
+ loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
12
+ loaderOptions: {
13
+ implementation: require.resolve('@umijs/bundler-utils/compiled/less'),
14
+ lessOptions: {
15
+ modifyVars: userConfig.theme,
16
+ javascriptEnabled: true,
17
+ ...userConfig.lessLoader,
25
18
  },
26
19
  },
20
+ },
21
+ {
22
+ name: 'sass',
23
+ test: /\.(sass|scss)(\?.*)?$/,
24
+ loader: require.resolve('@umijs/bundler-webpack/compiled/sass-loader'),
25
+ loaderOptions: userConfig.sassLoader || {},
26
+ },
27
+ ];
28
+ for (const { name, test, loader, loaderOptions } of rulesConfig) {
29
+ const rule = config.module.rule(name);
30
+ const nestRulesConfig = [
31
+ userConfig.autoCSSModules && {
32
+ rule: rule
33
+ .test(test)
34
+ .oneOf('css-modules')
35
+ .resourceQuery(/modules/),
36
+ isCSSModules: true,
37
+ },
27
38
  {
28
- name: 'sass',
29
- test: /\.(sass|scss)(\?.*)?$/,
30
- loader: require.resolve('@umijs/bundler-webpack/compiled/sass-loader'),
31
- loaderOptions: userConfig.sassLoader || {},
39
+ rule: rule.test(test).oneOf('css').sideEffects(true),
40
+ isCSSModules: false,
32
41
  },
33
- ];
34
- for (const { name, test, loader, loaderOptions } of rulesConfig) {
35
- const rule = config.module.rule(name);
36
- const nestRulesConfig = [
37
- userConfig.autoCSSModules && {
38
- rule: rule
39
- .test(test)
40
- .oneOf('css-modules')
41
- .resourceQuery(/modules/),
42
- isCSSModules: true,
43
- },
44
- {
45
- rule: rule.test(test).oneOf('css').sideEffects(true),
46
- isCSSModules: false,
47
- },
48
- ].filter(Boolean);
49
- // @ts-ignore
50
- for (const { rule, isCSSModules } of nestRulesConfig) {
51
- if (userConfig.styleLoader) {
52
- rule
53
- .use('style-loader')
54
- .loader(require.resolve('@umijs/bundler-webpack/compiled/style-loader'))
55
- .options(Object.assign({ base: 0, esModule: true }, userConfig.styleLoader));
56
- }
57
- else {
58
- rule
59
- .use('mini-css-extract-plugin-loader')
60
- .loader(require.resolve('@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader'))
61
- .options({
62
- publicPath: './',
63
- emit: true,
64
- esModule: true,
65
- });
66
- }
42
+ ].filter(Boolean);
43
+ // @ts-ignore
44
+ for (const { rule, isCSSModules } of nestRulesConfig) {
45
+ if (userConfig.styleLoader) {
67
46
  rule
68
- .use('css-loader')
69
- .loader(require.resolve('css-loader'))
70
- .options(Object.assign(Object.assign({ importLoaders: 1, esModule: true, url: true, import: true }, (isCSSModules
71
- ? {
72
- modules: Object.assign({ localIdentName: '[local]___[hash:base64:5]' }, userConfig.cssLoaderModules),
73
- }
74
- : {})), userConfig.cssLoader));
47
+ .use('style-loader')
48
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/style-loader'))
49
+ .options({ base: 0, esModule: true, ...userConfig.styleLoader });
50
+ }
51
+ else {
75
52
  rule
76
- .use('postcss-loader')
77
- .loader(require.resolve('@umijs/bundler-webpack/compiled/postcss-loader'))
53
+ .use('mini-css-extract-plugin')
54
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader'))
78
55
  .options({
79
- postcssOptions: Object.assign({ ident: 'postcss', plugins: [
80
- require('@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes'),
81
- require('postcss-preset-env')({
82
- browsers: opts.browsers,
83
- autoprefixer: Object.assign({ flexbox: 'no-2009' }, userConfig.autoprefixer),
84
- stage: 3,
85
- }),
86
- ].concat(userConfig.extraPostCSSPlugins || []) }, userConfig.postcssLoader),
56
+ publicPath: './',
57
+ emit: true,
58
+ esModule: true,
87
59
  });
88
- if (loader) {
89
- rule
90
- .use(loader)
91
- .loader(typeof loader === 'string' ? require.resolve(loader) : loader)
92
- .options(loaderOptions || {});
93
- }
60
+ }
61
+ rule
62
+ .use('css-loader')
63
+ .loader(require.resolve('css-loader'))
64
+ .options({
65
+ importLoaders: 1,
66
+ esModule: true,
67
+ url: true,
68
+ import: true,
69
+ ...(isCSSModules
70
+ ? {
71
+ modules: {
72
+ localIdentName: '[local]___[hash:base64:5]',
73
+ ...userConfig.cssLoaderModules,
74
+ },
75
+ }
76
+ : {}),
77
+ ...userConfig.cssLoader,
78
+ });
79
+ rule
80
+ .use('postcss-loader')
81
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/postcss-loader'))
82
+ .options({
83
+ postcssOptions: {
84
+ ident: 'postcss',
85
+ plugins: [
86
+ require('@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes'),
87
+ require('postcss-preset-env')({
88
+ browsers: opts.browsers,
89
+ autoprefixer: {
90
+ flexbox: 'no-2009',
91
+ ...userConfig.autoprefixer,
92
+ },
93
+ stage: 3,
94
+ }),
95
+ ].concat(userConfig.extraPostCSSPlugins || []),
96
+ ...userConfig.postcssLoader,
97
+ },
98
+ });
99
+ if (loader) {
100
+ rule
101
+ .use(loader)
102
+ .loader(typeof loader === 'string' ? require.resolve(loader) : loader)
103
+ .options(loaderOptions || {});
94
104
  }
95
105
  }
96
- });
106
+ }
97
107
  }
98
108
  exports.addCSSRules = addCSSRules;