@umijs/bundler-webpack 4.0.7 → 4.0.10

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 -68
  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 +114 -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.js +71 -35
  19. package/dist/config/detectDeadCode.js +120 -108
  20. package/dist/config/detectDeadCodePlugin.js +78 -63
  21. package/dist/config/fastRefreshPlugin.js +39 -20
  22. package/dist/config/forkTSCheckerPlugin.js +38 -19
  23. package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
  24. package/dist/config/ignorePlugin.js +38 -14
  25. package/dist/config/javaScriptRules.js +147 -173
  26. package/dist/config/manifestPlugin.js +51 -15
  27. package/dist/config/miniCSSExtractPlugin.js +42 -22
  28. package/dist/config/nodePolyfill.js +65 -26
  29. package/dist/config/nodePrefixPlugin.js +36 -12
  30. package/dist/config/progressPlugin.js +37 -13
  31. package/dist/config/purgecssWebpackPlugin.js +41 -19
  32. package/dist/config/speedMeasureWebpackPlugin.js +41 -20
  33. package/dist/config/ssrPlugin.js +83 -63
  34. package/dist/config/svgRules.js +74 -46
  35. package/dist/constants.js +57 -22
  36. package/dist/dev.d.ts +1 -1
  37. package/dist/dev.js +174 -134
  38. package/dist/index.js +22 -20
  39. package/dist/loader/svgr.js +73 -54
  40. package/dist/loader/swc.js +110 -69
  41. package/dist/parcelCSS.js +31 -27
  42. package/dist/plugins/ProgressPlugin.js +66 -43
  43. package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
  44. package/dist/plugins/_SamplePlugin.js +39 -14
  45. package/dist/requireHook.js +37 -27
  46. package/dist/schema.js +123 -96
  47. package/dist/server/server.d.ts +0 -1
  48. package/dist/server/server.js +214 -184
  49. package/dist/server/ws.d.ts +0 -2
  50. package/dist/server/ws.js +63 -38
  51. package/dist/swcPlugins/autoCSSModules.js +50 -31
  52. package/dist/swcPlugins/changeImportFromString.js +31 -9
  53. package/dist/swcPlugins/lockCoreJS.js +44 -20
  54. package/dist/types.d.ts +2 -1
  55. package/dist/types.js +61 -30
  56. package/dist/utils/browsersList.js +31 -8
  57. package/dist/utils/depMatch.js +63 -39
  58. package/dist/utils/formatWebpackMessages.js +93 -91
  59. package/dist/utils/getEsBuildTarget.d.ts +3 -1
  60. package/dist/utils/getEsBuildTarget.js +39 -11
  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
