@umijs/bundler-webpack 4.0.0-rc.14 → 4.0.0-rc.17

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 (39) hide show
  1. package/dist/build.js +48 -59
  2. package/dist/cli.js +6 -15
  3. package/dist/client/client.js +34 -47
  4. package/dist/config/_sampleFeature.js +6 -17
  5. package/dist/config/assetRules.js +44 -55
  6. package/dist/config/bundleAnalyzerPlugin.js +12 -23
  7. package/dist/config/compressPlugin.js +68 -76
  8. package/dist/config/config.js +177 -185
  9. package/dist/config/copyPlugin.js +29 -40
  10. package/dist/config/cssRules.js +93 -83
  11. package/dist/config/definePlugin.js +11 -19
  12. package/dist/config/detectDeadCodePlugin.js +16 -21
  13. package/dist/config/fastRefreshPlugin.js +11 -22
  14. package/dist/config/forkTSCheckerPlugin.js +11 -22
  15. package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
  16. package/dist/config/ignorePlugin.js +10 -21
  17. package/dist/config/javaScriptRules.js +151 -162
  18. package/dist/config/manifestPlugin.js +10 -18
  19. package/dist/config/miniCSSExtractPlugin.js +12 -23
  20. package/dist/config/nodePolyfill.js +14 -21
  21. package/dist/config/nodePrefixPlugin.js +8 -19
  22. package/dist/config/progressPlugin.js +7 -18
  23. package/dist/config/purgecssWebpackPlugin.js +15 -26
  24. package/dist/config/speedMeasureWebpackPlugin.js +12 -23
  25. package/dist/config/svgRules.js +43 -47
  26. package/dist/dev.js +101 -112
  27. package/dist/loader/svgr.js +4 -13
  28. package/dist/loader/swc.js +9 -14
  29. package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
  30. package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
  31. package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
  32. package/dist/schema.js +18 -6
  33. package/dist/server/server.d.ts +1 -1
  34. package/dist/server/server.js +161 -170
  35. package/dist/server/ws.d.ts +1 -1
  36. package/dist/types.d.ts +2 -6
  37. package/package.json +9 -11
  38. package/dist/server/https.d.ts +0 -4
  39. package/dist/server/https.js +0 -74
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  const core_1 = require("@swc/core");
15
4
  const types_1 = require("../types");
@@ -54,11 +43,17 @@ function swcLoader(contents) {
54
43
  // 启用异步模式
55
44
  const callback = this.async();
56
45
  const loaderOpts = this.getOptions();
57
- const { sync = false, parseMap = false } = loaderOpts, otherOpts = __rest(loaderOpts, ["sync", "parseMap"]);
46
+ const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
58
47
  const filename = this.resourcePath;
59
- const swcOpts = Object.assign(Object.assign(Object.assign({}, getBaseOpts({
48
+ const swcOpts = {
49
+ ...getBaseOpts({
50
+ filename,
51
+ }),
60
52
  filename,
61
- })), { filename, sourceMaps: this.sourceMap, sourceFileName: filename }), otherOpts);
53
+ sourceMaps: this.sourceMap,
54
+ sourceFileName: filename,
55
+ ...otherOpts,
56
+ };
62
57
  try {
63
58
  if (sync) {
64
59
  const output = (0, core_1.transformSync)(contents, swcOpts);
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
13
4
  const webpack_sources_1 = require("@umijs/bundler-webpack/compiled/webpack-sources");
@@ -30,34 +21,32 @@ class ESBuildCSSMinifyPlugin {
30
21
  name: PLUGIN_NAME,
31
22
  stage: 400,
32
23
  additionalAssets: true,
33
- }, () => __awaiter(this, void 0, void 0, function* () {
34
- yield this.transformAssets(compilation);
35
- }));
24
+ }, async () => {
25
+ await this.transformAssets(compilation);
26
+ });
36
27
  });
37
28
  }
