@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.2

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 (97) hide show
  1. package/dist/build.d.ts +20 -0
  2. package/dist/build.js +64 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +81 -0
  5. package/dist/client/client.d.ts +1 -0
  6. package/dist/client/client.js +245 -0
  7. package/dist/config/_sampleFeature.d.ts +10 -0
  8. package/dist/config/_sampleFeature.js +11 -0
  9. package/dist/config/assetRules.d.ts +11 -0
  10. package/dist/config/assetRules.js +50 -0
  11. package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
  12. package/dist/config/bundleAnalyzerPlugin.js +19 -0
  13. package/dist/config/compressPlugin.d.ts +10 -0
  14. package/dist/config/compressPlugin.js +83 -0
  15. package/dist/config/config.d.ts +27 -0
  16. package/dist/config/config.js +218 -0
  17. package/dist/config/copyPlugin.d.ts +10 -0
  18. package/dist/config/copyPlugin.js +38 -0
  19. package/dist/config/cssRules.d.ts +11 -0
  20. package/dist/config/cssRules.js +108 -0
  21. package/dist/config/definePlugin.d.ts +15 -0
  22. package/dist/config/definePlugin.js +37 -0
  23. package/dist/config/detectDeadCode.d.ts +12 -0
  24. package/dist/config/detectDeadCode.js +120 -0
  25. package/dist/config/detectDeadCodePlugin.d.ts +9 -0
  26. package/dist/config/detectDeadCodePlugin.js +70 -0
  27. package/dist/config/fastRefreshPlugin.d.ts +12 -0
  28. package/dist/config/fastRefreshPlugin.js +23 -0
  29. package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
  30. package/dist/config/forkTSCheckerPlugin.js +23 -0
  31. package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
  32. package/dist/config/harmonyLinkingErrorPlugin.js +31 -0
  33. package/dist/config/ignorePlugin.d.ts +10 -0
  34. package/dist/config/ignorePlugin.js +16 -0
  35. package/dist/config/javaScriptRules.d.ts +16 -0
  36. package/dist/config/javaScriptRules.js +177 -0
  37. package/dist/config/manifestPlugin.d.ts +11 -0
  38. package/dist/config/manifestPlugin.js +17 -0
  39. package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
  40. package/dist/config/miniCSSExtractPlugin.js +22 -0
  41. package/dist/config/nodePolyfill.d.ts +10 -0
  42. package/dist/config/nodePolyfill.js +28 -0
  43. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  44. package/dist/config/nodePrefixPlugin.js +14 -0
  45. package/dist/config/progressPlugin.d.ts +11 -0
  46. package/dist/config/progressPlugin.js +16 -0
  47. package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
  48. package/dist/config/purgecssWebpackPlugin.js +21 -0
  49. package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
  50. package/dist/config/speedMeasureWebpackPlugin.js +23 -0
  51. package/dist/config/svgRules.d.ts +12 -0
  52. package/dist/config/svgRules.js +53 -0
  53. package/dist/constants.d.ts +15 -0
  54. package/dist/constants.js +24 -0
  55. package/dist/dev.d.ts +25 -0
  56. package/dist/dev.js +134 -0
  57. package/dist/index.d.ts +8 -0
  58. package/dist/index.js +20 -0
  59. package/dist/loader/svgr.d.ts +4 -0
  60. package/dist/loader/svgr.js +58 -0
  61. package/dist/loader/swc.d.ts +4 -0
  62. package/dist/loader/swc.js +74 -0
  63. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
  64. package/dist/plugins/ESBuildCSSMinifyPlugin.js +52 -0
  65. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
  66. package/dist/plugins/ParcelCSSMinifyPlugin.js +73 -0
  67. package/dist/plugins/ProgressPlugin.d.ts +15 -0
  68. package/dist/plugins/ProgressPlugin.js +44 -0
  69. package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
  70. package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
  71. package/dist/plugins/_SamplePlugin.d.ts +9 -0
  72. package/dist/plugins/_SamplePlugin.js +14 -0
  73. package/dist/requireHook.d.ts +1 -0
  74. package/dist/requireHook.js +31 -0
  75. package/dist/schema.d.ts +3 -0
  76. package/dist/schema.js +84 -0
  77. package/dist/server/server.d.ts +17 -0
  78. package/dist/server/server.js +193 -0
  79. package/dist/server/ws.d.ts +11 -0
  80. package/dist/server/ws.js +42 -0
  81. package/dist/swcPlugins/autoCSSModules.d.ts +13 -0
  82. package/dist/swcPlugins/autoCSSModules.js +34 -0
  83. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  84. package/dist/swcPlugins/changeImportFromString.js +10 -0
  85. package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
  86. package/dist/swcPlugins/lockCoreJS.js +24 -0
  87. package/dist/types.d.ts +119 -0
  88. package/dist/types.js +30 -0
  89. package/dist/utils/browsersList.d.ts +5 -0
  90. package/dist/utils/browsersList.js +10 -0
  91. package/dist/utils/depMatch.d.ts +6 -0
  92. package/dist/utils/depMatch.js +46 -0
  93. package/dist/utils/formatWebpackMessages.d.ts +12 -0
  94. package/dist/utils/formatWebpackMessages.js +100 -0
  95. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  96. package/dist/utils/getEsBuildTarget.js +12 -0
  97. package/package.json +5 -5
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addFastRefreshPlugin = void 0;
7
+ // @ts-ignore
8
+ const lib_1 = __importDefault(require("@pmmmwh/react-refresh-webpack-plugin/lib"));
9
+ const constants_1 = require("../constants");
10
+ const types_1 = require("../types");
11
+ async function addFastRefreshPlugin(opts) {
12
+ const { config, userConfig, name } = opts;
13
+ const isDev = opts.env === types_1.Env.development;
14
+ const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
15
+ // TODO: Should only run in react csr
16
+ if (useFastRefresh) {
17
+ config
18
+ .plugin('fastRefresh')
19
+ .after('hmr')
20
+ .use(lib_1.default, [{ overlay: false }]);
21
+ }
22
+ }
23
+ exports.addFastRefreshPlugin = addFastRefreshPlugin;
@@ -0,0 +1,11 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export declare function addForkTSCheckerPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addForkTSCheckerPlugin = void 0;
7
+ // @ts-ignore
8
+ const fork_ts_checker_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/fork-ts-checker-webpack-plugin"));
9
+ async function addForkTSCheckerPlugin(opts) {
10
+ var _a;
11
+ const { config, userConfig } = opts;
12
+ if (userConfig.forkTSChecker) {
13
+ // use user's typescript
14
+ if ((_a = userConfig.forkTSChecker.typescript) === null || _a === void 0 ? void 0 : _a.enable) {
15
+ userConfig.forkTSChecker.typescript.typescriptPath =
16
+ require.resolve('typescript');
17
+ }
18
+ config
19
+ .plugin('fork-ts-checker-plugin')
20
+ .use(fork_ts_checker_webpack_plugin_1.default, [userConfig.forkTSChecker]);
21
+ }
22
+ }
23
+ exports.addForkTSCheckerPlugin = addForkTSCheckerPlugin;
@@ -0,0 +1,6 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ interface IOpts {
3
+ config: Config;
4
+ }
5
+ export declare function addHarmonyLinkingErrorPlugin(opts: IOpts): Promise<void>;
6
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addHarmonyLinkingErrorPlugin = void 0;
4
+ // ref: https://github.com/webpack/webpack/blob/ccecc17c01af96edddb931a76e7a3b21ef2969d8/lib/dependencies/HarmonyImportDependency.js#L164
5
+ const LINKING_ERROR_TAG = 'was not found in';
6
+ // build 时会出现 css modules 的引用警告,但这应该是需要忽略的
7
+ const CSS_NO_EXPORTS = /\.(css|sass|scss|styl|less)' \(module has no exports\)/;
8
+ class HarmonyLinkingErrorPlugin {
9
+ apply(compiler) {
10
+ compiler.hooks.afterCompile.tap('HarmonyLinkingErrorPlugin', (compilation) => {
11
+ if (!compilation.warnings.length) {
12
+ return;
13
+ }
14
+ const harmonyLinkingErrors = compilation.warnings.filter((w) => {
15
+ return (w.name === 'ModuleDependencyWarning' &&
16
+ !w.module.resource.includes('node_modules') &&
17
+ w.message.includes(LINKING_ERROR_TAG) &&
18
+ !CSS_NO_EXPORTS.test(w.message));
19
+ });
20
+ if (!harmonyLinkingErrors.length) {
21
+ return;
22
+ }
23
+ compilation.errors.push(...harmonyLinkingErrors);
24
+ });
25
+ }
26
+ }
27
+ async function addHarmonyLinkingErrorPlugin(opts) {
28
+ const { config } = opts;
29
+ config.plugin('harmony-linking-error-plugin').use(HarmonyLinkingErrorPlugin);
30
+ }
31
+ exports.addHarmonyLinkingErrorPlugin = addHarmonyLinkingErrorPlugin;
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ }
9
+ export declare function addIgnorePlugin(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addIgnorePlugin = void 0;
4
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
5
+ async function addIgnorePlugin(opts) {
6
+ const { config, userConfig } = opts;
7
+ if (userConfig.ignoreMomentLocale) {
8
+ config.plugin('ignore-moment-locale').use(webpack_1.IgnorePlugin, [
9
+ {
10
+ resourceRegExp: /^\.\/locale$/,
11
+ contextRegExp: /moment$/,
12
+ },
13
+ ]);
14
+ }
15
+ }
16
+ exports.addIgnorePlugin = addIgnorePlugin;
@@ -0,0 +1,16 @@
1
+ import Config from '../../compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ extraBabelPlugins: any[];
9
+ extraBabelPresets: any[];
10
+ extraBabelIncludes: string[];
11
+ extraEsbuildLoaderHandler: any[];
12
+ babelPreset: any;
13
+ name?: string;
14
+ }
15
+ export declare function addJavaScriptRules(opts: IOpts): Promise<void>;
16
+ export {};
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addJavaScriptRules = void 0;
4
+ const mfsu_1 = require("@umijs/mfsu");
5
+ const utils_1 = require("@umijs/utils");
6
+ const path_1 = require("path");
7
+ const webpack_1 = require("../../compiled/webpack");
8
+ const constants_1 = require("../constants");
9
+ const types_1 = require("../types");
10
+ const depMatch_1 = require("../utils/depMatch");
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
42
+ try {
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] }));
47
+ }
48
+ catch (e) {
49
+ if (e.code === 'MODULE_NOT_FOUND') {
50
+ throw new Error('Cannot resolve extraBabelIncludes: ' + p);
51
+ }
52
+ throw e;
53
+ }
54
+ }),
55
+ // support es5ImcompatibleVersions
56
+ (path) => {
57
+ try {
58
+ // do src transform for bundler-webpack/client/client/client.js
59
+ if (path.includes('client/client/client'))
60
+ return true;
61
+ return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
62
+ }
63
+ catch (e) {
64
+ console.error(utils_1.chalk.red(e));
65
+ throw e;
66
+ }
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 });
83
+ }
84
+ catch (e) {
85
+ console.error(utils_1.chalk.red(e));
86
+ throw e;
87
+ }
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
+ }
175
+ });
176
+ }
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;
@@ -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
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ useHash: boolean;
9
+ }
10
+ export declare function addMiniCSSExtractPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addMiniCSSExtractPlugin = void 0;
7
+ // @ts-ignore
8
+ const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
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
+ }
21
+ }
22
+ exports.addMiniCSSExtractPlugin = addMiniCSSExtractPlugin;
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ }
9
+ export declare function addNodePolyfill(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addNodePolyfill = void 0;
4
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
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) => {
16
+ if (nodeLibs[key]) {
17
+ memo[key] = nodeLibs[key];
18
+ }
19
+ else {
20
+ memo[key] = false;
21
+ }
22
+ return memo;
23
+ }, {}),
24
+ http: false,
25
+ https: false,
26
+ });
27
+ }
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;
@@ -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 addProgressPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addProgressPlugin = void 0;
7
+ const ProgressPlugin_1 = __importDefault(require("../plugins/ProgressPlugin"));
8
+ async function addProgressPlugin(opts) {
9
+ const { config, name } = opts;
10
+ config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
11
+ {
12
+ name,
13
+ },
14
+ ]);
15
+ }
16
+ exports.addProgressPlugin = addProgressPlugin;
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ }
9
+ export declare function applyPurgeCSSWebpackPlugin(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyPurgeCSSWebpackPlugin = void 0;
4
+ const types_1 = require("../types");
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
+ }
20
+ }
21
+ exports.applyPurgeCSSWebpackPlugin = applyPurgeCSSWebpackPlugin;
@@ -0,0 +1,6 @@
1
+ import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
2
+ interface IOpts {
3
+ webpackConfig: Configuration;
4
+ }
5
+ export declare function addSpeedMeasureWebpackPlugin(opts: IOpts): Promise<Configuration>;
6
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addSpeedMeasureWebpackPlugin = void 0;
7
+ // @ts-ignore
8
+ const speed_measure_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/speed-measure-webpack-plugin"));
9
+ const path_1 = require("path");
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;
22
+ }
23
+ exports.addSpeedMeasureWebpackPlugin = addSpeedMeasureWebpackPlugin;
@@ -0,0 +1,12 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ config: Config;
5
+ userConfig: IConfig;
6
+ cwd: string;
7
+ env: Env;
8
+ browsers: any;
9
+ staticPathPrefix: string;
10
+ }
11
+ export declare function addSVGRules(opts: IOpts): Promise<void>;
12
+ export {};
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSVGRules = void 0;
4
+ async function addSVGRules(opts) {
5
+ const { config, userConfig } = opts;
6
+ const { svgr, svgo = {} } = userConfig;
7
+ if (svgr) {
8
+ const svgrRule = config.module.rule('svgr');
9
+ svgrRule
10
+ .test(/\.svg$/)
11
+ .issuer(/\.[jt]sx?$/)
12
+ .type('javascript/auto')
13
+ .use('svgr-loader')
14
+ .loader(require.resolve('../loader/svgr'))
15
+ .options({
16
+ svgoConfig: {
17
+ plugins: [
18
+ {
19
+ name: 'preset-default',
20
+ params: {
21
+ overrides: {
22
+ removeTitle: false,
23
+ },
24
+ },
25
+ },
26
+ ],
27
+ ...svgo,
28
+ },
29
+ ...svgr,
30
+ svgo: !!svgo,
31
+ })
32
+ .end()
33
+ .use('url-loader')
34
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'))
35
+ .end();
36
+ }
37
+ if (svgo === false) {
38
+ const svgRule = config.module.rule('svg');
39
+ svgRule
40
+ .test(/\.svg$/)
41
+ .use('url-loader')
42
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/url-loader'));
43
+ return;
44
+ }
45
+ const svgRule = config.module.rule('svg');
46
+ svgRule
47
+ .test(/\.svg$/)
48
+ .use('svgo-loader')
49
+ .loader(require.resolve('@umijs/bundler-webpack/compiled/svgo-loader'))
50
+ .options({ configFile: false, ...svgo })
51
+ .end();
52
+ }
53
+ exports.addSVGRules = addSVGRules;
@@ -0,0 +1,15 @@
1
+ export declare const DEFAULT_DEVTOOL = "cheap-module-source-map";
2
+ export declare const DEFAULT_OUTPUT_PATH = "dist";
3
+ export declare const MFSU_NAME = "MFSU";
4
+ export declare enum MESSAGE_TYPE {
5
+ ok = "ok",
6
+ warnings = "warnings",
7
+ errors = "errors",
8
+ hash = "hash",
9
+ stillOk = "still-ok",
10
+ invalid = "invalid"
11
+ }
12
+ export declare const DEFAULT_BROWSER_TARGETS: {
13
+ chrome: number;
14
+ };
15
+ export declare const DEFAULT_ESBUILD_TARGET_KEYS: string[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = exports.DEFAULT_BROWSER_TARGETS = exports.MESSAGE_TYPE = exports.MFSU_NAME = exports.DEFAULT_OUTPUT_PATH = exports.DEFAULT_DEVTOOL = void 0;
4
+ exports.DEFAULT_DEVTOOL = 'cheap-module-source-map';
5
+ exports.DEFAULT_OUTPUT_PATH = 'dist';
6
+ exports.MFSU_NAME = 'MFSU';
7
+ var MESSAGE_TYPE;
8
+ (function (MESSAGE_TYPE) {
9
+ MESSAGE_TYPE["ok"] = "ok";
10
+ MESSAGE_TYPE["warnings"] = "warnings";
11
+ MESSAGE_TYPE["errors"] = "errors";
12
+ MESSAGE_TYPE["hash"] = "hash";
13
+ MESSAGE_TYPE["stillOk"] = "still-ok";
14
+ MESSAGE_TYPE["invalid"] = "invalid";
15
+ })(MESSAGE_TYPE = exports.MESSAGE_TYPE || (exports.MESSAGE_TYPE = {}));
16
+ exports.DEFAULT_BROWSER_TARGETS = {
17
+ chrome: 80,
18
+ };
19
+ exports.DEFAULT_ESBUILD_TARGET_KEYS = [
20
+ 'chrome',
21
+ 'firefox',
22
+ 'edge',
23
+ 'safari',
24
+ ];