package/dist/schema.js CHANGED
@@ -1,99 +1,126 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSchemas = void 0;
4
- const types_1 = require("./types");
5
- const options = [
6
- 'cheap-source-map',
7
- 'cheap-module-source-map',
8
- 'eval',
9
- 'eval-source-map',
10
- 'eval-cheap-source-map',
11
- 'eval-cheap-module-source-map',
12
- 'eval-nosources-cheap-source-map',
13
- 'eval-nosources-cheap-module-source-map',
14
- 'eval-nosources-source-map',
15
- 'source-map',
16
- 'hidden-source-map',
17
- 'hidden-nosources-cheap-source-map',
18
- 'hidden-nosources-cheap-module-source-map',
19
- 'hidden-nosources-source-map',
20
- 'hidden-cheap-source-map',
21
- 'hidden-cheap-module-source-map',
22
- 'inline-source-map',
23
- 'inline-cheap-source-map',
24
- 'inline-cheap-module-source-map',
25
- 'inline-nosources-cheap-source-map',
26
- 'inline-nosources-cheap-module-source-map',
27
- 'inline-nosources-source-map',
28
- 'nosources-source-map',
29
- 'nosources-cheap-source-map',
30
- 'nosources-cheap-module-source-map',
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
+ // src/schema.ts
20
+ var schema_exports = {};
21
+ __export(schema_exports, {
22
+ getSchemas: () => getSchemas
23
+ });
24
+ module.exports = __toCommonJS(schema_exports);
25
+ var import_types = require("./types");
26
+ var options = [
27
+ "cheap-source-map",
28
+ "cheap-module-source-map",
29
+ "eval",
30
+ "eval-source-map",
31
+ "eval-cheap-source-map",
32
+ "eval-cheap-module-source-map",
33
+ "eval-nosources-cheap-source-map",
34
+ "eval-nosources-cheap-module-source-map",
35
+ "eval-nosources-source-map",
36
+ "source-map",
37
+ "hidden-source-map",
38
+ "hidden-nosources-cheap-source-map",
39
+ "hidden-nosources-cheap-module-source-map",
40
+ "hidden-nosources-source-map",
41
+ "hidden-cheap-source-map",
42
+ "hidden-cheap-module-source-map",
43
+ "inline-source-map",
44
+ "inline-cheap-source-map",
45
+ "inline-cheap-module-source-map",
46
+ "inline-nosources-cheap-source-map",
47
+ "inline-nosources-cheap-module-source-map",
48
+ "inline-nosources-source-map",
49
+ "nosources-source-map",
50
+ "nosources-cheap-source-map",
51
+ "nosources-cheap-module-source-map"
31
52
  ];
32
- const DEVTOOL_REGEX = new RegExp('^' + // start of string
33
- '(#@|@|#)?' + // maybe one of the pragmas
34
- `(${options.join('$|')})`);
53
+ var DEVTOOL_REGEX = new RegExp(`^(#@|@|#)?(${options.join("$|")})`);
35
54
  function getSchemas() {
36
- return {
37
- alias: (Joi) => Joi.object(),
38
- autoCSSModules: (Joi) => Joi.boolean(),
39
- autoprefixer: (Joi) => Joi.object(),
40
- cacheDirectoryPath: (Joi) => Joi.string(),
41
- chainWebpack: (Joi) => Joi.function(),
42
- copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
43
- from: Joi.string(),
44
- to: Joi.string(),
45
- }), Joi.string())),
46
- cssLoader: (Joi) => Joi.object(),
47
- cssLoaderModules: (Joi) => Joi.object(),
48
- cssMinifier: (Joi) => Joi.string().valid(types_1.CSSMinifier.cssnano, types_1.CSSMinifier.esbuild, types_1.CSSMinifier.parcelCSS, types_1.CSSMinifier.none),
49
- cssMinifierOptions: (Joi) => Joi.object(),
50
- deadCode: (Joi) => Joi.object(),
51
- define: (Joi) => Joi.object(),
52
- depTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
53
- devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
54
- esm: (Joi) => Joi.object(),
55
- externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
56
- extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
57
- extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
58
- extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
59
- extraPostCSSPlugins: (Joi) => Joi.array(),
60
- fastRefresh: (Joi) => Joi.boolean(),
61
- forkTSChecker: (Joi) => Joi.object(),
62
- hash: (Joi) => Joi.boolean(),
63
- https: (Joi) => Joi.object(),
64
- ignoreMomentLocale: (Joi) => Joi.boolean(),
65
- inlineLimit: (Joi) => Joi.number(),
66
- jsMinifier: (Joi) => Joi.string().valid(types_1.JSMinifier.esbuild, types_1.JSMinifier.swc, types_1.JSMinifier.terser, types_1.JSMinifier.uglifyJs, types_1.JSMinifier.none),
67
- jsMinifierOptions: (Joi) => Joi.object(),
68
- lessLoader: (Joi) => Joi.object(),
69
- manifest: (Joi) => Joi.object(),
70
- mdx: (Joi) => Joi.object({
71
- loader: Joi.string(),
72
- loaderOptions: Joi.object(),
73
- }),
74
- mfsu: (Joi) => Joi.alternatives(Joi.object({
75
- cacheDirectory: Joi.string(),
76
- chainWebpack: Joi.function(),
77
- esbuild: Joi.boolean(),
78
- include: Joi.array().items(Joi.string()),
79
- mfName: Joi.string(),
80
- runtimePublicPath: Joi.boolean(),
81
- strategy: Joi.string().valid('eager', 'normal').default('normal'),
82
- }), Joi.boolean()),
83
- outputPath: (Joi) => Joi.string(),
84
- postcssLoader: (Joi) => Joi.object(),
85
- proxy: (Joi) => Joi.object(),
86
- publicPath: (Joi) => Joi.string(),
87
- purgeCSS: (Joi) => Joi.object(),
88
- runtimePublicPath: (Joi) => Joi.object(),
89
- sassLoader: (Joi) => Joi.object(),
90
- srcTranspiler: (Joi) => Joi.string().valid(types_1.Transpiler.babel, types_1.Transpiler.esbuild, types_1.Transpiler.swc, types_1.Transpiler.none),
91
- styleLoader: (Joi) => Joi.object(),
92
- svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
93
- svgr: (Joi) => Joi.object(),
94
- targets: (Joi) => Joi.object(),
95
- theme: (Joi) => Joi.object(),
96
- writeToDisk: (Joi) => Joi.boolean(),
97
- };
55
+ return {
56
+ alias: (Joi) => Joi.object(),
57
+ autoCSSModules: (Joi) => Joi.boolean(),
58
+ autoprefixer: (Joi) => Joi.object(),
59
+ babelLoaderCustomize: (Joi) => Joi.string(),
60
+ cacheDirectoryPath: (Joi) => Joi.string(),
61
+ chainWebpack: (Joi) => Joi.function(),
62
+ copy: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.object({
63
+ from: Joi.string(),
64
+ to: Joi.string()
65
+ }), Joi.string())),
66
+ cssLoader: (Joi) => Joi.object(),
67
+ cssLoaderModules: (Joi) => Joi.object(),
68
+ cssMinifier: (Joi) => Joi.string().valid(import_types.CSSMinifier.cssnano, import_types.CSSMinifier.esbuild, import_types.CSSMinifier.parcelCSS, import_types.CSSMinifier.none),
69
+ cssMinifierOptions: (Joi) => Joi.object(),
70
+ deadCode: (Joi) => Joi.object(),
71
+ define: (Joi) => Joi.object(),
72
+ depTranspiler: (Joi) => Joi.string().valid(import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc, import_types.Transpiler.none),
73
+ devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
74
+ esm: (Joi) => Joi.object(),
75
+ externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
76
+ extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
77
+ extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
78
+ extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
79
+ extraPostCSSPlugins: (Joi) => Joi.array(),
80
+ fastRefresh: (Joi) => Joi.boolean(),
81
+ forkTSChecker: (Joi) => Joi.object(),
82
+ hash: (Joi) => Joi.boolean(),
83
+ https: (Joi) => Joi.object(),
84
+ ignoreMomentLocale: (Joi) => Joi.boolean(),
85
+ inlineLimit: (Joi) => Joi.number(),
86
+ jsMinifier: (Joi) => Joi.string().valid(import_types.JSMinifier.esbuild, import_types.JSMinifier.swc, import_types.JSMinifier.terser, import_types.JSMinifier.uglifyJs, import_types.JSMinifier.none),
87
+ jsMinifierOptions: (Joi) => Joi.object(),
88
+ lessLoader: (Joi) => Joi.object(),
89
+ manifest: (Joi) => Joi.object(),
90
+ mdx: (Joi) => Joi.object({
91
+ loader: Joi.string(),
92
+ loaderOptions: Joi.object()
93
+ }),
94
+ mfsu: (Joi) => Joi.alternatives(Joi.object({
95
+ cacheDirectory: Joi.string(),
96
+ chainWebpack: Joi.function(),
97
+ esbuild: Joi.boolean(),
98
+ exclude: Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.object().regex())),
99
+ include: Joi.array().items(Joi.string()),
100
+ mfName: Joi.string(),
101
+ remoteAliases: Joi.array().items(Joi.string()),
102
+ remoteName: Joi.string(),
103
+ runtimePublicPath: Joi.boolean(),
104
+ shared: Joi.object(),
105
+ strategy: Joi.string().valid("eager", "normal").default("normal")
106
+ }), Joi.boolean()),
107
+ outputPath: (Joi) => Joi.string(),
108
+ postcssLoader: (Joi) => Joi.object(),
109
+ proxy: (Joi) => Joi.alternatives().try(Joi.object(), Joi.array()),
110
+ publicPath: (Joi) => Joi.string(),
111
+ purgeCSS: (Joi) => Joi.object(),
112
+ runtimePublicPath: (Joi) => Joi.object(),
113
+ sassLoader: (Joi) => Joi.object(),
114
+ srcTranspiler: (Joi) => Joi.string().valid(import_types.Transpiler.babel, import_types.Transpiler.esbuild, import_types.Transpiler.swc, import_types.Transpiler.none),
115
+ styleLoader: (Joi) => Joi.object(),
116
+ svgo: (Joi) => Joi.alternatives().try(Joi.object(), Joi.boolean()),
117
+ svgr: (Joi) => Joi.object(),
118
+ targets: (Joi) => Joi.object(),
119
+ theme: (Joi) => Joi.object(),
120
+ writeToDisk: (Joi) => Joi.boolean()
121
+ };
98
122
  }
