@umijs/bundler-webpack 4.0.0-canary.20220323.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/copy-webpack-plugin/{576.index.js → 939.index.js} +11 -11
- package/compiled/copy-webpack-plugin/index.js +12 -12
- package/dist/client/client.js +2 -1
- package/dist/dev.js +5 -0
- package/dist/schema.js +1 -0
- package/dist/server/server.d.ts +1 -2
- package/dist/server/server.js +11 -8
- package/dist/server/ws.d.ts +3 -2
- package/dist/swcPlugins/autoCSSModules.js +3 -1
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.js +3 -2
- package/dist/types.d.ts +6 -0
- package/dist/utils/server.d.ts +5 -0
- package/dist/utils/server.js +93 -0
- package/package.json +6 -5
package/dist/client/client.js
CHANGED
|
@@ -43,7 +43,8 @@ const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
|
|
|
43
43
|
console.log('[webpack] connecting...');
|
|
44
44
|
let pingTimer = null;
|
|
45
45
|
const host = location.host;
|
|
46
|
-
const
|
|
46
|
+
const isHttps = location.protocol === 'https:';
|
|
47
|
+
const wsUrl = `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
47
48
|
let isFirstCompilation = true;
|
|
48
49
|
let mostRecentCompilationHash = null;
|
|
49
50
|
let hasCompileErrors = false;
|
package/dist/dev.js
CHANGED
|
@@ -46,6 +46,11 @@ function dev(opts) {
|
|
|
46
46
|
return {
|
|
47
47
|
version: require('../package.json').version,
|
|
48
48
|
esbuildMode: !!((_a = opts.config.mfsu) === null || _a === void 0 ? void 0 : _a.esbuild),
|
|
49
|
+
alias: opts.config.alias,
|
|
50
|
+
externals: opts.config.externals,
|
|
51
|
+
theme: opts.config.theme,
|
|
52
|
+
runtimePublicPath: opts.config.runtimePublicPath,
|
|
53
|
+
publicPath: opts.config.publicPath,
|
|
49
54
|
};
|
|
50
55
|
},
|
|
51
56
|
});
|
package/dist/schema.js
CHANGED
|
@@ -46,6 +46,7 @@ function getSchemas() {
|
|
|
46
46
|
fastRefresh: (Joi) => Joi.boolean(),
|
|
47
47
|
forkTSChecker: (Joi) => Joi.object(),
|
|
48
48
|
hash: (Joi) => Joi.boolean(),
|
|
49
|
+
https: (Joi) => Joi.object(),
|
|
49
50
|
ignoreMomentLocale: (Joi) => Joi.boolean(),
|
|
50
51
|
inlineLimit: (Joi) => Joi.number(),
|
|
51
52
|
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),
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
|
|
3
|
-
import http from 'http';
|
|
4
3
|
import { IConfig } from '../types';
|
|
5
4
|
interface IOpts {
|
|
6
5
|
cwd: string;
|
|
@@ -12,5 +11,5 @@ interface IOpts {
|
|
|
12
11
|
afterMiddlewares?: any[];
|
|
13
12
|
onDevCompileDone?: Function;
|
|
14
13
|
}
|
|
15
|
-
export declare function createServer(opts: IOpts): Promise<http.Server>;
|
|
14
|
+
export declare function createServer(opts: IOpts): Promise<import("http").Server | import("https").Server | null>;
|
|
16
15
|
export {};
|
package/dist/server/server.js
CHANGED
|
@@ -18,9 +18,9 @@ const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-pr
|
|
|
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 }
|
|
@@ -165,24 +165,27 @@ function createServer(opts) {
|
|
|
165
165
|
res.set('Content-Type', 'text/html');
|
|
166
166
|
const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
|
|
167
167
|
if ((0, fs_1.existsSync)(htmlPath)) {
|
|
168
|
-
|
|
169
|
-
res.send(html);
|
|
168
|
+
(0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
|
|
170
169
|
}
|
|
171
170
|
else {
|
|
172
171
|
next();
|
|
173
172
|
}
|
|
174
173
|
});
|
|
175
|
-
const server =
|
|
174
|
+
const server = yield (0, server_1.getServer)(app, userConfig.https);
|
|
175
|
+
if (!server) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
176
178
|
const ws = (0, ws_1.createWebSocketServer)(server);
|
|
177
179
|
ws.wss.on('connection', (socket) => {
|
|
178
180
|
if (stats) {
|
|
179
181
|
sendStats(getStats(stats), false, socket);
|
|
180
182
|
}
|
|
181
183
|
});
|
|
184
|
+
const protocol = userConfig.https ? 'https:' : 'http:';
|
|
182
185
|
const port = opts.port || 8000;
|
|
183
186
|
server.listen(port, () => {
|
|
184
187
|
const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : '127.0.0.1';
|
|
185
|
-
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}`)}`);
|
|
186
189
|
});
|
|
187
190
|
return server;
|
|
188
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;
|
|
@@ -5,6 +5,7 @@ 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;
|
|
@@ -24,7 +25,8 @@ class AutoCSSModule extends Visitor_1.default {
|
|
|
24
25
|
const { specifiers, source } = expression;
|
|
25
26
|
const { value } = source;
|
|
26
27
|
if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
|
|
27
|
-
|
|
28
|
+
const newImportFrom = `${value}?modules`;
|
|
29
|
+
(0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
|
|
28
30
|
}
|
|
29
31
|
return expression;
|
|
30
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
|
@@ -41,6 +41,11 @@ export interface DeadCodeParams {
|
|
|
41
41
|
detectUnusedExport?: boolean;
|
|
42
42
|
context?: string;
|
|
43
43
|
}
|
|
44
|
+
export interface HttpsParams {
|
|
45
|
+
key?: string;
|
|
46
|
+
cert?: string;
|
|
47
|
+
hosts?: string[];
|
|
48
|
+
}
|
|
44
49
|
export interface IConfig {
|
|
45
50
|
alias?: Record<string, string>;
|
|
46
51
|
autoCSSModules?: boolean;
|
|
@@ -63,6 +68,7 @@ export interface IConfig {
|
|
|
63
68
|
depTranspiler?: Transpiler;
|
|
64
69
|
devtool?: Config.DevTool;
|
|
65
70
|
deadCode?: DeadCodeParams;
|
|
71
|
+
https?: HttpsParams;
|
|
66
72
|
externals?: WebpackConfig['externals'];
|
|
67
73
|
esm?: {
|
|
68
74
|
[key: string]: any;
|
|
@@ -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-
|
|
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",
|
|
@@ -35,9 +35,10 @@
|
|
|
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-
|
|
39
|
-
"@umijs/
|
|
40
|
-
"@umijs/
|
|
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",
|
|
41
42
|
"css-loader": "6.7.1",
|
|
42
43
|
"es5-imcompatible-versions": "^0.1.73",
|
|
43
44
|
"jest-worker": "27.5.1",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"react-error-overlay": "6.0.9"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@swc/core": "1.2.
|
|
51
|
+
"@swc/core": "1.2.160",
|
|
51
52
|
"@types/webpack-sources": "3.2.0",
|
|
52
53
|
"@types/ws": "8.5.3",
|
|
53
54
|
"autoprefixer": "10.4.4",
|