@umijs/bundler-webpack 4.0.0-rc.9 → 4.0.0

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 (77) hide show
  1. package/client/client/client.js +65 -37
  2. package/client/constants.js +9 -0
  3. package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
  4. package/compiled/cssnano/index.js +6 -6
  5. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  6. package/compiled/{tapable → react-refresh}/LICENSE +6 -6
  7. package/compiled/react-refresh/index.js +9 -7
  8. package/compiled/react-refresh/package.json +1 -0
  9. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  10. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  11. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  12. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  13. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  14. package/compiled/webpack/RuleSetCompiler.js +1 -0
  15. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  16. package/compiled/webpack/deepImports.json +6 -1
  17. package/compiled/webpack/index.js +3978 -3167
  18. package/compiled/webpack/types.d.ts +606 -171
  19. package/compiled/webpack-dev-middleware/index.js +8 -7
  20. package/compiled/webpack-manifest-plugin/index.js +1 -1
  21. package/dist/build.d.ts +1 -0
  22. package/dist/build.js +49 -56
  23. package/dist/cli.js +6 -15
  24. package/dist/client/client.js +52 -50
  25. package/dist/config/_sampleFeature.js +6 -17
  26. package/dist/config/assetRules.js +44 -55
  27. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  28. package/dist/config/compressPlugin.js +89 -70
  29. package/dist/config/config.d.ts +2 -0
  30. package/dist/config/config.js +181 -179
  31. package/dist/config/copyPlugin.js +29 -40
  32. package/dist/config/cssRules.js +114 -83
  33. package/dist/config/definePlugin.js +11 -19
  34. package/dist/config/detectDeadCodePlugin.js +16 -21
  35. package/dist/config/fastRefreshPlugin.js +11 -22
  36. package/dist/config/forkTSCheckerPlugin.js +11 -22
  37. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  38. package/dist/config/ignorePlugin.js +10 -21
  39. package/dist/config/javaScriptRules.d.ts +1 -0
  40. package/dist/config/javaScriptRules.js +152 -136
  41. package/dist/config/manifestPlugin.d.ts +1 -1
  42. package/dist/config/manifestPlugin.js +10 -18
  43. package/dist/config/miniCSSExtractPlugin.js +15 -23
  44. package/dist/config/nodePolyfill.js +14 -20
  45. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  46. package/dist/config/nodePrefixPlugin.js +14 -0
  47. package/dist/config/progressPlugin.js +7 -18
  48. package/dist/config/purgecssWebpackPlugin.js +15 -26
  49. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  50. package/dist/config/ssrPlugin.d.ts +11 -0
  51. package/dist/config/ssrPlugin.js +66 -0
  52. package/dist/config/svgRules.js +44 -47
  53. package/dist/constants.d.ts +1 -0
  54. package/dist/constants.js +7 -1
  55. package/dist/dev.d.ts +4 -0
  56. package/dist/dev.js +113 -93
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.js +16 -0
  59. package/dist/loader/svgr.js +4 -13
  60. package/dist/loader/swc.js +9 -14
  61. package/dist/plugins/ProgressPlugin.js +3 -3
  62. package/dist/plugins/RuntimePublicPathPlugin.js +4 -1
  63. package/dist/schema.js +21 -6
  64. package/dist/server/server.d.ts +3 -1
  65. package/dist/server/server.js +165 -159
  66. package/dist/server/ws.d.ts +7 -2
  67. package/dist/types.d.ts +3 -0
  68. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  69. package/dist/utils/getEsBuildTarget.js +12 -0
  70. package/package.json +22 -20
  71. package/compiled/tapable/index.js +0 -1
  72. package/compiled/tapable/package.json +0 -1
  73. package/compiled/tapable/tapable.d.ts +0 -116
  74. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  75. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -63
  76. package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +0 -10
  77. package/dist/plugins/ParcelCSSMinifyPlugin.js +0 -75
@@ -1,164 +1,180 @@
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.addJavaScriptRules = void 0;
13
4
  const mfsu_1 = require("@umijs/mfsu");
14
5
  const utils_1 = require("@umijs/utils");
6
+ const path_1 = require("path");
15
7
  const webpack_1 = require("../../compiled/webpack");
16
8
  const constants_1 = require("../constants");
17
9
  const types_1 = require("../types");
18
10
  const depMatch_1 = require("../utils/depMatch");