99
- exports.getSchemas = getSchemas;
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ getSchemas
126
+ });
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
4
3
  import http from 'http';
5
4
  import { IConfig } from '../types';
@@ -1,196 +1,226 @@
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 __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
4
35
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createServer = void 0;
7
- const bundler_utils_1 = require("@umijs/bundler-utils");
8
- const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
9
- const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
10
- const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
11
- const utils_1 = require("@umijs/utils");
12
- const cors_1 = __importDefault(require("cors"));
13
- const fs_1 = require("fs");
14
- const http_1 = __importDefault(require("http"));
15
- const path_1 = require("path");
16
- const constants_1 = require("../constants");
17
- const ws_1 = require("./ws");
36
+ 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));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/server/server.ts
40
+ var server_exports = {};
41
+ __export(server_exports, {
42
+ createServer: () => createServer
43
+ });
44
+ module.exports = __toCommonJS(server_exports);
45
+ var import_bundler_utils = require("@umijs/bundler-utils");
46
+ var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
47
+ var import_http_proxy_middleware = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
48
+ var import_webpack = __toESM(require("@umijs/bundler-webpack/compiled/webpack"));
49
+ var import_utils = require("@umijs/utils");
50
+ var import_assert = __toESM(require("assert"));
51
+ var import_cors = __toESM(require("cors"));
52
+ var import_fs = require("fs");
53
+ var import_http = __toESM(require("http"));
54
+ var import_path = require("path");
55
+ var import_constants = require("../constants");
56
+ var import_ws = require("./ws");
18
57
  async function createServer(opts) {
19
- const { webpackConfig, userConfig } = opts;
20
- const { proxy } = userConfig;
21
- const app = (0, express_1.default)();
22
- // cros
23
- app.use((0, cors_1.default)({
24
- origin: true,
25
- methods: ['GET', 'HEAD', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS'],
26
- credentials: true,
27
- }));
28
- // compression
29
- app.use(require('@umijs/bundler-webpack/compiled/compression')());
30
- // debug all js file
31
- app.use((req, res, next) => {
32
- const file = req.path;
33
- const filePath = (0, path_1.join)(opts.cwd, file);
34
- const ext = (0, path_1.extname)(filePath);
35
- if (ext === '.js' && (0, fs_1.existsSync)(filePath)) {
36
- utils_1.logger.info('[dev]', `${file} is responded with ${filePath}, remove it to use original file`);
37
- res.sendFile(filePath);
38
- }
39
- else {
40
- next();
41
- }
42
- });
43
- // before middlewares
44
- (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
45
- // webpack dev middleware
46
- const configs = Array.isArray(webpackConfig)
47
- ? webpackConfig
48
- : [webpackConfig];
49
- const progresses = [];
50
- if (opts.onProgress) {
51
- configs.forEach((config) => {
52
- const progress = {
53
- percent: 0,
54
- status: 'waiting',
55
- };
56
- progresses.push(progress);
57
- config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
58
- progress.percent = percent;
59
- progress.status = msg;
60
- opts.onProgress({ progresses });
61
- }));
62
- });
58
+ const { webpackConfig, userConfig } = opts;
59
+ const { proxy } = userConfig;
60
+ const app = (0, import_express.default)();
61
+ app.use((0, import_cors.default)({
62
+ origin: true,
63
+ methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
64
+ credentials: true
65
+ }));
66
+ app.use(require("@umijs/bundler-webpack/compiled/compression")());
67
+ app.use((req, res, next) => {
68
+ const file = req.path;
69
+ const filePath = (0, import_path.join)(opts.cwd, file);
70
+ const ext = (0, import_path.extname)(filePath);
71
+ if (ext === ".js" && (0, import_fs.existsSync)(filePath)) {
72
+ import_utils.logger.info("[dev]", `${file} is responded with ${filePath}, remove it to use original file`);
73
+ res.sendFile(filePath);
74
+ } else {
75
+ next();
63
76
  }
64
- const compiler = (0, webpack_1.default)(configs);
65
- const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
66
- const compilerMiddleware = webpackDevMiddleware(compiler, {
67
- publicPath: userConfig.publicPath || '/',
68
- writeToDisk: userConfig.writeToDisk,
69
- stats: 'none',
70
- // watchOptions: { ignored }
77
+ });
78
+ (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
79
+ const configs = Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig];
80
+ const progresses = [];
81
+ if (opts.onProgress) {
82
+ configs.forEach((config) => {
83
+ const progress = {
84
+ percent: 0,
85
+ status: "waiting"
86
+ };
87
+ progresses.push(progress);
88
+ config.plugins.push(new import_webpack.default.ProgressPlugin((percent, msg) => {
89
+ progress.percent = percent;
90
+ progress.status = msg;
91
+ opts.onProgress({ progresses });
92
+ }));
71
93
  });
72
- app.use(compilerMiddleware);
73
- // hmr hooks
74
- let stats;
75
- let isFirstCompile = true;
76
- compiler.compilers.forEach(addHooks);
77
- function addHooks(compiler) {
78
- compiler.hooks.invalid.tap('server', () => {
79
- sendMessage(constants_1.MESSAGE_TYPE.invalid);
80
- });
81
- compiler.hooks.done.tap('server', (_stats) => {
82
- var _a;
83
- stats = _stats;
84
- sendStats(getStats(stats));
85
- (_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
86
- stats,
87
- isFirstCompile,
88
- time: stats.endTime - stats.startTime,
89
- });
90
- isFirstCompile = false;
91
- });
92
- }
93
- function sendStats(stats, force, sender) {
94
- const shouldEmit = !force &&
95
- stats &&
96
- (!stats.errors || stats.errors.length === 0) &&
97
- (!stats.warnings || stats.warnings.length === 0) &&
98
- stats.assets &&
99
- stats.assets.every((asset) => !asset.emitted);
100
- if (shouldEmit) {
101
- sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
102
- return;
103
- }
104
- sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
105
- if ((stats.errors && stats.errors.length > 0) ||
106
- (stats.warnings && stats.warnings.length > 0)) {
107
- if (stats.warnings && stats.warnings.length > 0) {
108
- sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
109
- }
110
- if (stats.errors && stats.errors.length > 0) {
111
- sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
112
- }
113
- }
114
- else {
115
- sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
116
- }
117
- }
118
- function getStats(stats) {
119
- return stats.toJson({
120
- all: false,
121
- hash: true,
122
- assets: true,
123
- warnings: true,
124
- errors: true,
125
- errorDetails: false,
126
- });
127
- }
128
- function sendMessage(type, data, sender) {
129
- (sender || ws).send(JSON.stringify({ type, data }));
94
+ }
95
+ const compiler = (0, import_webpack.default)(configs);
96
+ const webpackDevMiddleware = require("@umijs/bundler-webpack/compiled/webpack-dev-middleware");
97
+ const compilerMiddleware = webpackDevMiddleware(compiler, {
98
+ publicPath: userConfig.publicPath || "/",
99
+ writeToDisk: userConfig.writeToDisk,
100
+ stats: "none"
101
+ });
102
+ app.use(compilerMiddleware);
103
+ let stats;
104
+ let isFirstCompile = true;
105
+ compiler.compilers.forEach(addHooks);
106
+ function addHooks(compiler2) {
107
+ compiler2.hooks.invalid.tap("server", () => {
108
+ sendMessage(import_constants.MESSAGE_TYPE.invalid);
109
+ });
110
+ compiler2.hooks.done.tap("server", (_stats) => {
111
+ var _a;
112
+ stats = _stats;
113
+ sendStats(getStats(stats));
114
+ (_a = opts.onDevCompileDone) == null ? void 0 : _a.call(opts, {
115
+ stats,
116
+ isFirstCompile,
117
+ time: stats.endTime - stats.startTime
118
+ });
119
+ isFirstCompile = false;
120
+ });
121
+ }
122
+ function sendStats(stats2, force, sender) {
123
+ const shouldEmit = !force && stats2 && (!stats2.errors || stats2.errors.length === 0) && (!stats2.warnings || stats2.warnings.length === 0) && stats2.assets && stats2.assets.every((asset) => !asset.emitted);
124
+ if (shouldEmit) {
125
+ sendMessage(import_constants.MESSAGE_TYPE.stillOk, null, sender);
126
+ return;
130
127
  }
131
- // mock
132
- // proxy
133
- if (proxy) {
134
- Object.keys(proxy).forEach((key) => {
135
- const proxyConfig = proxy[key];
136
- const target = proxyConfig.target;
137
- if (target) {
138
- app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
139
- ...proxy[key],
140
- // Add x-real-url in response header
141
- onProxyRes(proxyRes, req, res) {
142
- var _a, _b;
143
- proxyRes.headers['x-real-url'] =
144
- ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
145
- (_b = proxyConfig.onProxyRes) === null || _b === void 0 ? void 0 : _b.call(proxyConfig, proxyRes, req, res);
146
- },
147
- }));
148
- }
149
- });
128
+ sendMessage(import_constants.MESSAGE_TYPE.hash, stats2.hash, sender);
129
+ if (stats2.errors && stats2.errors.length > 0 || stats2.warnings && stats2.warnings.length > 0) {
130
+ if (stats2.warnings && stats2.warnings.length > 0) {
131
+ sendMessage(import_constants.MESSAGE_TYPE.warnings, stats2.warnings, sender);
132
+ }
133
+ if (stats2.errors && stats2.errors.length > 0) {
134
+ sendMessage(import_constants.MESSAGE_TYPE.errors, stats2.errors, sender);
135
+ }
136
+ } else {
137
+ sendMessage(import_constants.MESSAGE_TYPE.ok, null, sender);
150
138
  }
151
- // after middlewares
152
- (opts.afterMiddlewares || []).forEach((m) => {
153
- // TODO: FIXME
154
- app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
139
+ }
140
+ function getStats(stats2) {
141
+ return stats2.toJson({
142
+ all: false,
143
+ hash: true,
144
+ assets: true,
145
+ warnings: true,
146
+ errors: true,
147
+ errorDetails: false
155
148
  });
156
- // history fallback
157
- app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
158
- index: '/',
159
- }));
160
- // hmr reconnect ping
161
- app.use('/__umi_ping', (_, res) => {
162
- res.end('pong');
149
+ }
150
+ function sendMessage(type, data, sender) {
151
+ (sender || ws).send(JSON.stringify({ type, data }));
152
+ }
153
+ if (proxy) {
154
+ const proxyArr = Array.isArray(proxy) ? proxy : proxy.target ? [proxy] : Object.keys(proxy).map((key) => {
155
+ return __spreadProps(__spreadValues({}, proxy[key]), {
156
+ context: key
157
+ });
163
158
  });
164
- // index.html
165
- // TODO: remove me
166
- app.get('/', (_req, res, next) => {
167
- res.set('Content-Type', 'text/html');
168
- const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
169
- if ((0, fs_1.existsSync)(htmlPath)) {
170
- (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
171
- }
172
- else {
173
- next();
159
+ proxyArr.forEach((proxy2) => {
160
+ let middleware;
161
+ if (proxy2.target) {
162
+ (0, import_assert.default)(typeof proxy2.target === "string", "proxy.target must be string");
163
+ (0, import_assert.default)(proxy2.context, "proxy.context must be supplied");
164
+ middleware = (0, import_http_proxy_middleware.createProxyMiddleware)(proxy2.context, __spreadProps(__spreadValues({}, proxy2), {
165
+ onProxyRes(proxyRes, req, res) {
166
+ var _a, _b;
167
+ proxyRes.headers["x-real-url"] = ((_a = new URL(req.url || "", proxy2.target)) == null ? void 0 : _a.href) || "";
168
+ (_b = proxy2.onProxyRes) == null ? void 0 : _b.call(proxy2, proxyRes, req, res);
169
+ }
170
+ }));
171
+ }
172
+ app.use((req, res, next) => {
173
+ const bypassUrl = typeof proxy2.bypass === "function" ? proxy2.bypass(req, res, proxy2) : null;
174
+ if (typeof bypassUrl === "string") {
175
+ req.url = bypassUrl;
176
+ return next();
177
+ } else if (bypassUrl === false) {
178
+ return res.end(404);
179
+ } else if ((bypassUrl === null || bypassUrl === void 0) && middleware) {
180
+ return middleware(req, res, next);
181
+ } else {
182
+ next();
174
183
  }
184
+ });
175
185
  });
176
- const server = userConfig.https
177
- ? await (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
178
- : http_1.default.createServer(app);
179
- if (!server) {
180
- return null;
186
+ }
187
+ (opts.afterMiddlewares || []).forEach((m) => {
188
+ app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
189
+ });
190
+ app.use(require("@umijs/bundler-webpack/compiled/connect-history-api-fallback")({
191
+ index: "/"
192
+ }));
193
+ app.use("/__umi_ping", (_, res) => {
194
+ res.end("pong");
195
+ });
196
+ app.get("/", (_req, res, next) => {
197
+ res.set("Content-Type", "text/html");
198
+ const htmlPath = (0, import_path.join)(opts.cwd, "index.html");
199
+ if ((0, import_fs.existsSync)(htmlPath)) {
200
+ (0, import_fs.createReadStream)(htmlPath).on("error", next).pipe(res);
201
+ } else {
202
+ next();
181
203
  }
182
- const ws = (0, ws_1.createWebSocketServer)(server);
183
- ws.wss.on('connection', (socket) => {
184
- if (stats) {
185
- sendStats(getStats(stats), false, socket);
186
- }
187
- });
188
- const protocol = userConfig.https ? 'https:' : 'http:';
189
- const port = opts.port || 8000;
190
- server.listen(port, () => {
191
- const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : 'localhost';
192
- utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
193
- });
194
- return server;
204
+ });
205
+ const server = userConfig.https ? await (0, import_bundler_utils.createHttpsServer)(app, userConfig.https) : import_http.default.createServer(app);
206
+ if (!server) {
207
+ return null;
208
+ }
209
+ const ws = (0, import_ws.createWebSocketServer)(server);
210
+ ws.wss.on("connection", (socket) => {
211
+ if (stats) {
212
+ sendStats(getStats(stats), false, socket);
213
+ }
214
+ });
215
+ const protocol = userConfig.https ? "https:" : "http:";
216
+ const port = opts.port || 8e3;
217
+ server.listen(port, () => {
218
+ const host = opts.host && opts.host !== "0.0.0.0" ? opts.host : "localhost";
219
+ import_utils.logger.ready(`App listening at ${import_utils.chalk.green(`${protocol}//${host}:${port}`)}`);
220
+ });
221
+ return server;
195
222
  }
196
- exports.createServer = createServer;
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ createServer
226
+ });