@umijs/bundler-webpack 4.0.0-rc.2 → 4.0.0-rc.22

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 (113) 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 +2 -0
  4. package/compiled/autoprefixer/index.js +3 -3
  5. package/compiled/autoprefixer/postcss/lib/declaration.d.ts +1 -1
  6. package/compiled/autoprefixer/postcss/lib/node.d.ts +2 -2
  7. package/compiled/babel-loader/index.js +2 -2
  8. package/compiled/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
  9. package/compiled/copy-webpack-plugin/index.js +12 -12
  10. package/compiled/css-minimizer-webpack-plugin/index.js +7 -7
  11. package/compiled/cssnano/index.js +6 -6
  12. package/compiled/cssnano/package.json +1 -1
  13. package/compiled/express.d.ts +2 -0
  14. package/compiled/fork-ts-checker-webpack-plugin/index.js +7 -13
  15. package/compiled/http-proxy-middleware/index.js +10 -10
  16. package/compiled/mini-css-extract-plugin/index.js +440 -401
  17. package/compiled/mini-css-extract-plugin/loader.js +3 -1
  18. package/compiled/mini-css-extract-plugin/utils.js +2 -0
  19. package/compiled/{tapable → react-refresh}/LICENSE +6 -6
  20. package/compiled/react-refresh/index.js +9 -7
  21. package/compiled/react-refresh/package.json +1 -0
  22. package/compiled/terser/index.js +1 -1
  23. package/compiled/webpack/BasicEffectRulePlugin.js +1 -0
  24. package/compiled/webpack/BasicMatcherRulePlugin.js +1 -0
  25. package/compiled/webpack/HotModuleReplacement.runtime.js +29 -14
  26. package/compiled/webpack/JavascriptHotModuleReplacement.runtime.js +4 -3
  27. package/compiled/webpack/ObjectMatcherRulePlugin.js +1 -0
  28. package/compiled/webpack/RuleSetCompiler.js +1 -0
  29. package/compiled/webpack/UseEffectRulePlugin.js +1 -0
  30. package/compiled/webpack/deepImports.json +6 -1
  31. package/compiled/webpack/index.js +5155 -3422
  32. package/compiled/webpack/types.d.ts +606 -171
  33. package/compiled/webpack-dev-middleware/index.js +8 -7
  34. package/compiled/webpack-manifest-plugin/index.js +1 -1
  35. package/dist/build.d.ts +1 -0
  36. package/dist/build.js +48 -57
  37. package/dist/cli.js +6 -15
  38. package/dist/client/client.js +57 -51
  39. package/dist/config/_sampleFeature.js +6 -17
  40. package/dist/config/assetRules.js +44 -55
  41. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  42. package/dist/config/compressPlugin.js +89 -64
  43. package/dist/config/config.d.ts +2 -0
  44. package/dist/config/config.js +178 -179
  45. package/dist/config/copyPlugin.js +29 -40
  46. package/dist/config/cssRules.js +93 -83
  47. package/dist/config/definePlugin.js +11 -19
  48. package/dist/config/detectDeadCode.js +1 -1
  49. package/dist/config/detectDeadCodePlugin.js +21 -22
  50. package/dist/config/fastRefreshPlugin.js +11 -22
  51. package/dist/config/forkTSCheckerPlugin.js +11 -22
  52. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  53. package/dist/config/ignorePlugin.js +10 -21
  54. package/dist/config/javaScriptRules.d.ts +1 -0
  55. package/dist/config/javaScriptRules.js +152 -138
  56. package/dist/config/manifestPlugin.js +10 -18
  57. package/dist/config/miniCSSExtractPlugin.js +12 -23
  58. package/dist/config/nodePolyfill.js +14 -20
  59. package/dist/config/nodePrefixPlugin.d.ts +11 -0
  60. package/dist/config/nodePrefixPlugin.js +14 -0
  61. package/dist/config/progressPlugin.js +7 -18
  62. package/dist/config/purgecssWebpackPlugin.js +15 -26
  63. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  64. package/dist/config/svgRules.js +44 -47
  65. package/dist/constants.d.ts +1 -0
  66. package/dist/constants.js +7 -1
  67. package/dist/dev.d.ts +4 -0
  68. package/dist/dev.js +115 -94
  69. package/dist/index.d.ts +4 -1
  70. package/dist/index.js +5 -1
  71. package/dist/loader/svgr.js +4 -13
  72. package/dist/loader/swc.js +9 -14
  73. package/dist/plugins/ProgressPlugin.js +2 -2
  74. package/dist/plugins/RuntimePublicPathPlugin.js +4 -1
  75. package/dist/schema.js +29 -13
  76. package/dist/server/server.d.ts +3 -1
  77. package/dist/server/server.js +166 -148
  78. package/dist/server/ws.d.ts +7 -2
  79. package/dist/swcPlugins/autoCSSModules.js +3 -1
  80. package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
  81. package/dist/swcPlugins/changeImportFromString.js +10 -0
  82. package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
  83. package/dist/swcPlugins/lockCoreJS.js +3 -2
  84. package/dist/types.d.ts +4 -0
  85. package/dist/types.js +1 -0
  86. package/dist/utils/getEsBuildTarget.d.ts +5 -0
  87. package/dist/utils/getEsBuildTarget.js +12 -0
  88. package/package.json +33 -35
  89. package/compiled/css-loader/LICENSE +0 -20
  90. package/compiled/css-loader/api.js +0 -102
  91. package/compiled/css-loader/getUrl.js +0 -29
  92. package/compiled/css-loader/index.js +0 -2
  93. package/compiled/css-loader/noSourceMaps.js +0 -5
  94. package/compiled/css-loader/package.json +0 -1
  95. package/compiled/css-loader/sourceMaps.js +0 -22
  96. package/compiled/express/LICENSE +0 -24
  97. package/compiled/express/body-parser/index.d.ts +0 -104
  98. package/compiled/express/connect/index.d.ts +0 -93
  99. package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
  100. package/compiled/express/index.d.ts +0 -133
  101. package/compiled/express/index.js +0 -321
  102. package/compiled/express/mime/index.d.ts +0 -35
  103. package/compiled/express/package.json +0 -1
  104. package/compiled/express/qs/index.d.ts +0 -62
  105. package/compiled/express/range-parser/index.d.ts +0 -35
  106. package/compiled/express/serve-static/index.d.ts +0 -108
  107. package/compiled/less/index.js +0 -31
  108. package/compiled/less/package.json +0 -1
  109. package/compiled/tapable/index.js +0 -1
  110. package/compiled/tapable/package.json +0 -1
  111. package/compiled/tapable/tapable.d.ts +0 -116
  112. package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +0 -11
  113. package/dist/plugins/ESBuildCSSMinifyPlugin.js +0 -65