19
- function addJavaScriptRules(opts) {
11
+ async function addJavaScriptRules(opts) {
20
12
  var _a, _b;
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { config, userConfig, cwd, name } = opts;
23
- const isDev = opts.env === types_1.Env.development;
24
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
25
- const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
26
- const srcRules = [
27
- config.module
28
- .rule('src')
29
- .test(/\.(js|mjs)$/)
30
- .include.add([
31
- cwd,
32
- // import module out of cwd using APP_ROOT
33
- // issue: https://github.com/umijs/umi/issues/5594
34
- ...(process.env.APP_ROOT ? [process.cwd()] : []),
35
- ])
36
- .end()
37
- .exclude.add(/node_modules/)
38
- .end(),
39
- config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
40
- config.module
41
- .rule('extra-src')
42
- .test(/\.(js|mjs)$/)
43
- .include.add((path) => {
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
44
42
  try {
45
- // do src transform for bundler-webpack/client/client/client.js
46
- if (path.includes('client/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
- if (userConfig.mdx) {
58
- srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
59
- }
60
- const depRules = [
61
- config.module
62
- .rule('dep')
63
- .test(/\.(js|mjs)$/)
64
- .include.add(/node_modules/)
65
- .end()
66
- .exclude.add((path) => {
54
+ }),
55
+ // support es5ImcompatibleVersions
56
+ (path) => {
67
57
  try {
58
+ // do src transform for bundler-webpack/client/client/client.js
59
+ if (path.includes('client/client/client'))
60
+ return true;
68
61
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
69
62
  }
70
63
  catch (e) {
71
64
  console.error(utils_1.chalk.red(e));
72
65
  throw e;
73
66
  }
74
- })
75
- .end(),
76
- ];
77
- // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
78
- const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
79
- srcRules.forEach((rule) => {
80
- if (srcTranspiler === types_1.Transpiler.babel) {
81
- rule
82
- .use('babel-loader')
83
- .loader(require.resolve('../../compiled/babel-loader'))
84
- .options({
85
- // Tell babel to guess the type, instead assuming all files are modules
86
- // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
87
- sourceType: 'unambiguous',
88
- babelrc: false,
89
- cacheDirectory: false,
90
- // process.env.BABEL_CACHE !== 'none'
91
- // ? join(cwd, `.umi/.cache/babel-loader`)
92
- // : false,
93
- targets: userConfig.targets,
94
- presets: [
95
- opts.babelPreset || [
96
- require.resolve('@umijs/babel-preset-umi'),
97
- {
98
- presetEnv: {},
99
- presetReact: {},
100
- presetTypeScript: {},
101
- pluginTransformRuntime: {},
102
- pluginLockCoreJS: {},
103
- pluginDynamicImportNode: false,
104
- pluginAutoCSSModules: userConfig.autoCSSModules,
105
- },
106
- ],
107
- ...opts.extraBabelPresets,
108
- ...(userConfig.extraBabelPresets || []).filter(Boolean),
109
- ],
110
- plugins: [
111
- useFastRefresh && require.resolve('react-refresh/babel'),
112
- ...opts.extraBabelPlugins,
113
- ...(userConfig.extraBabelPlugins || []),
114
- ].filter(Boolean),
115
- });
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 });
116
83
  }
117
- else if (srcTranspiler === types_1.Transpiler.swc) {
118
- const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
119
- rule
120
- .use('swc-loader')
121
- .loader(require.resolve('../loader/swc'))
122
- .options({
123
- plugin: (m) => new AutoCSSModule().visitProgram(m),
124
- });
84
+ catch (e) {
85
+ console.error(utils_1.chalk.red(e));
86
+ throw e;
125
87
  }
126
- else if (srcTranspiler === types_1.Transpiler.esbuild) {
127
- rule
128
- .use('esbuild-loader')
129
- .loader(mfsu_1.esbuildLoader)
130
- .options({
131
- target: isDev ? 'esnext' : 'es2015',
132
- handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
133
- });
134
- // esbuild loader can not auto import `React`
135
- config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
136
- {
137
- React: 'react',
138
- },
139
- ]);
140
- }
141
- else {
142
- throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
143
- }
144
- });
145
- if (userConfig.mdx) {
146
- config.module
147
- .rule('mdx')
148
- .test(/\.mdx?$/)
149
- .use('mdx-loader')
150
- .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
151
- .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
88
+ })
89
+ .end(),
90
+ ];
91
+ srcRules
92
+ .concat(depRules)
93
+ .forEach((rule) => rule.resolve.set('fullySpecified', false));
94
+ // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
95
+ const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
96
+ srcRules.forEach((rule) => {
97
+ if (srcTranspiler === types_1.Transpiler.babel) {
98
+ rule
99
+ .use('babel-loader')
100
+ .loader(require.resolve('../../compiled/babel-loader'))
101
+ .options({
102
+ // Tell babel to guess the type, instead assuming all files are modules
103
+ // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
104
+ sourceType: 'unambiguous',
105
+ babelrc: false,
106
+ cacheDirectory: false,
107
+ // process.env.BABEL_CACHE !== 'none'
108
+ // ? join(cwd, `.umi/.cache/babel-loader`)
109
+ // : false,
110
+ targets: userConfig.targets,
111
+ presets: [
112
+ opts.babelPreset || [
113
+ require.resolve('@umijs/babel-preset-umi'),
114
+ {
115
+ presetEnv: {},
116
+ presetReact: {},
117
+ presetTypeScript: {},
118
+ pluginTransformRuntime: {},
119
+ pluginLockCoreJS: {},
120
+ pluginDynamicImportNode: false,
121
+ pluginAutoCSSModules: userConfig.autoCSSModules,
122
+ },
123
+ ],
124
+ ...opts.extraBabelPresets,
125
+ ...(userConfig.extraBabelPresets || []).filter(Boolean),
126
+ ],
127
+ plugins: [
128
+ useFastRefresh && require.resolve('react-refresh/babel'),
129
+ ...opts.extraBabelPlugins,
130
+ ...(userConfig.extraBabelPlugins || []),
131
+ ].filter(Boolean),
132
+ });
133
+ }
134
+ else if (srcTranspiler === types_1.Transpiler.swc) {
135
+ const AutoCSSModule = require('../swcPlugins/autoCSSModules').default;
136
+ rule
137
+ .use('swc-loader')
138
+ .loader(require.resolve('../loader/swc'))
139
+ .options({
140
+ plugin: (m) => new AutoCSSModule().visitProgram(m),
141
+ });
142
+ }
143
+ else if (srcTranspiler === types_1.Transpiler.esbuild) {
144
+ rule
145
+ .use('esbuild-loader')
146
+ .loader(mfsu_1.esbuildLoader)
147
+ .options({
148
+ target: isDev ? 'esnext' : 'es2015',
149
+ handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
150
+ });
151
+ // esbuild loader can not auto import `React`
152
+ config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
153
+ {
154
+ React: 'react',
155
+ },
156
+ ]);
157
+ }
158
+ else {
159
+ throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
160
+ }
161
+ });
162
+ if (userConfig.mdx) {
163
+ config.module
164
+ .rule('mdx')
165
+ .test(/\.mdx?$/)
166
+ .use('mdx-loader')
167
+ .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
168
+ .options((_b = userConfig.mdx) === null || _b === void 0 ? void 0 : _b.loaderOptions);
169
+ }
170
+ const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
171
+ depRules.forEach((_rule) => {
172
+ if (depTranspiler === types_1.Transpiler.none) {
173
+ // noop
174
+ }
175
+ else {
176
+ throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
152
177
  }
153
- const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
154
- depRules.forEach((_rule) => {
155
- if (depTranspiler === types_1.Transpiler.none) {
156
- // noop
157
- }
158
- else {
159
- throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
160
- }
161
- });
162
178
  });
