@umijs/bundler-webpack 4.0.0-rc.14 → 4.0.0-rc.15
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.
- package/dist/build.js +48 -59
- package/dist/cli.js +6 -15
- package/dist/client/client.js +34 -47
- package/dist/config/_sampleFeature.js +6 -17
- package/dist/config/assetRules.js +44 -55
- package/dist/config/bundleAnalyzerPlugin.js +12 -23
- package/dist/config/compressPlugin.js +68 -76
- package/dist/config/config.js +177 -185
- package/dist/config/copyPlugin.js +29 -40
- package/dist/config/cssRules.js +93 -83
- package/dist/config/definePlugin.js +11 -19
- package/dist/config/detectDeadCodePlugin.js +16 -21
- package/dist/config/fastRefreshPlugin.js +11 -22
- package/dist/config/forkTSCheckerPlugin.js +11 -22
- package/dist/config/harmonyLinkingErrorPlugin.js +3 -14
- package/dist/config/ignorePlugin.js +10 -21
- package/dist/config/javaScriptRules.js +151 -162
- package/dist/config/manifestPlugin.js +10 -18
- package/dist/config/miniCSSExtractPlugin.js +12 -23
- package/dist/config/nodePolyfill.js +14 -21
- package/dist/config/nodePrefixPlugin.js +8 -19
- package/dist/config/progressPlugin.js +7 -18
- package/dist/config/purgecssWebpackPlugin.js +15 -26
- package/dist/config/speedMeasureWebpackPlugin.js +12 -23
- package/dist/config/svgRules.js +43 -47
- package/dist/dev.js +101 -112
- package/dist/loader/svgr.js +4 -13
- package/dist/loader/swc.js +9 -14
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +23 -34
- package/dist/plugins/ParcelCSSMinifyPlugin.js +30 -32
- package/dist/server/server.d.ts +1 -1
- package/dist/server/server.js +161 -170
- package/dist/server/ws.d.ts +1 -1
- package/dist/types.d.ts +2 -6
- package/package.json +6 -8
- package/dist/server/https.d.ts +0 -4
- package/dist/server/https.js +0 -74
package/dist/loader/swc.js
CHANGED
|
@@ -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
|
|
46
|
+
const { sync = false, parseMap = false, ...otherOpts } = loaderOpts;
|
|
58
47
|
const filename = this.resourcePath;
|
|
59
|
-
const swcOpts =
|
|
48
|
+
const swcOpts = {
|
|
49
|
+
...getBaseOpts({
|
|
50
|
+
filename,
|
|
51
|
+
}),
|
|
60
52
|
filename,
|
|
61
|
-
|
|
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
|
-
}, () =>
|
|
34
|
-
|
|
35
|
-
})
|
|
24
|
+
}, async () => {
|
|
25
|
+
await this.transformAssets(compilation);
|
|
26
|
+
});
|
|
36
27
|
});
|
|
37
28
|
}
|
|
38
|
-
transformAssets(compilation) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
}, () =>
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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;
|
package/dist/server/server.d.ts
CHANGED
|
@@ -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 |
|
|
16
|
+
export declare function createServer(opts: IOpts): Promise<http.Server | import("https").Server | null>;
|
|
17
17
|
export {};
|
package/dist/server/server.js
CHANGED
|
@@ -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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
(
|
|
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
|
-
|
|
123
|
-
sendMessage(constants_1.MESSAGE_TYPE.
|
|
108
|
+
if (stats.errors && stats.errors.length > 0) {
|
|
109
|
+
sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
|
|
124
110
|
}
|
|
125
111
|
}
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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;
|
package/dist/server/ws.d.ts
CHANGED
|
@@ -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?:
|
|
67
|
+
https?: HttpsServerOptions;
|
|
72
68
|
externals?: WebpackConfig['externals'];
|
|
73
69
|
esm?: {
|
|
74
70
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/bundler-webpack",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.15",
|
|
4
4
|
"description": "@umijs/bundler-webpack",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -35,22 +35,20 @@
|
|
|
35
35
|
"@svgr/plugin-jsx": "^6.2.1",
|
|
36
36
|
"@svgr/plugin-svgo": "^6.2.0",
|
|
37
37
|
"@types/hapi__joi": "17.1.8",
|
|
38
|
-
"@umijs/babel-preset-umi": "4.0.0-rc.
|
|
39
|
-
"@umijs/bundler-utils": "4.0.0-rc.
|
|
40
|
-
"@umijs/mfsu": "4.0.0-rc.
|
|
41
|
-
"@umijs/utils": "4.0.0-rc.
|
|
38
|
+
"@umijs/babel-preset-umi": "4.0.0-rc.15",
|
|
39
|
+
"@umijs/bundler-utils": "4.0.0-rc.15",
|
|
40
|
+
"@umijs/mfsu": "4.0.0-rc.15",
|
|
41
|
+
"@umijs/utils": "4.0.0-rc.15",
|
|
42
42
|
"css-loader": "6.7.1",
|
|
43
43
|
"es5-imcompatible-versions": "^0.1.73",
|
|
44
44
|
"jest-worker": "27.5.1",
|
|
45
45
|
"node-libs-browser": "2.2.1",
|
|
46
46
|
"postcss": "^8.4.12",
|
|
47
47
|
"postcss-preset-env": "7.4.3",
|
|
48
|
-
"react-error-overlay": "6.0.9"
|
|
49
|
-
"spdy": "^4.0.2"
|
|
48
|
+
"react-error-overlay": "6.0.9"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
51
|
"@swc/core": "1.2.165",
|
|
53
|
-
"@types/spdy": "^3.4.5",
|
|
54
52
|
"@types/webpack-sources": "3.2.0",
|
|
55
53
|
"@types/ws": "8.5.3",
|
|
56
54
|
"autoprefixer": "10.4.4",
|
package/dist/server/https.d.ts
DELETED