@@ -1,166 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
2
  Object.defineProperty(exports, "__esModule", { value: true });
15
3
  exports.addJavaScriptRules = void 0;
16
4
  const mfsu_1 = require("@umijs/mfsu");
17
5
  const utils_1 = require("@umijs/utils");
6
+ const path_1 = require("path");
18
7
  const webpack_1 = require("../../compiled/webpack");
19
8
  const constants_1 = require("../constants");
20
- const autoCSSModules_1 = __importDefault(require("../swcPlugins/autoCSSModules"));
21
9
  const types_1 = require("../types");
22
10
  const depMatch_1 = require("../utils/depMatch");
23
- function addJavaScriptRules(opts) {
11
+ async function addJavaScriptRules(opts) {
24
12
  var _a, _b;
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const { config, userConfig, cwd, name } = opts;
27
- const isDev = opts.env === types_1.Env.development;
28
- const useFastRefresh = isDev && userConfig.fastRefresh !== false && name !== constants_1.MFSU_NAME;
29
- const depPkgs = Object.assign({}, (0, depMatch_1.es5ImcompatibleVersionsToPkg)());
30
- const srcRules = [
31
- config.module
32
- .rule('src')
33
- .test(/\.(js|mjs)$/)
34
- .include.add([
35
- cwd,
36
- // import module out of cwd using APP_ROOT
37
- // issue: https://github.com/umijs/umi/issues/5594
38
- ...(process.env.APP_ROOT ? [process.cwd()] : []),
39
- ])
40
- .end()
41
- .exclude.add(/node_modules/)
42
- .end(),
43
- config.module.rule('jsx-ts-tsx').test(/\.(jsx|ts|tsx)$/),
44
- config.module
45
- .rule('extra-src')
46
- .test(/\.(js|mjs)$/)
47
- .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
48
42
  try {
49
- if (path.includes('client/client'))
50
- return true;
51
- 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] }));
52
47
  }