38
- transformAssets(compilation) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const { options: { devtool }, } = compilation.compiler;
41
- const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
42
- const assets = compilation.getAssets().filter((asset) => {
43
- return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
44
- });
45
- yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
46
- const { source, map } = asset.source.sourceAndMap();
47
- const sourceAsString = source.toString();
48
- const result = yield (0, esbuild_1.transform)(sourceAsString, {
49
- loader: 'css',
50
- sourcemap,
51
- sourcefile: asset.name,
52
- minify: true,
53
- });
54
- compilation.updateAsset(asset.name,
55
- // @ts-ignore
56
- sourcemap
57
- ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
58
- : new webpack_sources_1.RawSource(result.code), Object.assign(Object.assign({}, asset.info), { minimized: true }));
59
- })));
29
+ async transformAssets(compilation) {
30
+ const { options: { devtool }, } = compilation.compiler;
31
+ const sourcemap = this.options.sourcemap === undefined ? !!devtool : this.options.sourcemap;
32
+ const assets = compilation.getAssets().filter((asset) => {
33
+ return !asset.info.minimized && RE_CSS_FILE.test(asset.name);
60
34
  });
35
+ await Promise.all(assets.map(async (asset) => {
36
+ const { source, map } = asset.source.sourceAndMap();
37
+ const sourceAsString = source.toString();
38
+ const result = await (0, esbuild_1.transform)(sourceAsString, {
39
+ loader: 'css',
40
+ sourcemap,
41
+ sourcefile: asset.name,
42
+ minify: true,
43
+ });
44
+ compilation.updateAsset(asset.name,
45
+ // @ts-ignore
46
+ sourcemap
47
+ ? new webpack_sources_1.SourceMapSource(result.code, asset.name, result.map, sourceAsString, map, true)
48
+ : new webpack_sources_1.RawSource(result.code), { ...asset.info, minimized: true });
49
+ }));
61
50
  }
62
51
  }
63
52
  exports.default = ESBuildCSSMinifyPlugin;
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ParcelCSSMinifyPlugin = void 0;
13
4
  const utils_1 = require("@umijs/utils");
@@ -35,7 +26,7 @@ class ParcelCSSMinifyPlugin {
35
26
  // @ts-ignore
36
27
  stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,
37
28
  additionalAssets: true,
38
- }, () => __awaiter(this, void 0, void 0, function* () { return yield this.transformAssets(compilation); }));
29
+ }, async () => await this.transformAssets(compilation));
39
30
  compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (statsPrinter) => {
40
31
  statsPrinter.hooks.print
41
32
  .for('asset.info.minimized')
@@ -47,29 +38,36 @@ class ParcelCSSMinifyPlugin {
47
38
  });
48
39
  });
49
40
  }
50
- transformAssets(compilation) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const { options: { devtool }, } = compilation.compiler;
53
- const sourcemap = this.options.sourceMap === undefined
54
- ? (devtool && devtool.includes('source-map'))
55
- : this.options.sourceMap;
56
- const assets = compilation.getAssets().filter((asset) => {
57
- return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
58
- });
59
- yield Promise.all(assets.map((asset) => __awaiter(this, void 0, void 0, function* () {
60
- const { source, map } = asset.source.sourceAndMap();
61
- const sourceAsString = source.toString();
62
- const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
63
- const { transform } = (0, utils_1.importLazy)('@parcel/css');
64
- const result = yield transform(Object.assign({ filename: asset.name, code, minify: true, sourceMap: sourcemap }, this.options));
65
- const codeString = result.code.toString();
66
- compilation.updateAsset(asset.name,
67
- // @ts-ignore
68
- sourcemap
69
- ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
70
- : new webpack_sources_1.RawSource(codeString), Object.assign(Object.assign({}, asset.info), { minimized: true }));
71
- })));
41
+ async transformAssets(compilation) {
42
+ const { options: { devtool }, } = compilation.compiler;
43
+ const sourcemap = this.options.sourceMap === undefined
44
+ ? (devtool && devtool.includes('source-map'))
45
+ : this.options.sourceMap;
46
+ const assets = compilation.getAssets().filter((asset) => {
47
+ return !asset.info.minimized && CSS_FILE_REG.test(asset.name);
72
48
  });
49
+ await Promise.all(assets.map(async (asset) => {
50
+ const { source, map } = asset.source.sourceAndMap();
51
+ const sourceAsString = source.toString();
52
+ const code = typeof source === 'string' ? buffer_1.Buffer.from(source) : source;
53
+ const { transform } = (0, utils_1.importLazy)('@parcel/css');
54
+ const result = await transform({
55
+ filename: asset.name,
56
+ code,
57
+ minify: true,
58
+ sourceMap: sourcemap,
59
+ ...this.options,
60
+ });
61
+ const codeString = result.code.toString();
62
+ compilation.updateAsset(asset.name,
63
+ // @ts-ignore
64
+ sourcemap
65
+ ? new webpack_sources_1.SourceMapSource(codeString, asset.name, JSON.parse(result.map.toString()), sourceAsString, map, true)
66
+ : new webpack_sources_1.RawSource(codeString), {
67
+ ...asset.info,
68
+ minimized: true,
69
+ });
70
+ }));
73
71
  }
