@umijs/bundler-webpack 4.0.6 → 4.0.9

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 (69) hide show
  1. package/{dist → client}/client/client.d.ts +0 -0
  2. package/client/client/client.js +295 -194
  3. package/client/constants.d.ts +15 -0
  4. package/client/constants.js +28 -19
  5. package/client/utils/formatWebpackMessages.d.ts +12 -0
  6. package/client/utils/formatWebpackMessages.js +68 -86
  7. package/dist/build.d.ts +1 -1
  8. package/dist/build.js +105 -61
  9. package/dist/cli.js +77 -69
  10. package/dist/config/_sampleFeature.js +33 -9
  11. package/dist/config/assetRules.js +45 -36
  12. package/dist/config/bundleAnalyzerPlugin.js +39 -17
  13. package/dist/config/compressPlugin.js +113 -95
  14. package/dist/config/config.d.ts +1 -0
  15. package/dist/config/config.js +204 -215
  16. package/dist/config/copyPlugin.js +59 -40
  17. package/dist/config/cssRules.js +136 -131
  18. package/dist/config/definePlugin.d.ts +1 -0
  19. package/dist/config/definePlugin.js +71 -31
  20. package/dist/config/detectDeadCode.js +120 -108
  21. package/dist/config/detectDeadCodePlugin.js +78 -63
  22. package/dist/config/fastRefreshPlugin.js +39 -20
  23. package/dist/config/forkTSCheckerPlugin.js +38 -19
  24. package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
  25. package/dist/config/ignorePlugin.js +38 -14
  26. package/dist/config/javaScriptRules.js +147 -173
  27. package/dist/config/manifestPlugin.js +51 -15
  28. package/dist/config/miniCSSExtractPlugin.js +42 -22
  29. package/dist/config/nodePolyfill.js +65 -26
  30. package/dist/config/nodePrefixPlugin.js +36 -12
  31. package/dist/config/progressPlugin.js +37 -13
  32. package/dist/config/purgecssWebpackPlugin.js +41 -19
  33. package/dist/config/speedMeasureWebpackPlugin.js +41 -20
  34. package/dist/config/ssrPlugin.js +83 -63
  35. package/dist/config/svgRules.js +74 -46
  36. package/dist/constants.js +57 -22
  37. package/dist/dev.d.ts +1 -1
  38. package/dist/dev.js +170 -129
  39. package/dist/index.js +22 -20
  40. package/dist/loader/svgr.js +73 -54
  41. package/dist/loader/swc.js +110 -69
  42. package/dist/parcelCSS.js +31 -27
  43. package/dist/plugins/ProgressPlugin.js +66 -43
  44. package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
  45. package/dist/plugins/_SamplePlugin.js +39 -14
  46. package/dist/requireHook.js +37 -27
  47. package/dist/schema.js +120 -95
  48. package/dist/server/server.d.ts +0 -1
  49. package/dist/server/server.js +214 -184
  50. package/dist/server/ws.d.ts +0 -2
  51. package/dist/server/ws.js +63 -38
  52. package/dist/swcPlugins/autoCSSModules.js +50 -31
  53. package/dist/swcPlugins/changeImportFromString.js +31 -9
  54. package/dist/swcPlugins/lockCoreJS.js +44 -20
  55. package/dist/types.d.ts +2 -1
  56. package/dist/types.js +61 -30
  57. package/dist/utils/browsersList.js +31 -8
  58. package/dist/utils/depMatch.js +63 -39
  59. package/dist/utils/formatWebpackMessages.js +93 -91
  60. package/dist/utils/getEsBuildTarget.js +32 -10
  61. package/package.json +12 -16
  62. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +0 -21
  63. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  64. package/compiled/fork-ts-checker-webpack-plugin/index.js +0 -42
  65. package/compiled/fork-ts-checker-webpack-plugin/package.json +0 -1
  66. package/compiled/react-refresh/LICENSE +0 -21
  67. package/compiled/react-refresh/index.js +0 -21
  68. package/compiled/react-refresh/package.json +0 -1
  69. package/dist/client/client.js +0 -245