53
48
  catch (e) {
54
- console.error(utils_1.chalk.red(e));
49
+ if (e.code === 'MODULE_NOT_FOUND') {
50
+ throw new Error('Cannot resolve extraBabelIncludes: ' + p);
51
+ }
55
52
  throw e;
56
53
  }
57
- })
58
- .end(),
59
- ];
60
- if (userConfig.mdx) {
61
- srcRules.push(config.module.rule('markdown').test(/\.mdx?$/));
62
- }
63
- const depRules = [
64
- config.module
65
- .rule('dep')
66
- .test(/\.(js|mjs)$/)
67
- .include.add(/node_modules/)
68
- .end()
69
- .exclude.add((path) => {
54
+ }),
55
+ // support es5ImcompatibleVersions
56
+ (path) => {
70
57
  try {
58
+ // do src transform for bundler-webpack/client/client/client.js
59
+ if (path.includes('client/client/client'))
60
+ return true;
71
61
  return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
72
62
  }
73
63
  catch (e) {
74
64
  console.error(utils_1.chalk.red(e));
75
65
  throw e;
76
66
  }
77
- })
78
- .end(),
79
- ];
80
- // const prefix = existsSync(join(cwd, 'src')) ? join(cwd, 'src') : cwd;
81
- const srcTranspiler = userConfig.srcTranspiler || types_1.Transpiler.babel;
82
- srcRules.forEach((rule) => {
83
- if (srcTranspiler === types_1.Transpiler.babel) {
84
- rule
85
- .use('babel-loader')
86
- .loader(require.resolve('../../compiled/babel-loader'))
87
- .options({
88
- // Tell babel to guess the type, instead assuming all files are modules
89
- // https://github.com/webpack/webpack/issues/4039#issuecomment-419284940
90
- sourceType: 'unambiguous',
91
- babelrc: false,
92
- cacheDirectory: false,
93
- // process.env.BABEL_CACHE !== 'none'
94
- // ? join(cwd, `.umi/.cache/babel-loader`)
95
- // : false,
96
- targets: userConfig.targets,
97
- presets: [
98
- opts.babelPreset || [
99
- require.resolve('@umijs/babel-preset-umi'),
100
- {
101
- presetEnv: {},
102
- presetReact: {},
103
- presetTypeScript: {},
104
- pluginTransformRuntime: {},
105
- pluginLockCoreJS: {},
106
- pluginDynamicImportNode: false,
107
- pluginAutoCSSModules: userConfig.autoCSSModules,
108
- },
109
- ],
110
- ...opts.extraBabelPresets,
111
- ...(userConfig.extraBabelPresets || []).filter(Boolean),
112
- ],
113
- plugins: [
114
- useFastRefresh && require.resolve('react-refresh/babel'),
115
- ...opts.extraBabelPlugins,
116
- ...(userConfig.extraBabelPlugins || []),
117
- ].filter(Boolean),
118
- });
119
- }
120
- else if (srcTranspiler === types_1.Transpiler.swc) {
121
- rule
122
- .use('swc-loader')
123
- .loader(require.resolve('../loader/swc'))
124
- .options({
125
- plugin: (m) => new autoCSSModules_1.default().visitProgram(m),
126
- });
127
- }
128
- else if (srcTranspiler === types_1.Transpiler.esbuild) {
129
- rule
130
- .use('esbuild-loader')
131
- .loader(mfsu_1.esbuildLoader)
132
- .options({
133
- target: isDev ? 'esnext' : 'es2015',
134
- handler: [mfsu_1.autoCssModulesHandler, ...opts.extraEsbuildLoaderHandler],
135
- });
136
- // esbuild loader can not auto import `React`
137
- config.plugin('react-provide-plugin').use(webpack_1.ProvidePlugin, [
138
- {
139
- React: 'react',
140
- },
141
- ]);
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 });
142
83
  }
