@umijs/bundler-webpack 4.0.0-rc.1 → 4.0.0-rc.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.
- package/client/client/client.js +49 -35
- package/client/constants.js +3 -0
- package/compiled/autoprefixer/browserslist/index.d.ts +6 -0
- package/compiled/autoprefixer/index.js +3 -3
- package/compiled/autoprefixer/postcss/lib/at-rule.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/comment.d.ts +1 -1
- package/compiled/autoprefixer/postcss/lib/declaration.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/node.d.ts +2 -2
- package/compiled/autoprefixer/postcss/lib/rule.d.ts +1 -1
- package/compiled/autoprefixer/source-map-js/source-map.d.ts +99 -82
- package/compiled/babel-loader/index.js +2 -2
- package/compiled/copy-webpack-plugin/939.index.js +1171 -0
- package/compiled/copy-webpack-plugin/index.js +16 -10
- package/compiled/copy-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/index.js +8 -2
- package/compiled/css-minimizer-webpack-plugin/minify.js +25 -11
- package/compiled/css-minimizer-webpack-plugin/package.json +1 -1
- package/compiled/css-minimizer-webpack-plugin/utils.js +225 -28
- package/compiled/cssnano/index.js +12 -11
- package/compiled/cssnano/package.json +1 -1
- package/compiled/express.d.ts +2 -0
- package/compiled/fork-ts-checker-webpack-plugin/index.js +14 -15
- package/compiled/http-proxy-middleware/dist/types.d.ts +5 -5
- package/compiled/http-proxy-middleware/http-proxy/index.d.ts +1 -1
- package/compiled/http-proxy-middleware/index.js +10 -10
- package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +60 -8
- package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +13 -1
- package/compiled/mini-css-extract-plugin/index.js +4523 -4036
- package/compiled/mini-css-extract-plugin/loader.js +179 -54
- package/compiled/mini-css-extract-plugin/package.json +1 -1
- package/compiled/mini-css-extract-plugin/utils.js +79 -23
- package/compiled/sass-loader/index.js +1 -1
- package/compiled/terser/index.js +1 -1
- package/compiled/terser-webpack-plugin/index.js +296 -297
- package/compiled/terser-webpack-plugin/minify.js +4 -2
- package/compiled/terser-webpack-plugin/package.json +1 -1
- package/compiled/terser-webpack-plugin/types/index.d.ts +180 -146
- package/compiled/terser-webpack-plugin/types/minify.d.ts +17 -0
- package/compiled/terser-webpack-plugin/types/utils.d.ts +1 -3
- package/compiled/terser-webpack-plugin/utils.js +9 -12
- package/compiled/webpack/index.js +9855 -4185
- package/compiled/webpack-dev-middleware/index.js +7 -7
- package/compiled/webpack-dev-middleware/package.json +1 -1
- package/compiled/webpack-manifest-plugin/index.js +1 -1
- package/compiled/webpack-sources/index.js +1 -1
- package/compiled/ws/index.d.ts +1 -2
- package/compiled/ws/index.js +1 -1
- package/dist/build.d.ts +2 -1
- package/dist/build.js +1 -1
- package/dist/client/client.js +7 -2
- package/dist/config/compressPlugin.js +6 -0
- package/dist/config/config.js +4 -3
- package/dist/config/cssRules.js +1 -1
- package/dist/config/detectDeadCode.d.ts +12 -0
- package/dist/config/detectDeadCode.js +120 -0
- package/dist/config/detectDeadCodePlugin.d.ts +9 -0
- package/dist/config/detectDeadCodePlugin.js +75 -0
- package/dist/config/javaScriptRules.js +7 -12
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +13 -5
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -1
- package/dist/loader/swc.js +14 -18
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +1 -3
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
- package/dist/plugins/ProgressPlugin.js +2 -2
- package/dist/plugins/RuntimePublicPathPlugin.js +1 -1
- package/dist/requireHook.js +1 -1
- package/dist/schema.js +10 -6
- package/dist/server/server.d.ts +1 -2
- package/dist/server/server.js +27 -11
- package/dist/server/ws.d.ts +3 -2
- package/dist/swcPlugins/autoCSSModules.d.ts +7 -2
- package/dist/swcPlugins/autoCSSModules.js +14 -17
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +1 -1
- package/dist/swcPlugins/lockCoreJS.js +3 -2
- package/dist/types.d.ts +16 -12
- package/dist/types.js +1 -0
- package/dist/utils/depMatch.js +1 -1
- package/dist/utils/server.d.ts +5 -0
- package/dist/utils/server.js +93 -0
- package/package.json +38 -41
- package/compiled/css-loader/LICENSE +0 -20
- package/compiled/css-loader/api.js +0 -102
- package/compiled/css-loader/getUrl.js +0 -29
- package/compiled/css-loader/index.js +0 -2
- package/compiled/css-loader/noSourceMaps.js +0 -5
- package/compiled/css-loader/package.json +0 -1
- package/compiled/css-loader/sourceMaps.js +0 -22
- package/compiled/express/LICENSE +0 -24
- package/compiled/express/body-parser/index.d.ts +0 -104
- package/compiled/express/connect/index.d.ts +0 -93
- package/compiled/express/express-serve-static-core/index.d.ts +0 -1252
- package/compiled/express/index.d.ts +0 -133
- package/compiled/express/index.js +0 -338
- package/compiled/express/mime/index.d.ts +0 -35
- package/compiled/express/package.json +0 -1
- package/compiled/express/qs/index.d.ts +0 -62
- package/compiled/express/range-parser/index.d.ts +0 -35
- package/compiled/express/serve-static/index.d.ts +0 -108
- package/compiled/less/index.js +0 -31
- package/compiled/less/package.json +0 -1
- package/dist/esbuildHandler/autoCssModules.d.ts +0 -2
- package/dist/esbuildHandler/autoCssModules.js +0 -23
- package/dist/loader/esbuild.d.ts +0 -5
- package/dist/loader/esbuild.js +0 -53
package/dist/server/server.js
CHANGED
|
@@ -13,14 +13,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.createServer = void 0;
|
|
16
|
-
const express_1 = __importDefault(require("@umijs/bundler-
|
|
16
|
+
const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
|
|
17
17
|
const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
18
18
|
const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
|
|
19
19
|
const utils_1 = require("@umijs/utils");
|
|
20
20
|
const fs_1 = require("fs");
|
|
21
|
-
const http_1 = __importDefault(require("http"));
|
|
22
21
|
const path_1 = require("path");
|
|
23
22
|
const constants_1 = require("../constants");
|
|
23
|
+
const server_1 = require("../utils/server");
|
|
24
24
|
const ws_1 = require("./ws");
|
|
25
25
|
function createServer(opts) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -42,7 +42,7 @@ function createServer(opts) {
|
|
|
42
42
|
// cros
|
|
43
43
|
app.use((_req, res, next) => {
|
|
44
44
|
res.header('Access-Control-Allow-Origin', '*');
|
|
45
|
-
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With
|
|
45
|
+
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With');
|
|
46
46
|
res.header('Access-Control-Allow-Methods', 'GET, HEAD, PUT, POST, PATCH, DELETE, OPTIONS');
|
|
47
47
|
next();
|
|
48
48
|
});
|
|
@@ -55,7 +55,7 @@ function createServer(opts) {
|
|
|
55
55
|
app.use((req, res, next) => {
|
|
56
56
|
if (req.path === '/umi.js' && (0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'umi.js'))) {
|
|
57
57
|
res.setHeader('Content-Type', 'application/javascript');
|
|
58
|
-
|
|
58
|
+
(0, fs_1.createReadStream)((0, path_1.join)(opts.cwd, 'umi.js')).on('error', next).pipe(res);
|
|
59
59
|
}
|
|
60
60
|
else {
|
|
61
61
|
next();
|
|
@@ -65,7 +65,7 @@ function createServer(opts) {
|
|
|
65
65
|
const compiler = (0, webpack_1.default)(Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig]);
|
|
66
66
|
const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
|
|
67
67
|
const compilerMiddleware = webpackDevMiddleware(compiler, {
|
|
68
|
-
publicPath: '/',
|
|
68
|
+
publicPath: userConfig.publicPath || '/',
|
|
69
69
|
writeToDisk: userConfig.writeToDisk,
|
|
70
70
|
stats: 'none',
|
|
71
71
|
// watchOptions: { ignored }
|
|
@@ -133,11 +133,24 @@ function createServer(opts) {
|
|
|
133
133
|
// proxy
|
|
134
134
|
if (proxy) {
|
|
135
135
|
Object.keys(proxy).forEach((key) => {
|
|
136
|
-
|
|
136
|
+
const proxyConfig = proxy[key];
|
|
137
|
+
const target = proxyConfig.target;
|
|
138
|
+
if (target) {
|
|
139
|
+
app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, Object.assign(Object.assign({}, proxy[key]), {
|
|
140
|
+
// Add x-real-url in response header
|
|
141
|
+
onProxyRes(proxyRes, req) {
|
|
142
|
+
var _a;
|
|
143
|
+
proxyRes.headers['x-real-url'] =
|
|
144
|
+
((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
|
|
145
|
+
} })));
|
|
146
|
+
}
|
|
137
147
|
});
|
|
138
148
|
}
|
|
139
149
|
// after middlewares
|
|
140
|
-
(opts.afterMiddlewares || []).forEach((m) =>
|
|
150
|
+
(opts.afterMiddlewares || []).forEach((m) => {
|
|
151
|
+
// TODO: FIXME
|
|
152
|
+
app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
|
|
153
|
+
});
|
|
141
154
|
// history fallback
|
|
142
155
|
app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
|
|
143
156
|
index: '/',
|
|
@@ -152,24 +165,27 @@ function createServer(opts) {
|
|
|
152
165
|
res.set('Content-Type', 'text/html');
|
|
153
166
|
const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
|
|
154
167
|
if ((0, fs_1.existsSync)(htmlPath)) {
|
|
155
|
-
|
|
156
|
-
res.send(html);
|
|
168
|
+
(0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
|
|
157
169
|
}
|
|
158
170
|
else {
|
|
159
171
|
next();
|
|
160
172
|
}
|
|
161
173
|
});
|
|
162
|
-
const server =
|
|
174
|
+
const server = yield (0, server_1.getServer)(app, userConfig.https);
|
|
175
|
+
if (!server) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
163
178
|
const ws = (0, ws_1.createWebSocketServer)(server);
|
|
164
179
|
ws.wss.on('connection', (socket) => {
|
|
165
180
|
if (stats) {
|
|
166
181
|
sendStats(getStats(stats), false, socket);
|
|
167
182
|
}
|
|
168
183
|
});
|
|
184
|
+
const protocol = userConfig.https ? 'https:' : 'http:';
|
|
169
185
|
const port = opts.port || 8000;
|
|
170
186
|
server.listen(port, () => {
|
|
171
187
|
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
172
|
-
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(
|
|
188
|
+
utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
|
|
173
189
|
});
|
|
174
190
|
return server;
|
|
175
191
|
});
|
package/dist/server/ws.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Server } from 'http';
|
|
2
|
+
import { Server as HttpServer } from 'http';
|
|
3
|
+
import { Server as HttpsServer } from 'https';
|
|
3
4
|
import WebSocket from '../../compiled/ws';
|
|
4
|
-
export declare function createWebSocketServer(server:
|
|
5
|
+
export declare function createWebSocketServer(server: HttpServer | HttpsServer): {
|
|
5
6
|
send(message: string): void;
|
|
6
7
|
wss: WebSocket.Server;
|
|
7
8
|
close(): void;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { ImportDeclaration,
|
|
1
|
+
import type { ImportDeclaration, ModuleItem, TsType } from '@swc/core';
|
|
2
2
|
import Visitor from '@swc/core/Visitor';
|
|
3
3
|
declare class AutoCSSModule extends Visitor {
|
|
4
4
|
visitTsType(expression: TsType): TsType;
|
|
5
|
+
/**
|
|
6
|
+
* call path:
|
|
7
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
8
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
9
|
+
*/
|
|
10
|
+
visitModuleItem(n: ModuleItem): ImportDeclaration | import("@swc/core").ExportDeclaration | import("@swc/core").ExportNamedDeclaration | import("@swc/core").ExportDefaultDeclaration | import("@swc/core").ExportDefaultExpression | import("@swc/core").ExportAllDeclaration | import("@swc/core").TsImportEqualsDeclaration | import("@swc/core").TsExportAssignment | import("@swc/core").TsNamespaceExportDeclaration | import("@swc/core").ExpressionStatement | import("@swc/core").BlockStatement | import("@swc/core").EmptyStatement | import("@swc/core").DebuggerStatement | import("@swc/core").WithStatement | import("@swc/core").ReturnStatement | import("@swc/core").LabeledStatement | import("@swc/core").BreakStatement | import("@swc/core").ContinueStatement | import("@swc/core").IfStatement | import("@swc/core").SwitchStatement | import("@swc/core").ThrowStatement | import("@swc/core").TryStatement | import("@swc/core").WhileStatement | import("@swc/core").DoWhileStatement | import("@swc/core").ForStatement | import("@swc/core").ForInStatement | import("@swc/core").ForOfStatement | import("@swc/core").ClassDeclaration | import("@swc/core").FunctionDeclaration | import("@swc/core").VariableDeclaration | import("@swc/core").TsInterfaceDeclaration | import("@swc/core").TsTypeAliasDeclaration | import("@swc/core").TsEnumDeclaration | import("@swc/core").TsModuleDeclaration;
|
|
5
11
|
visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
|
|
6
|
-
visitVariableDeclaration(expression: VariableDeclaration): VariableDeclaration;
|
|
7
12
|
}
|
|
8
13
|
export default AutoCSSModule;
|
|
@@ -5,31 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
|
|
7
7
|
const utils_1 = require("@umijs/utils");
|
|
8
|
+
const changeImportFromString_1 = require("./changeImportFromString");
|
|
8
9
|
class AutoCSSModule extends Visitor_1.default {
|
|
9
10
|
visitTsType(expression) {
|
|
10
11
|
return expression;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* call path:
|
|
15
|
+
* visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
|
|
16
|
+
* @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
|
|
17
|
+
*/
|
|
18
|
+
visitModuleItem(n) {
|
|
19
|
+
if (n.type === 'ImportDeclaration') {
|
|
20
|
+
return this.visitImportDeclaration(n);
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
12
24
|
visitImportDeclaration(expression) {
|
|
13
25
|
const { specifiers, source } = expression;
|
|
14
26
|
const { value } = source;
|
|
15
27
|
if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return expression;
|
|
19
|
-
}
|
|
20
|
-
visitVariableDeclaration(expression) {
|
|
21
|
-
const { declarations } = expression;
|
|
22
|
-
if (declarations.length &&
|
|
23
|
-
declarations[0].init &&
|
|
24
|
-
declarations[0].init.type === 'AwaitExpression' &&
|
|
25
|
-
declarations[0].init.argument.type === 'CallExpression' &&
|
|
26
|
-
declarations[0].init.argument.arguments.length &&
|
|
27
|
-
declarations[0].init.argument.arguments[0].expression.type ===
|
|
28
|
-
'StringLiteral' &&
|
|
29
|
-
(0, utils_1.isStyleFile)({
|
|
30
|
-
filename: declarations[0].init.argument.arguments[0].expression.value,
|
|
31
|
-
})) {
|
|
32
|
-
declarations[0].init.argument.arguments[0].expression.value = `${declarations[0].init.argument.arguments[0].expression.value}?modules`;
|
|
28
|
+
const newImportFrom = `${value}?modules`;
|
|
29
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
|
|
33
30
|
}
|
|
34
31
|
return expression;
|
|
35
32
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.changeImportFromString = void 0;
|
|
4
|
+
const changeImportFromString = (e, v) => {
|
|
5
|
+
e.source.value = v;
|
|
6
|
+
// sync change to `raw`
|
|
7
|
+
// https://github.com/swc-project/swc/issues/4128
|
|
8
|
+
e.source.raw = `'${v}'`;
|
|
9
|
+
};
|
|
10
|
+
exports.changeImportFromString = changeImportFromString;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
|
|
7
7
|
const utils_1 = require("@umijs/utils");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
+
const changeImportFromString_1 = require("./changeImportFromString");
|
|
9
10
|
function addLastSlash(path) {
|
|
10
11
|
return path.endsWith('/') ? path : `${path}/`;
|
|
11
12
|
}
|
|
@@ -14,8 +15,8 @@ class LockCoreJS extends Visitor_1.default {
|
|
|
14
15
|
const { source } = expression;
|
|
15
16
|
let { value, type } = source;
|
|
16
17
|
if (type === 'StringLiteral' && value.startsWith('core-js/')) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const newValue = value.replace(/^core-js\//, addLastSlash((0, utils_1.winPath)((0, path_1.dirname)(require.resolve('core-js/package.json')))));
|
|
19
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newValue);
|
|
19
20
|
}
|
|
20
21
|
return expression;
|
|
21
22
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { Config as SwcConfig } from '@swc/core';
|
|
2
|
-
import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
|
|
3
|
-
import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
|
|
4
2
|
import type { Options as ProxyOptions } from '../compiled/http-proxy-middleware';
|
|
5
3
|
import { Configuration } from '../compiled/webpack';
|
|
6
4
|
import Config from '../compiled/webpack-5-chain';
|
|
@@ -24,6 +22,7 @@ export declare enum JSMinifier {
|
|
|
24
22
|
export declare enum CSSMinifier {
|
|
25
23
|
esbuild = "esbuild",
|
|
26
24
|
cssnano = "cssnano",
|
|
25
|
+
parcelCSS = "parcelCSS",
|
|
27
26
|
none = "none"
|
|
28
27
|
}
|
|
29
28
|
export interface ICopy {
|
|
@@ -34,6 +33,19 @@ declare type WebpackConfig = Required<Configuration>;
|
|
|
34
33
|
declare type IBabelPlugin = Function | string | [string, {
|
|
35
34
|
[key: string]: any;
|
|
36
35
|
}];
|
|
36
|
+
export interface DeadCodeParams {
|
|
37
|
+
patterns?: string[];
|
|
38
|
+
exclude?: string[];
|
|
39
|
+
failOnHint?: boolean;
|
|
40
|
+
detectUnusedFiles?: boolean;
|
|
41
|
+
detectUnusedExport?: boolean;
|
|
42
|
+
context?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface HttpsParams {
|
|
45
|
+
key?: string;
|
|
46
|
+
cert?: string;
|
|
47
|
+
hosts?: string[];
|
|
48
|
+
}
|
|
37
49
|
export interface IConfig {
|
|
38
50
|
alias?: Record<string, string>;
|
|
39
51
|
autoCSSModules?: boolean;
|
|
@@ -55,6 +67,8 @@ export interface IConfig {
|
|
|
55
67
|
};
|
|
56
68
|
depTranspiler?: Transpiler;
|
|
57
69
|
devtool?: Config.DevTool;
|
|
70
|
+
deadCode?: DeadCodeParams;
|
|
71
|
+
https?: HttpsParams;
|
|
58
72
|
externals?: WebpackConfig['externals'];
|
|
59
73
|
esm?: {
|
|
60
74
|
[key: string]: any;
|
|
@@ -104,15 +118,5 @@ export interface IConfig {
|
|
|
104
118
|
export interface SwcOptions extends SwcConfig {
|
|
105
119
|
sync?: boolean;
|
|
106
120
|
parseMap?: boolean;
|
|
107
|
-
targets?: Record<string, any>;
|
|
108
|
-
}
|
|
109
|
-
export interface IEsbuildLoaderHandlerParams {
|
|
110
|
-
code: string;
|
|
111
|
-
filePath: string;
|
|
112
|
-
imports: readonly ImportSpecifier[];
|
|
113
|
-
exports: readonly string[];
|
|
114
|
-
}
|
|
115
|
-
export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
|
|
116
|
-
handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
|
|
117
121
|
}
|
|
118
122
|
export {};
|
package/dist/types.js
CHANGED
|
@@ -25,5 +25,6 @@ var CSSMinifier;
|
|
|
25
25
|
(function (CSSMinifier) {
|
|
26
26
|
CSSMinifier["esbuild"] = "esbuild";
|
|
27
27
|
CSSMinifier["cssnano"] = "cssnano";
|
|
28
|
+
CSSMinifier["parcelCSS"] = "parcelCSS";
|
|
28
29
|
CSSMinifier["none"] = "none";
|
|
29
30
|
})(CSSMinifier = exports.CSSMinifier || (exports.CSSMinifier = {}));
|
package/dist/utils/depMatch.js
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http, { RequestListener } from 'http';
|
|
3
|
+
import https from 'https';
|
|
4
|
+
import { HttpsParams } from '../types';
|
|
5
|
+
export declare const getServer: (app: RequestListener, httpsConfig?: HttpsParams | undefined) => Promise<http.Server | https.Server | undefined>;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getServer = void 0;
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const http_1 = __importDefault(require("http"));
|
|
20
|
+
const https_1 = __importDefault(require("https"));
|
|
21
|
+
const path_1 = require("path");
|
|
22
|
+
const defaultHttpsHosts = ['localhost', '127.0.0.1'];
|
|
23
|
+
/**
|
|
24
|
+
* Check if mkcert is installed
|
|
25
|
+
*/
|
|
26
|
+
const mkcertCmdChecker = () => {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
(0, child_process_1.exec)('mkcert -help', (error, stdout) => {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!error && ((_a = stdout === null || stdout === void 0 ? void 0 : stdout.includes) === null || _a === void 0 ? void 0 : _a.call(stdout, 'mkcert'))) {
|
|
31
|
+
resolve(true);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
reject(false);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Generate key and certificate files in https mode.
|
|
41
|
+
*/
|
|
42
|
+
const generateCertFiles = (hosts = defaultHttpsHosts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
utils_1.logger.warn('[https] No key or cert has been passed in.');
|
|
45
|
+
mkcertCmdChecker()
|
|
46
|
+
.then(() => {
|
|
47
|
+
utils_1.logger.wait('[https] Generating cert and key files...');
|
|
48
|
+
const certFilePath = (0, path_1.join)(__dirname, 'umi.pem');
|
|
49
|
+
const keyFilePath = (0, path_1.join)(__dirname, 'umi.key.pem');
|
|
50
|
+
(0, child_process_1.exec)(`mkcert -cert-file ${certFilePath} -key-file ${keyFilePath} ${hosts.join(' ')}`, (error) => {
|
|
51
|
+
if (error) {
|
|
52
|
+
reject({});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
resolve({
|
|
56
|
+
key: keyFilePath,
|
|
57
|
+
cert: certFilePath,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
})
|
|
62
|
+
.catch(() => {
|
|
63
|
+
reject(new Error('[https] The mkcert has not been installed.'));
|
|
64
|
+
utils_1.logger.info([
|
|
65
|
+
'[https] Please follow the guide to install manually.\n',
|
|
66
|
+
`\tMac: ${utils_1.chalk.green([
|
|
67
|
+
'brew install mkcert',
|
|
68
|
+
'brew install nss',
|
|
69
|
+
'mkcert -install',
|
|
70
|
+
].join(' + '))}\n`,
|
|
71
|
+
`\tWindows: ${utils_1.chalk.green('https://github.com/FiloSottile/mkcert#windows')}\n`,
|
|
72
|
+
`\tLinux: ${utils_1.chalk.green('https://github.com/FiloSottile/mkcert#linux')}\n`,
|
|
73
|
+
].join(''));
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
const getServer = (app, httpsConfig) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
if (!httpsConfig) {
|
|
79
|
+
return http_1.default.createServer(app);
|
|
80
|
+
}
|
|
81
|
+
utils_1.logger.wait('[https] Starting service in https mode...');
|
|
82
|
+
const isHttpsConfigLegally = httpsConfig.cert && httpsConfig.key;
|
|
83
|
+
const { key, cert } = isHttpsConfigLegally
|
|
84
|
+
? httpsConfig
|
|
85
|
+
: yield generateCertFiles(httpsConfig.hosts);
|
|
86
|
+
if (key && cert) {
|
|
87
|
+
return https_1.default.createServer({
|
|
88
|
+
key: (0, fs_1.readFileSync)(key, 'utf8'),
|
|
89
|
+
cert: (0, fs_1.readFileSync)(cert, 'utf8'),
|
|
90
|
+
}, app);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
exports.getServer = getServer;
|
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.10",
|
|
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",
|
|
@@ -25,63 +25,63 @@
|
|
|
25
25
|
"build:client": "pnpm tsc --project ./tsconfig.client.json",
|
|
26
26
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
27
27
|
"dev": "pnpm build -- --watch",
|
|
28
|
-
"generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs"
|
|
28
|
+
"generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs",
|
|
29
|
+
"test": "jest -c ../../jest.turbo.config.ts"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@svgr/
|
|
34
|
-
"@svgr/plugin-
|
|
35
|
-
"@
|
|
36
|
-
"@types/hapi__joi": "17.1.
|
|
37
|
-
"@umijs/babel-preset-umi": "4.0.0-rc.
|
|
38
|
-
"@umijs/
|
|
39
|
-
"@umijs/
|
|
40
|
-
"
|
|
32
|
+
"@parcel/css": "1.7.2",
|
|
33
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
34
|
+
"@svgr/core": "6.2.1",
|
|
35
|
+
"@svgr/plugin-jsx": "^6.2.1",
|
|
36
|
+
"@svgr/plugin-svgo": "^6.2.0",
|
|
37
|
+
"@types/hapi__joi": "17.1.8",
|
|
38
|
+
"@umijs/babel-preset-umi": "4.0.0-rc.10",
|
|
39
|
+
"@umijs/bundler-utils": "4.0.0-rc.10",
|
|
40
|
+
"@umijs/mfsu": "4.0.0-rc.10",
|
|
41
|
+
"@umijs/utils": "4.0.0-rc.10",
|
|
42
|
+
"css-loader": "6.7.1",
|
|
41
43
|
"es5-imcompatible-versions": "^0.1.73",
|
|
42
|
-
"jest-worker": "27.
|
|
44
|
+
"jest-worker": "27.5.1",
|
|
43
45
|
"node-libs-browser": "2.2.1",
|
|
44
|
-
"postcss": "^8.4.
|
|
45
|
-
"postcss-preset-env": "7.
|
|
46
|
+
"postcss": "^8.4.12",
|
|
47
|
+
"postcss-preset-env": "7.4.3",
|
|
46
48
|
"react-error-overlay": "6.0.9"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
|
-
"@
|
|
51
|
+
"@swc/core": "1.2.160",
|
|
50
52
|
"@types/webpack-sources": "3.2.0",
|
|
51
|
-
"@types/ws": "8.
|
|
52
|
-
"autoprefixer": "10.4.
|
|
53
|
-
"babel-loader": "8.2.
|
|
53
|
+
"@types/ws": "8.5.3",
|
|
54
|
+
"autoprefixer": "10.4.4",
|
|
55
|
+
"babel-loader": "8.2.4",
|
|
54
56
|
"compression": "1.7.4",
|
|
55
57
|
"connect-history-api-fallback": "1.6.0",
|
|
56
|
-
"copy-webpack-plugin": "
|
|
57
|
-
"css-minimizer-webpack-plugin": "3.
|
|
58
|
-
"cssnano": "5.
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"http-proxy-middleware": "2.0.1",
|
|
62
|
-
"less": "4.1.2",
|
|
58
|
+
"copy-webpack-plugin": "10.2.4",
|
|
59
|
+
"css-minimizer-webpack-plugin": "3.4.1",
|
|
60
|
+
"cssnano": "5.1.5",
|
|
61
|
+
"fork-ts-checker-webpack-plugin": "7.2.1",
|
|
62
|
+
"http-proxy-middleware": "2.0.4",
|
|
63
63
|
"less-loader": "10.2.0",
|
|
64
|
-
"mini-css-extract-plugin": "2.
|
|
64
|
+
"mini-css-extract-plugin": "2.6.0",
|
|
65
65
|
"postcss-flexbugs-fixes": "5.0.2",
|
|
66
66
|
"postcss-loader": "6.2.1",
|
|
67
|
-
"purgecss-webpack-plugin": "4.
|
|
67
|
+
"purgecss-webpack-plugin": "4.1.3",
|
|
68
68
|
"react-refresh": "0.11.0",
|
|
69
|
-
"sass-loader": "12.
|
|
69
|
+
"sass-loader": "12.6.0",
|
|
70
70
|
"schema-utils": "4.0.0",
|
|
71
71
|
"speed-measure-webpack-plugin": "1.5.0",
|
|
72
72
|
"style-loader": "3.3.1",
|
|
73
73
|
"svgo-loader": "3.0.0",
|
|
74
74
|
"tapable": "2.2.1",
|
|
75
|
-
"terser": "5.
|
|
76
|
-
"terser-webpack-plugin": "5.
|
|
75
|
+
"terser": "5.12.1",
|
|
76
|
+
"terser-webpack-plugin": "5.3.1",
|
|
77
77
|
"url-loader": "4.1.1",
|
|
78
|
-
"webpack": "5.
|
|
78
|
+
"webpack": "5.70.0",
|
|
79
79
|
"webpack-5-chain": "8.0.0",
|
|
80
80
|
"webpack-bundle-analyzer": "4.5.0",
|
|
81
|
-
"webpack-dev-middleware": "5.
|
|
82
|
-
"webpack-manifest-plugin": "
|
|
83
|
-
"webpack-sources": "3.2.
|
|
84
|
-
"ws": "8.
|
|
81
|
+
"webpack-dev-middleware": "5.3.1",
|
|
82
|
+
"webpack-manifest-plugin": "5.0.0",
|
|
83
|
+
"webpack-sources": "3.2.3",
|
|
84
|
+
"ws": "8.5.0"
|
|
85
85
|
},
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
@@ -99,10 +99,8 @@
|
|
|
99
99
|
"cssnano",
|
|
100
100
|
"compression",
|
|
101
101
|
"connect-history-api-fallback",
|
|
102
|
-
"express",
|
|
103
102
|
"fork-ts-checker-webpack-plugin",
|
|
104
103
|
"http-proxy-middleware",
|
|
105
|
-
"less",
|
|
106
104
|
"less-loader",
|
|
107
105
|
"mini-css-extract-plugin",
|
|
108
106
|
"postcss-flexbugs-fixes",
|
|
@@ -131,9 +129,9 @@
|
|
|
131
129
|
"@babel/core": "@umijs/bundler-utils/compiled/babel/core",
|
|
132
130
|
"es-module-lexer": "@umijs/bundler-utils/compiled/es-module-lexer",
|
|
133
131
|
"esbuild": "@umijs/bundler-utils/compiled/esbuild",
|
|
134
|
-
"express": "
|
|
132
|
+
"express": "@umijs/bundler-utils/compiled/express",
|
|
135
133
|
"jest-worker": "jest-worker",
|
|
136
|
-
"less": "
|
|
134
|
+
"less": "@umijs/bundler-utils/compiled/less",
|
|
137
135
|
"cssnano": "$$LOCAL",
|
|
138
136
|
"postcss": "postcss",
|
|
139
137
|
"tapable": "$$LOCAL",
|
|
@@ -172,7 +170,6 @@
|
|
|
172
170
|
"compression",
|
|
173
171
|
"connect-history-api-fallback",
|
|
174
172
|
"fork-ts-checker-webpack-plugin",
|
|
175
|
-
"less",
|
|
176
173
|
"less-loader",
|
|
177
174
|
"mini-css-extract-plugin",
|
|
178
175
|
"postcss-flexbugs-fixes",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright JS Foundation and other contributors
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
'Software'), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|