@@ -1,223 +1,212 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __export = (target, all) => {
22
+ for (var name in all)
23
+ __defProp(target, name, { get: all[name], enumerable: true });
4
24
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfig = void 0;
7
- const path_1 = require("path");
8
- const webpack_1 = __importDefault(require("../../compiled/webpack"));
9
- const webpack_5_chain_1 = __importDefault(require("../../compiled/webpack-5-chain"));
10
- const constants_1 = require("../constants");
11
- const RuntimePublicPathPlugin_1 = require("../plugins/RuntimePublicPathPlugin");
12
- const types_1 = require("../types");
13
- const browsersList_1 = require("../utils/browsersList");
14
- const assetRules_1 = require("./assetRules");
15
- const bundleAnalyzerPlugin_1 = require("./bundleAnalyzerPlugin");
16
- const compressPlugin_1 = require("./compressPlugin");
17
- const copyPlugin_1 = require("./copyPlugin");
18
- const cssRules_1 = require("./cssRules");
19
- const definePlugin_1 = require("./definePlugin");
20
- const detectDeadCodePlugin_1 = require("./detectDeadCodePlugin");
21
- const fastRefreshPlugin_1 = require("./fastRefreshPlugin");
22
- const forkTSCheckerPlugin_1 = require("./forkTSCheckerPlugin");
23
- const harmonyLinkingErrorPlugin_1 = require("./harmonyLinkingErrorPlugin");
24
- const ignorePlugin_1 = require("./ignorePlugin");
25
- const javaScriptRules_1 = require("./javaScriptRules");
26
- const manifestPlugin_1 = require("./manifestPlugin");
27
- const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
28
- const nodePolyfill_1 = require("./nodePolyfill");
29
- const progressPlugin_1 = require("./progressPlugin");
30
- const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
31
- const ssrPlugin_1 = __importDefault(require("./ssrPlugin"));
32
- const svgRules_1 = require("./svgRules");
25
+ var __copyProps = (to, from, except, desc) => {
26
+ if (from && typeof from === "object" || typeof from === "function") {
27
+ for (let key of __getOwnPropNames(from))
28
+ if (!__hasOwnProp.call(to, key) && key !== except)
29
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
+ }
31
+ return to;
32
+ };
33
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+
36
+ // config.ts
37
+ var config_exports = {};
38
+ __export(config_exports, {
39
+ getConfig: () => getConfig
40
+ });
41
+ module.exports = __toCommonJS(config_exports);
42
+ var import_case_sensitive_paths_webpack_plugin = __toESM(require("@umijs/case-sensitive-paths-webpack-plugin"));
43
+ var import_utils = require("@umijs/utils");
44
+ var import_path = require("path");
45
+ var import_webpack = __toESM(require("../../compiled/webpack"));
46
+ var import_webpack_5_chain = __toESM(require("../../compiled/webpack-5-chain"));
47
+ var import_constants = require("../constants");
48
+ var import_RuntimePublicPathPlugin = require("../plugins/RuntimePublicPathPlugin");
49
+ var import_types = require("../types");
50
+ var import_browsersList = require("../utils/browsersList");
51
+ var import_assetRules = require("./assetRules");
52
+ var import_bundleAnalyzerPlugin = require("./bundleAnalyzerPlugin");
53
+ var import_compressPlugin = require("./compressPlugin");
54
+ var import_copyPlugin = require("./copyPlugin");
55
+ var import_cssRules = require("./cssRules");
56
+ var import_definePlugin = require("./definePlugin");
57
+ var import_detectDeadCodePlugin = require("./detectDeadCodePlugin");
58
+ var import_fastRefreshPlugin = require("./fastRefreshPlugin");
59
+ var import_forkTSCheckerPlugin = require("./forkTSCheckerPlugin");
60
+ var import_harmonyLinkingErrorPlugin = require("./harmonyLinkingErrorPlugin");
61
+ var import_ignorePlugin = require("./ignorePlugin");
62
+ var import_javaScriptRules = require("./javaScriptRules");
63
+ var import_manifestPlugin = require("./manifestPlugin");
64
+ var import_miniCSSExtractPlugin = require("./miniCSSExtractPlugin");
65
+ var import_nodePolyfill = require("./nodePolyfill");
66
+ var import_progressPlugin = require("./progressPlugin");
67
+ var import_speedMeasureWebpackPlugin = require("./speedMeasureWebpackPlugin");
68
+ var import_ssrPlugin = __toESM(require("./ssrPlugin"));
69
+ var import_svgRules = require("./svgRules");
33
70
  async function getConfig(opts) {
34
- const { userConfig } = opts;
35
- const isDev = opts.env === types_1.Env.development;
36
- const config = new webpack_5_chain_1.default();
37
- userConfig.targets || (userConfig.targets = constants_1.DEFAULT_BROWSER_TARGETS);
38
- const useHash = !!(opts.hash || (userConfig.hash && !isDev));
39
- const applyOpts = {
40
- name: opts.name,
41
- config,
42
- userConfig,
43
- cwd: opts.cwd,
44
- env: opts.env,
45
- babelPreset: opts.babelPreset,
46
- extraBabelPlugins: opts.extraBabelPlugins || [],
47
- extraBabelPresets: opts.extraBabelPresets || [],
48
- extraBabelIncludes: opts.extraBabelIncludes || [],
49
- extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
50
- browsers: (0, browsersList_1.getBrowsersList)({
51
- targets: userConfig.targets,
52
- }),
53
- useHash,
54
- staticPathPrefix: opts.staticPathPrefix !== undefined ? opts.staticPathPrefix : 'static/',
55
- };
56
- // mode
57
- config.mode(opts.env);
58
- config.stats('none');
59
- // entry
60
- Object.keys(opts.entry).forEach((key) => {
61
- const entry = config.entry(key);
62
- if (isDev && opts.hmr) {
63
- entry.add(require.resolve('../../client/client/client'));
64
- }
65
- entry.add(opts.entry[key]);
66
- });
67
- // devtool
68
- config.devtool(isDev
69
- ? userConfig.devtool === false
70
- ? false
71
- : userConfig.devtool || constants_1.DEFAULT_DEVTOOL
72
- : userConfig.devtool);
73
- // output
74
- const absOutputPath = (0, path_1.resolve)(opts.cwd, userConfig.outputPath || constants_1.DEFAULT_OUTPUT_PATH);
75
- const disableCompress = process.env.COMPRESS === 'none';
76
- config.output
77
- .path(absOutputPath)
78
- .filename(useHash ? `[name].[contenthash:8].js` : `[name].js`)
79
- .chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`)
80
- .publicPath(userConfig.publicPath || 'auto')
81
- .pathinfo(isDev || disableCompress)
82
- .set('assetModuleFilename', `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`);
83
- // resolve
84
- // prettier-ignore
85
- config.resolve
86
- .set('symlinks', true)
87
- .modules
88
- .add('node_modules')
89
- .end()
90
- .alias
91
- .merge(userConfig.alias || {})
92
- .end()
93
- .extensions
94
- .merge([
95
- '.wasm',
96
- '.mjs',
97
- '.js',
98
- '.jsx',
99
- '.ts',
100
- '.tsx',
101
- '.json'
102
- ])
103
- .end();
104
- // externals
105
- config.externals(userConfig.externals || []);
106
- // target
107
- config.target(['web', 'es5']);
108
- // experiments
109
- config.experiments({
110
- topLevelAwait: true,
111
- outputModule: !!userConfig.esm,
112
- });
113
- // node polyfill
114
- await (0, nodePolyfill_1.addNodePolyfill)(applyOpts);
115
- // rules
116
- await (0, javaScriptRules_1.addJavaScriptRules)(applyOpts);
117
- await (0, cssRules_1.addCSSRules)(applyOpts);
118
- await (0, assetRules_1.addAssetRules)(applyOpts);
119
- await (0, svgRules_1.addSVGRules)(applyOpts);
120
- // plugins
121
- // mini-css-extract-plugin
122
- await (0, miniCSSExtractPlugin_1.addMiniCSSExtractPlugin)(applyOpts);
123
- // ignoreMomentLocale
124
- await (0, ignorePlugin_1.addIgnorePlugin)(applyOpts);
125
- // define
126
- await (0, definePlugin_1.addDefinePlugin)(applyOpts);
127
- // fast refresh
128
- await (0, fastRefreshPlugin_1.addFastRefreshPlugin)(applyOpts);
129
- // progress
130
- await (0, progressPlugin_1.addProgressPlugin)(applyOpts);
131
- // detect-dead-code-plugin
132
- await (0, detectDeadCodePlugin_1.addDetectDeadCodePlugin)(applyOpts);
133
- // fork-ts-checker
134
- await (0, forkTSCheckerPlugin_1.addForkTSCheckerPlugin)(applyOpts);
135
- // copy
136
- await (0, copyPlugin_1.addCopyPlugin)(applyOpts);
137
- // manifest
138
- await (0, manifestPlugin_1.addManifestPlugin)(applyOpts);
139
- // hmr
71
+ var _a, _b, _c;
72
+ const { userConfig } = opts;
73
+ const isDev = opts.env === import_types.Env.development;
74
+ const config = new import_webpack_5_chain.default();
75
+ userConfig.targets || (userConfig.targets = import_constants.DEFAULT_BROWSER_TARGETS);
76
+ const useHash = !!(opts.hash || userConfig.hash && !isDev);
77
+ const applyOpts = {
78
+ name: opts.name,
79
+ config,
80
+ userConfig,
81
+ cwd: opts.cwd,
82
+ env: opts.env,
83
+ babelPreset: opts.babelPreset,
84
+ extraBabelPlugins: opts.extraBabelPlugins || [],
85
+ extraBabelPresets: opts.extraBabelPresets || [],
86
+ extraBabelIncludes: opts.extraBabelIncludes || [],
87
+ extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
88
+ browsers: (0, import_browsersList.getBrowsersList)({
89
+ targets: userConfig.targets
90
+ }),
91
+ useHash,
92
+ staticPathPrefix: opts.staticPathPrefix !== void 0 ? opts.staticPathPrefix : "static/"
93
+ };
94
+ config.mode(opts.env);
95
+ config.stats("none");
96
+ Object.keys(opts.entry).forEach((key) => {
97
+ const entry = config.entry(key);
140
98
  if (isDev && opts.hmr) {
141
- config.plugin('hmr').use(webpack_1.default.HotModuleReplacementPlugin);
142
- }
143
- // ssr
144
- await (0, ssrPlugin_1.default)(applyOpts);
145
- // compress
146
- await (0, compressPlugin_1.addCompressPlugin)(applyOpts);
147
- // purgecss
148
- // await applyPurgeCSSWebpackPlugin(applyOpts);
149
- // handle HarmonyLinkingError
150
- await (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
151
- // remove node: prefix
152
- // disable for performance
153
- // await addNodePrefixPlugin(applyOpts);
154
- // runtimePublicPath
155
- if (userConfig.runtimePublicPath) {
156
- config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
99
+ entry.add(require.resolve("../../client/client/client"));
157
100
  }
158
- // cache
159
- if (opts.cache) {
160
- config.cache({
161
- type: 'filesystem',
162
- version: require('../../package.json').version,
163
- buildDependencies: {
164
- config: opts.cache.buildDependencies || [],
165
- },
166
- cacheDirectory: opts.cache.cacheDirectory ||
167
- // 使用 rootDir 是在有 APP_ROOT 时,把 cache 目录放在根目录下
168
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules', '.cache', 'bundler-webpack'),
169
- });
170
- // tnpm 安装依赖的情况 webpack 默认的 managedPaths 不生效
171
- // 使用 immutablePaths 避免 node_modules 的内容被写入缓存
172
- // tnpm 安装的依赖路径中同时包含包名和版本号,满足 immutablePaths 使用的条件
173
- // 同时配置 managedPaths 将 tnpm 的软连接结构标记为可信,避免执行快照序列化时 OOM
174
- // ref: smallfish
175
- if ( /*isTnpm*/require('@umijs/utils/package').__npminstall_done) {
176
- const nodeModulesPath = opts.cache.absNodeModulesPath ||
177
- (0, path_1.join)(opts.rootDir || opts.cwd, 'node_modules');
178
- config.snapshot({
179
- immutablePaths: [nodeModulesPath],
180
- managedPaths: [nodeModulesPath],
181
- });
101
+ entry.add(opts.entry[key]);
102
+ });
103
+ config.devtool(isDev ? userConfig.devtool === false ? false : userConfig.devtool || import_constants.DEFAULT_DEVTOOL : userConfig.devtool);
104
+ const absOutputPath = (0, import_path.resolve)(opts.cwd, userConfig.outputPath || import_constants.DEFAULT_OUTPUT_PATH);
105
+ const disableCompress = process.env.COMPRESS === "none";
106
+ config.output.path(absOutputPath).filename(useHash ? `[name].[contenthash:8].js` : `[name].js`).chunkFilename(useHash ? `[name].[contenthash:8].async.js` : `[name].async.js`).publicPath(userConfig.publicPath || "auto").pathinfo(isDev || disableCompress).set("assetModuleFilename", `${applyOpts.staticPathPrefix}[name].[hash:8][ext]`);
107
+ config.resolve.set("symlinks", true).modules.add("node_modules").end().alias.merge(userConfig.alias || {}).end().extensions.merge([
108
+ ".wasm",
109
+ ".mjs",
110
+ ".js",
111
+ ".jsx",
112
+ ".ts",
113
+ ".tsx",
114
+ ".json"
115
+ ]).end();
116
+ config.externals(userConfig.externals || []);
117
+ config.target(["web", "es5"]);
118
+ config.experiments({
119
+ topLevelAwait: true,
120
+ outputModule: !!userConfig.esm
121
+ });
122
+ await (0, import_nodePolyfill.addNodePolyfill)(applyOpts);
123
+ await (0, import_javaScriptRules.addJavaScriptRules)(applyOpts);
124
+ await (0, import_cssRules.addCSSRules)(applyOpts);
125
+ await (0, import_assetRules.addAssetRules)(applyOpts);
126
+ await (0, import_svgRules.addSVGRules)(applyOpts);
127
+ await (0, import_miniCSSExtractPlugin.addMiniCSSExtractPlugin)(applyOpts);
128
+ await (0, import_ignorePlugin.addIgnorePlugin)(applyOpts);
129
+ await (0, import_definePlugin.addDefinePlugin)(applyOpts);
130
+ await (0, import_fastRefreshPlugin.addFastRefreshPlugin)(applyOpts);
131
+ await (0, import_progressPlugin.addProgressPlugin)(applyOpts);
132
+ await (0, import_detectDeadCodePlugin.addDetectDeadCodePlugin)(applyOpts);
133
+ await (0, import_forkTSCheckerPlugin.addForkTSCheckerPlugin)(applyOpts);
134
+ await (0, import_copyPlugin.addCopyPlugin)(applyOpts);
135
+ await (0, import_manifestPlugin.addManifestPlugin)(applyOpts);
136
+ if (isDev && opts.hmr) {
137
+ config.plugin("hmr").use(import_webpack.default.HotModuleReplacementPlugin);
138
+ }
139
+ await (0, import_ssrPlugin.default)(applyOpts);
140
+ await (0, import_compressPlugin.addCompressPlugin)(applyOpts);
141
+ await (0, import_harmonyLinkingErrorPlugin.addHarmonyLinkingErrorPlugin)(applyOpts);
142
+ if (userConfig.runtimePublicPath) {
143
+ config.plugin("runtimePublicPath").use(import_RuntimePublicPathPlugin.RuntimePublicPathPlugin);
144
+ }
145
+ config.plugin("case-sensitive-paths").use(import_case_sensitive_paths_webpack_plugin.default);
146
+ if (opts.cache) {
147
+ config.cache({
148
+ type: "filesystem",
149
+ version: require("../../package.json").version,
150
+ buildDependencies: {
151
+ config: opts.cache.buildDependencies || []
152
+ },
153
+ cacheDirectory: opts.cache.cacheDirectory || (0, import_path.join)(opts.rootDir || opts.cwd, "node_modules", ".cache", "bundler-webpack")
154
+ });
155
+ if (require("@umijs/utils/package").__npminstall_done) {
156
+ const nodeModulesPath = opts.cache.absNodeModulesPath || (0, import_path.join)(opts.rootDir || opts.cwd, "node_modules");
157
+ const localLinkedNodeModules = Object.keys(Object.assign({}, (_a = opts.pkg) == null ? void 0 : _a.dependencies, (_b = opts.pkg) == null ? void 0 : _b.peerDependencies, (_c = opts.pkg) == null ? void 0 : _c.devDependencies)).map((pkg) => {
158
+ try {
159
+ return (0, import_path.resolve)(import_utils.resolve.sync(`${pkg}/package.json`, {
160
+ basedir: opts.rootDir || opts.cwd,
161
+ preserveSymlinks: false
162
+ }), "../node_modules");
163
+ } catch {
164
+ return opts.rootDir || opts.cwd;
182
165
  }
183
- config.infrastructureLogging({
184
- level: 'error',
185
- ...(process.env.WEBPACK_FS_CACHE_DEBUG
186
- ? {
187
- debug: /webpack\.cache/,
188
- }
189
- : {}),
190
- });
191
- }
192
- // analyzer
193
- if (opts.analyze) {
194
- await (0, bundleAnalyzerPlugin_1.addBundleAnalyzerPlugin)(applyOpts);
195
- }
196
- // chain webpack
197
- if (opts.chainWebpack) {
198
- await opts.chainWebpack(config, {
199
- env: opts.env,
200
- webpack: webpack_1.default,
201
- });
202
- }
203
- if (userConfig.chainWebpack) {
204
- await userConfig.chainWebpack(config, {
205
- env: opts.env,
206
- webpack: webpack_1.default,
207
- });
166
+ }).filter((pkg) => !pkg.startsWith(opts.rootDir || opts.cwd));
167
+ if (localLinkedNodeModules.length) {
168
+ import_utils.logger.info(`Detected local linked tnpm node_modules, to avoid oom, they will be treated as immutablePaths & managedPaths in webpack snapshot:`);
169
+ localLinkedNodeModules.forEach((p) => import_utils.logger.info(` ${p}`));
170
+ }
171
+ config.snapshot({
172
+ immutablePaths: [nodeModulesPath, ...localLinkedNodeModules],
173
+ managedPaths: [nodeModulesPath, ...localLinkedNodeModules]
174
+ });
208
175
  }
209
- let webpackConfig = config.toConfig();
210
- // speed measure
211
- // TODO: mini-css-extract-plugin 报错
212
- webpackConfig = await (0, speedMeasureWebpackPlugin_1.addSpeedMeasureWebpackPlugin)({
213
- webpackConfig,
176
+ config.infrastructureLogging(__spreadValues({
177
+ level: "error"
178
+ }, process.env.WEBPACK_FS_CACHE_DEBUG ? {
179
+ debug: /webpack\.cache/
180
+ } : {}));
181
+ }
182
+ if (opts.analyze) {
183
+ await (0, import_bundleAnalyzerPlugin.addBundleAnalyzerPlugin)(applyOpts);
184
+ }
185
+ if (opts.chainWebpack) {
186
+ await opts.chainWebpack(config, {
187
+ env: opts.env,
188
+ webpack: import_webpack.default
214
189
  });
215
- if (opts.modifyWebpackConfig) {
216
- webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
217
- env: opts.env,
218
- webpack: webpack_1.default,
219
- });
220
- }
221
- return webpackConfig;
190
+ }
191
+ if (userConfig.chainWebpack) {
192
+ await userConfig.chainWebpack(config, {
193
+ env: opts.env,
194
+ webpack: import_webpack.default
195
+ });
196
+ }
197
+ let webpackConfig = config.toConfig();
198
+ webpackConfig = await (0, import_speedMeasureWebpackPlugin.addSpeedMeasureWebpackPlugin)({
199
+ webpackConfig
200
+ });
201
+ if (opts.modifyWebpackConfig) {
202
+ webpackConfig = await opts.modifyWebpackConfig(webpackConfig, {
203
+ env: opts.env,
204
+ webpack: import_webpack.default
205
+ });
206
+ }
207
+ return webpackConfig;
222
208
  }
223
- exports.getConfig = getConfig;
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ getConfig
212
+ });
@@ -1,42 +1,61 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addCopyPlugin = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // copyPlugin.ts
20
+ var copyPlugin_exports = {};
21
+ __export(copyPlugin_exports, {
22
+ addCopyPlugin: () => addCopyPlugin
23
+ });
24
+ module.exports = __toCommonJS(copyPlugin_exports);
25
+ var import_fs = require("fs");
26
+ var import_path = require("path");
6
27
  async function addCopyPlugin(opts) {
7
- var _a;
8
- const { config, userConfig, cwd } = opts;
9
- const copyPatterns = [
10
- (0, fs_1.existsSync)((0, path_1.join)(cwd, 'public')) && {
11
- from: (0, path_1.join)(cwd, 'public'),
12
- // ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
13
- // Set minimized so terser will not do minimize
14
- info: { minimized: true },
15
- },
16
- ...(userConfig.copy
17
- ? (_a = userConfig.copy) === null || _a === void 0 ? void 0 : _a.map((pattern) => {
18
- if (typeof pattern === 'string') {
19
- return {
20
- from: (0, path_1.resolve)(cwd, pattern),
21
- info: { minimized: true },
22
- };
23
- }
24
- return {
25
- from: (0, path_1.resolve)(cwd, pattern.from),
26
- to: (0, path_1.resolve)(cwd, pattern.to),
27
- info: { minimized: true },
28
- };
29
- })
30
- : []),
31
- ].filter(Boolean);
32
- if (copyPatterns.length) {
33
- config
34
- .plugin('copy')
35
- .use(require('@umijs/bundler-webpack/compiled/copy-webpack-plugin'), [
36
- {
37
- patterns: copyPatterns,
38
- },
39
- ]);
40
- }
28
+ var _a;
29
+ const { config, userConfig, cwd } = opts;
30
+ const publicDir = (0, import_path.join)(cwd, "public");
31
+ const copyPatterns = [
32
+ (0, import_fs.existsSync)(publicDir) && (0, import_fs.readdirSync)(publicDir).length && {
33
+ from: publicDir,
34
+ info: { minimized: true }
35
+ },
36
+ ...userConfig.copy ? (_a = userConfig.copy) == null ? void 0 : _a.map((pattern) => {
37
+ if (typeof pattern === "string") {
38
+ return {
39
+ from: (0, import_path.resolve)(cwd, pattern),
40
+ info: { minimized: true }
41
+ };
42
+ }
43
+ return {
44
+ from: (0, import_path.resolve)(cwd, pattern.from),
45
+ to: (0, import_path.resolve)(cwd, pattern.to),
46
+ info: { minimized: true }
47
+ };
48
+ }) : []
49
+ ].filter(Boolean);
50
+ if (copyPatterns.length) {
51
+ config.plugin("copy").use(require("@umijs/bundler-webpack/compiled/copy-webpack-plugin"), [
52
+ {
53
+ patterns: copyPatterns
54
+ }
55
+ ]);
56
+ }
41
57
  }
42
- exports.addCopyPlugin = addCopyPlugin;
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ addCopyPlugin
61
+ });