143
- else {
144
- throw new Error(`Unsupported srcTranspiler ${srcTranspiler}.`);
84
+ catch (e) {
85
+ console.error(utils_1.chalk.red(e));
86
+ throw e;
145
87
  }
146
- });
147
- if (userConfig.mdx) {
148
- config.module
149
- .rule('mdx')
150
- .test(/\.mdx?$/)
151
- .use('mdx-loader')
152
- .loader((_a = userConfig.mdx) === null || _a === void 0 ? void 0 : _a.loader)
153
- .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}.`);
154
177
  }
155
- const depTranspiler = userConfig.depTranspiler || types_1.Transpiler.none;
156
- depRules.forEach((_rule) => {
157
- if (depTranspiler === types_1.Transpiler.none) {
158
- // noop
159
- }
160
- else {
161
- throw new Error(`Unsupported depTranspiler ${depTranspiler}.`);
162
- }
163
- });
164
178
  });
165
179
  }
166
180
  exports.addJavaScriptRules = addJavaScriptRules;
@@ -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,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.addMiniCSSExtractPlugin = void 0;
16
7
  // @ts-ignore
17
8
  const mini_css_extract_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/mini-css-extract-plugin"));
18
- 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: `[name]${hash}.chunk.css`,
17
+ ignoreOrder: true,
18
+ },
19
+ ]);
20
+ }
32
21
  }
33
22
  exports.addMiniCSSExtractPlugin = addMiniCSSExtractPlugin;
@@ -1,26 +1,18 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.addNodePolyfill = void 0;
13
4
  const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
14
- function addNodePolyfill(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config } = opts;
17
- const nodeLibs = require('node-libs-browser');
18
- config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
19
- {
20
- Buffer: ['buffer', 'Buffer'],
21
- },
22
- ]);
23
- config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
5
+ async function addNodePolyfill(opts) {
6
+ const { config } = opts;
7
+ const nodeLibs = require('node-libs-browser');
8
+ config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
9
+ {
10
+ Buffer: ['buffer', 'Buffer'],
11
+ process: nodeLibs['process'],
12
+ },
13
+ ]);
14
+ config.resolve.fallback.merge({
15
+ ...Object.keys(nodeLibs).reduce((memo, key) => {
24
16
  if (nodeLibs[key]) {
25
17
  memo[key] = nodeLibs[key];
26
18
  }
@@ -28,7 +20,9 @@ function addNodePolyfill(opts) {
28
20
  memo[key] = false;
29
21
  }
30
22
  return memo;
31
- }, {})), { http: false, https: false }));
23
+ }, {}),
24
+ http: false,
25
+ https: false,
32
26
  });
33
27
  }
34
28
  exports.addNodePolyfill = addNodePolyfill;
@@ -0,0 +1,11 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { Env, IConfig } from '../types';
3
+ interface IOpts {
4
+ name?: string;
5
+ config: Config;
6
+ userConfig: IConfig;
7
+ cwd: string;
8
+ env: Env;
9
+ }
10
+ export declare function addNodePrefixPlugin(opts: IOpts): Promise<void>;
11
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addNodePrefixPlugin = void 0;
4
+ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
5
+ async function addNodePrefixPlugin(opts) {
6
+ const { config } = opts;
7
+ config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
8
+ /^node:/,
9
+ (resource) => {
10
+ resource.request = resource.request.replace(/^node:/, '');
11
+ },
12
+ ]);
13
+ }
14
+ exports.addNodePrefixPlugin = addNodePrefixPlugin;
@@ -1,27 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.addProgressPlugin = void 0;
16
7
  const ProgressPlugin_1 = __importDefault(require("../plugins/ProgressPlugin"));
17
- function addProgressPlugin(opts) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const { config, name } = opts;
20
- config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
21
- {
22
- name,
23
- },
24
- ]);
25
- });
8
+ async function addProgressPlugin(opts) {
9
+ const { config, name } = opts;
10
+ config.plugin('progress-plugin').use(ProgressPlugin_1.default, [
11
+ {
12
+ name,
13
+ },
14
+ ]);
26
15
  }
27
16
  exports.addProgressPlugin = addProgressPlugin;
@@ -1,32 +1,21 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.applyPurgeCSSWebpackPlugin = void 0;
13
4
  const types_1 = require("../types");
14
- function applyPurgeCSSWebpackPlugin(opts) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const { config, userConfig, cwd, env } = opts;
17
- config;
18
- userConfig;
19
- cwd;
20
- env;
21
- if (userConfig.purgeCSS && env === types_1.Env.production) {
22
- config
23
- .plugin('purgecss-webpack-plugin')
24
- .use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
25
- {
26
- paths: [],
27
- },
28
- ]);
29
- }
30
- });
5
+ async function applyPurgeCSSWebpackPlugin(opts) {
6
+ const { config, userConfig, cwd, env } = opts;
7
+ config;
8
+ userConfig;
9
+ cwd;
10
+ env;
11
+ if (userConfig.purgeCSS && env === types_1.Env.production) {
12
+ config
13
+ .plugin('purgecss-webpack-plugin')
14
+ .use(require('@umijs/bundler-webpack/compiled/purgecss-webpack-plugin'), [
15
+ {
16
+ paths: [],
17
+ },
18
+ ]);
19
+ }
31
20
  }
32
21
  exports.applyPurgeCSSWebpackPlugin = applyPurgeCSSWebpackPlugin;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -16,19 +7,17 @@ exports.addSpeedMeasureWebpackPlugin = void 0;
16
7
  // @ts-ignore
17
8
  const speed_measure_webpack_plugin_1 = __importDefault(require("@umijs/bundler-webpack/compiled/speed-measure-webpack-plugin"));
18
9
  const path_1 = require("path");
19
- function addSpeedMeasureWebpackPlugin(opts) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- let webpackConfig = opts.webpackConfig;
22
- if (process.env.SPEED_MEASURE) {
23
- const smpOption = process.env.SPEED_MEASURE === 'JSON'
24
- ? {
25
- outputFormat: 'json',
26
- outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
27
- }
28
- : { outputFormat: 'human', outputTarget: console.log };
29
- webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
30
- }
31
- return webpackConfig;
32
- });
10
+ async function addSpeedMeasureWebpackPlugin(opts) {
11
+ let webpackConfig = opts.webpackConfig;
12
+ if (process.env.SPEED_MEASURE) {
13
+ const smpOption = process.env.SPEED_MEASURE === 'JSON'
14
+ ? {
15
+ outputFormat: 'json',
16
+ outputTarget: (0, path_1.join)(process.cwd(), 'SPEED_MEASURE.json'),
17
+ }
18
+ : { outputFormat: 'human', outputTarget: console.log };
19
+ webpackConfig = new speed_measure_webpack_plugin_1.default(smpOption).wrap(webpackConfig);
20
+ }
21
+ return webpackConfig;
33
22
  }
34
23
  exports.addSpeedMeasureWebpackPlugin = addSpeedMeasureWebpackPlugin;