163
179
  }
164
180
  exports.addJavaScriptRules = addJavaScriptRules;
@@ -1,5 +1,5 @@
1
1
  import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
- import { Env, IConfig } from '../types';
2
+ import type { Env, IConfig } from '../types';
3
3
  interface IOpts {
4
4
  name?: string;
5
5
  config: Config;
@@ -1,25 +1,17 @@
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.addManifestPlugin = void 0;
13
4
  // @ts-ignore
14
5
  const webpack_manifest_plugin_1 = require("@umijs/bundler-webpack/compiled/webpack-manifest-plugin");
15
- function addManifestPlugin(opts) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { config, userConfig } = opts;
18
- if (userConfig.manifest) {
19
- config.plugin('manifest-plugin').use(webpack_manifest_plugin_1.WebpackManifestPlugin, [
20
- Object.assign({ fileName: 'asset-manifest.json' }, userConfig.manifest),
21
- ]);
22
- }
23
- });
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
+ }
24
16
  }
25
17
  exports.addManifestPlugin = addManifestPlugin;
@@ -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,19 +6,20 @@ 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
- function addMiniCSSExtractPlugin(opts) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const { config, userConfig, useHash } = opts;
21
- const hash = useHash ? '.[contenthash:8]' : '';
22
- if (!userConfig.styleLoader) {
23
- config.plugin('mini-css-extract-plugin').use(mini_css_extract_plugin_1.default, [
24
- {
25
- filename: `[name]${hash}.css`,
26
- chunkFilename: `[name]${hash}.chunk.css`,
27
- ignoreOrder: true,
28
- },
29
- ]);
30
- }
31
- });
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: opts.userConfig.ssr
17
+ ? // TODO: FIXME
18
+ `umi${hash}.css`
19
+ : `[name]${hash}.chunk.css`,
20
+ ignoreOrder: true,
21
+ },
22
+ ]);
23
+ }
32
24
  }
33
25
  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;
@@ -0,0 +1,11 @@
1
+ import Config from '../../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 default function addSSRPlugin(opts: IOpts): void;
11
+ export {};