74
72
  }
75
73
  exports.ParcelCSSMinifyPlugin = ParcelCSSMinifyPlugin;
@@ -11,7 +11,7 @@ class RuntimePublicPathPlugin {
11
11
  // https://github.com/webpack/webpack/blob/master/lib/runtime/PublicPathRuntimeModule.js
12
12
  if (module.constructor.name === 'PublicPathRuntimeModule') {
13
13
  // @ts-ignore
14
- module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath;`;
14
+ module._cachedGeneratedCode = `__webpack_require__.p = (globalThis || window).publicPath || '/';`;
15
15
  }
16
16
  });
17
17
  });
package/dist/schema.js CHANGED
@@ -4,18 +4,30 @@ exports.getSchemas = void 0;
4
4
  const types_1 = require("./types");
5
5
  const options = [
6
6
  'cheap-source-map',
7
- 'cheap-eval-source-map',
8
- 'cheap-hidden-source-map',
9
- 'cheap-inline-source-map',
10
7
  'cheap-module-source-map',
11
- 'cheap-module-eval-source-map',
12
- 'cheap-module-hidden-source-map',
13
- 'cheap-module-inline-source-map',
14
8
  'eval',
15
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',
16
15
  'source-map',
17
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',
18
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',
19
31
  ];
20
32
  const DEVTOOL_REGEX = new RegExp('^' + // start of string
21
33
  '(#@|@|#)?' + // maybe one of the pragmas
@@ -13,5 +13,5 @@ interface IOpts {
13
13
  onDevCompileDone?: Function;
14
14
  onProgress?: Function;
15
15
  }
16
- export declare function createServer(opts: IOpts): Promise<import("https").Server | http.Server | null>;
16
+ export declare function createServer(opts: IOpts): Promise<http.Server | import("https").Server | null>;
17
17
  export {};
@@ -1,18 +1,10 @@
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.createServer = void 0;
7
+ const bundler_utils_1 = require("@umijs/bundler-utils");
16
8
  const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
17
9
  const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
18
10
  const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
@@ -21,182 +13,181 @@ const fs_1 = require("fs");
21
13
  const http_1 = __importDefault(require("http"));
22
14
  const path_1 = require("path");
23
15
  const constants_1 = require("../constants");
24
- const https_1 = require("./https");
25
16
  const ws_1 = require("./ws");
26
- function createServer(opts) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const { webpackConfig, userConfig } = opts;
29
- const { proxy } = userConfig;
30
- const app = (0, express_1.default)();
31
- // cros
32
- app.use((_req, res, next) => {
33
- res.header('Access-Control-Allow-Origin', '*');
34
- res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
35
- res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
17
+ async function createServer(opts) {
18
+ const { webpackConfig, userConfig } = opts;
19
+ const { proxy } = userConfig;
20
+ const app = (0, express_1.default)();
21
+ // cros
22
+ app.use((_req, res, next) => {
23
+ res.header('Access-Control-Allow-Origin', '*');
24
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
25
+ res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
26
+ next();
27
+ });
28
+ // compression
29
+ app.use(require('@umijs/bundler-webpack/compiled/compression')());
30
+ // TODO: headers
31
+ // before middlewares
32
+ (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
33
+ // TODO: add to before middleware
34
+ app.use((req, res, next) => {
35
+ if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
36
+ res.setHeader('Content-Type', 'application/javascript');
37
+ (0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
38
+ }
39
+ else {
36
40
  next();
41
+ }
42
+ });
43
+ // webpack dev middleware
44
+ const configs = Array.isArray(webpackConfig)
45
+ ? webpackConfig
46
+ : [webpackConfig];
47
+ const progresses = [];
48
+ if (opts.onProgress) {
49
+ configs.forEach((config) => {
50
+ const progress = {
51
+ percent: 0,
52
+ status: 'waiting',
53
+ };
54
+ progresses.push(progress);
55
+ config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
56
+ progress.percent = percent;
57
+ progress.status = msg;
58
+ opts.onProgress({ progresses });
59
+ }));
37
60
  });
38
- // compression
39
- app.use(require('@umijs/bundler-webpack/compiled/compression')());
40
- // TODO: headers
41
- // before middlewares
42
- (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
43
- // TODO: add to before middleware
44
- app.use((req, res, next) => {
45
- if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
46
- res.setHeader('Content-Type', 'application/javascript');
47
- (0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
48
- }
49
- else {
50
- next();
51
- }
61
+ }
62
+ const compiler = (0, webpack_1.default)(configs);
63
+ const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
64
+ const compilerMiddleware = webpackDevMiddleware(compiler, {
65
+ publicPath: userConfig.publicPath || '/',
66
+ writeToDisk: userConfig.writeToDisk,
67
+ stats: 'none',
68
+ // watchOptions: { ignored }
69
+ });
70
+ app.use(compilerMiddleware);
71
+ // hmr hooks
72
+ let stats;
73
+ let isFirstCompile = true;
74
+ compiler.compilers.forEach(addHooks);
75
+ function addHooks(compiler) {
76
+ compiler.hooks.invalid.tap('server', () => {
77
+ sendMessage(constants_1.MESSAGE_TYPE.invalid);
52
78
  });
53
- // webpack dev middleware
54
- const configs = Array.isArray(webpackConfig)
55
- ? webpackConfig
56
- : [webpackConfig];
57
- const progresses = [];
58
- if (opts.onProgress) {
59
- configs.forEach((config) => {
60
- const progress = {
61
- percent: 0,
62
- status: 'waiting',
63
- };
64
- progresses.push(progress);
65
- config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
66
- progress.percent = percent;
67
- progress.status = msg;
68
- opts.onProgress({ progresses });
69
- }));
79
+ compiler.hooks.done.tap('server', (_stats) => {
80
+ var _a;
81
+ stats = _stats;
82
+ sendStats(getStats(stats));
83
+ (_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
84
+ stats,
85
+ isFirstCompile,
86
+ time: stats.endTime - stats.startTime,
70
87
  });
71
- }
72
- const compiler = (0, webpack_1.default)(configs);
73
- const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
74
- const compilerMiddleware = webpackDevMiddleware(compiler, {
75
- publicPath: userConfig.publicPath || '/',
76
- writeToDisk: userConfig.writeToDisk,
77
- stats: 'none',
78
- // watchOptions: { ignored }
88
+ isFirstCompile = false;
79
89
  });
80
- app.use(compilerMiddleware);
81
- // hmr hooks
82
- let stats;
83
- let isFirstCompile = true;
84
- compiler.compilers.forEach(addHooks);
85
- function addHooks(compiler) {
86
- compiler.hooks.invalid.tap('server', () => {
87
- sendMessage(constants_1.MESSAGE_TYPE.invalid);
88
- });
89
- compiler.hooks.done.tap('server', (_stats) => {
90
- var _a;
91
- stats = _stats;
92
- sendStats(getStats(stats));
93
- (_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
94
- stats,
95
- isFirstCompile,
96
- time: stats.endTime - stats.startTime,
97
- });
98
- isFirstCompile = false;
99
- });
90
+ }
91
+ function sendStats(stats, force, sender) {
92
+ const shouldEmit = !force &&
93
+ stats &&
94
+ (!stats.errors || stats.errors.length === 0) &&
95
+ (!stats.warnings || stats.warnings.length === 0) &&
96
+ stats.assets &&
97
+ stats.assets.every((asset) => !asset.emitted);
98
+ if (shouldEmit) {
99
+ sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
100
+ return;
100
101
  }
101
- function sendStats(stats, force, sender) {
102
- const shouldEmit = !force &&
103
- stats &&
104
- (!stats.errors || stats.errors.length === 0) &&
105
- (!stats.warnings || stats.warnings.length === 0) &&
106
- stats.assets &&
107
- stats.assets.every((asset) => !asset.emitted);
108
- if (shouldEmit) {
109
- sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
110
- return;
111
- }
112
- sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
113
- if ((stats.errors && stats.errors.length > 0) ||
114
- (stats.warnings && stats.warnings.length > 0)) {
115
- if (stats.warnings && stats.warnings.length > 0) {
116
- sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
117
- }
118
- if (stats.errors && stats.errors.length > 0) {
119
- sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
120
- }
102
+ sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
103
+ if ((stats.errors && stats.errors.length > 0) ||
104
+ (stats.warnings && stats.warnings.length > 0)) {
105
+ if (stats.warnings && stats.warnings.length > 0) {
106
+ sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
121
107
  }
122
- else {
123
- sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
108
+ if (stats.errors && stats.errors.length > 0) {
109
+ sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
124
110
  }
125
111
  }
126
- function getStats(stats) {
127
- return stats.toJson({
128
- all: false,
129
- hash: true,
130
- assets: true,
131
- warnings: true,
132
- errors: true,
133
- errorDetails: false,
134
- });
135
- }
136
- function sendMessage(type, data, sender) {
137
- (sender || ws).send(JSON.stringify({ type, data }));
112
+ else {
113
+ sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
138
114
  }
139
- // mock
140
- // proxy
141
- if (proxy) {
142
- Object.keys(proxy).forEach((key) => {
143
- const proxyConfig = proxy[key];
144
- const target = proxyConfig.target;
145
- if (target) {
146
- app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, Object.assign(Object.assign({}, proxy[key]), {
147
- // Add x-real-url in response header
148
- onProxyRes(proxyRes, req) {
149
- var _a;
150
- proxyRes.headers['x-real-url'] =
151
- ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
152
- } })));
153
- }
154
- });
155
- }
156
- // after middlewares
157
- (opts.afterMiddlewares || []).forEach((m) => {
158
- // TODO: FIXME
159
- app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
115
+ }
116
+ function getStats(stats) {
117
+ return stats.toJson({
118
+ all: false,
119
+ hash: true,
120
+ assets: true,
121
+ warnings: true,
122
+ errors: true,
123
+ errorDetails: false,
160
124
  });
161
- // history fallback
162
- app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
163
- index: '/',
164
- }));
165
- // hmr reconnect ping
166
- app.use('/__umi_ping', (_, res) => {
167
- res.end('pong');
168
- });
169
- // index.html
170
- // TODO: remove me
171
- app.get('/', (_req, res, next) => {
172
- res.set('Content-Type', 'text/html');
173
- const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
174
- if ((0, fs_1.existsSync)(htmlPath)) {
175
- (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
176
- }
177
- else {
178
- next();
125
+ }
126
+ function sendMessage(type, data, sender) {
127
+ (sender || ws).send(JSON.stringify({ type, data }));
128
+ }
129
+ // mock
130
+ // proxy
131
+ if (proxy) {
132
+ Object.keys(proxy).forEach((key) => {
133
+ const proxyConfig = proxy[key];
134
+ const target = proxyConfig.target;
135
+ if (target) {
136
+ app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
137
+ ...proxy[key],
138
+ // Add x-real-url in response header
139
+ onProxyRes(proxyRes, req) {
140
+ var _a;
141
+ proxyRes.headers['x-real-url'] =
142
+ ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
143
+ },
144
+ }));
179
145
  }
180
146
  });
181
- const server = userConfig.https
182
- ? yield (0, https_1.createHttpsServer)(app, userConfig.https)
183
- : http_1.default.createServer(app);
184
- if (!server) {
185
- return null;
147
+ }
148
+ // after middlewares
149
+ (opts.afterMiddlewares || []).forEach((m) => {
150
+ // TODO: FIXME
151
+ app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
152
+ });
153
+ // history fallback
154
+ app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
155
+ index: '/',
156
+ }));
157
+ // hmr reconnect ping
158
+ app.use('/__umi_ping', (_, res) => {
159
+ res.end('pong');
160
+ });
161
+ // index.html
162
+ // TODO: remove me
163
+ app.get('/', (_req, res, next) => {
164
+ res.set('Content-Type', 'text/html');
165
+ const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
166
+ if ((0, fs_1.existsSync)(htmlPath)) {
167
+ (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
186
168
  }
187
- const ws = (0, ws_1.createWebSocketServer)(server);
188
- ws.wss.on('connection', (socket) => {
189
- if (stats) {
190
- sendStats(getStats(stats), false, socket);
191
- }
192
- });
193
- const protocol = userConfig.https ? 'https:' : 'http:';
194
- const port = opts.port || 8000;
195
- server.listen(port, () => {
196
- const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
197
- utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
198
- });
199
- return server;
169
+ else {
170
+ next();
171
+ }
172
+ });
173
+ const server = userConfig.https
174
+ ? await (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
175
+ : http_1.default.createServer(app);
176
+ if (!server) {
177
+ return null;
178
+ }
179
+ const ws = (0, ws_1.createWebSocketServer)(server);
180
+ ws.wss.on('connection', (socket) => {
181
+ if (stats) {
182
+ sendStats(getStats(stats), false, socket);
183
+ }
184
+ });
185
+ const protocol = userConfig.https ? 'https:' : 'http:';
186
+ const port = opts.port || 8000;
187
+ server.listen(port, () => {
188
+ const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
189
+ utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
200
190
  });
191
+ return server;
201
192
  }
202
193
  exports.createServer = createServer;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
+ import type { SpdyServer as Server } from '@umijs/bundler-utils';
2
3
  import { Server as HttpServer } from 'http';
3
4
  import { Http2Server } from 'http2';
4
5
  import { Server as HttpsServer } from 'https';
5
- import { Server } from 'spdy';
6
6
  import WebSocket from '../../compiled/ws';
7
7
  export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
8
8
  send(message: string): void;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Config as SwcConfig } from '@swc/core';
2
+ import type { HttpsServerOptions } from '@umijs/bundler-utils';
2
3
  import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
3
4
  import { Configuration } from '../compiled/webpack';
4
5
  import Config from '../compiled/webpack-5-chain';
@@ -41,11 +42,6 @@ export interface DeadCodeParams {
41
42
  detectUnusedExport?: boolean;
42
43
  context?: string;
43
44
  }
44
- export interface HttpsParams {
45
- key?: string;
46
- cert?: string;
47
- hosts?: string[];
48
- }
49
45
  export interface IConfig {
50
46
  alias?: Record<string, string>;
51
47
  autoCSSModules?: boolean;
@@ -68,7 +64,7 @@ export interface IConfig {
68
64
  depTranspiler?: Transpiler;
69
65
  devtool?: Config.DevTool;
70
66
  deadCode?: DeadCodeParams;
71
- https?: HttpsParams;
67
+ https?: HttpsServerOptions;
72
68
  externals?: WebpackConfig['externals'];
73
69
  esm?: {
74
70
  [key: string]: any;