@umijs/bundler-webpack 4.0.0-rc.10 → 4.0.0-rc.11
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 +10 -4
- package/dist/client/client.js +10 -4
- package/dist/config/config.js +3 -0
- package/dist/config/nodePolyfill.js +1 -1
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +25 -0
- package/dist/server/https.d.ts +5 -0
- package/dist/server/https.js +73 -0
- package/dist/server/server.d.ts +2 -1
- package/dist/server/server.js +5 -2
- package/package.json +5 -5
- package/dist/utils/server.d.ts +0 -5
- package/dist/utils/server.js +0 -93
package/client/client/client.js
CHANGED
|
@@ -13,15 +13,21 @@ import * as ErrorOverlay from 'react-error-overlay';
|
|
|
13
13
|
import { MESSAGE_TYPE } from '../constants';
|
|
14
14
|
import { formatWebpackMessages } from '../utils/formatWebpackMessages';
|
|
15
15
|
console.log('[webpack] connecting...');
|
|
16
|
+
function getSocketHost() {
|
|
17
|
+
let l = location;
|
|
18
|
+
if (process.env.SOCKET_SERVER) {
|
|
19
|
+
l = new URL(process.env.SOCKET_SERVER);
|
|
20
|
+
}
|
|
21
|
+
const host = l.host;
|
|
22
|
+
const isHttps = l.protocol === 'https:';
|
|
23
|
+
return `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
24
|
+
}
|
|
16
25
|
let pingTimer = null;
|
|
17
|
-
const host = location.host;
|
|
18
|
-
const isHttps = location.protocol === 'https:';
|
|
19
|
-
const wsUrl = `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
20
26
|
let isFirstCompilation = true;
|
|
21
27
|
let mostRecentCompilationHash = null;
|
|
22
28
|
let hasCompileErrors = false;
|
|
23
29
|
let hadRuntimeError = false;
|
|
24
|
-
const socket = new WebSocket(
|
|
30
|
+
const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
|
|
25
31
|
socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
32
|
data = JSON.parse(data);
|
|
27
33
|
if (data.type === 'connected') {
|
package/dist/client/client.js
CHANGED
|
@@ -41,15 +41,21 @@ const ErrorOverlay = __importStar(require("react-error-overlay"));
|
|
|
41
41
|
const constants_1 = require("../constants");
|
|
42
42
|
const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
|
|
43
43
|
console.log('[webpack] connecting...');
|
|
44
|
+
function getSocketHost() {
|
|
45
|
+
let l = location;
|
|
46
|
+
if (process.env.SOCKET_SERVER) {
|
|
47
|
+
l = new URL(process.env.SOCKET_SERVER);
|
|
48
|
+
}
|
|
49
|
+
const host = l.host;
|
|
50
|
+
const isHttps = l.protocol === 'https:';
|
|
51
|
+
return `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
52
|
+
}
|
|
44
53
|
let pingTimer = null;
|
|
45
|
-
const host = location.host;
|
|
46
|
-
const isHttps = location.protocol === 'https:';
|
|
47
|
-
const wsUrl = `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
48
54
|
let isFirstCompilation = true;
|
|
49
55
|
let mostRecentCompilationHash = null;
|
|
50
56
|
let hasCompileErrors = false;
|
|
51
57
|
let hadRuntimeError = false;
|
|
52
|
-
const socket = new WebSocket(
|
|
58
|
+
const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
|
|
53
59
|
socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
60
|
data = JSON.parse(data);
|
|
55
61
|
if (data.type === 'connected') {
|
package/dist/config/config.js
CHANGED
|
@@ -35,6 +35,7 @@ const javaScriptRules_1 = require("./javaScriptRules");
|
|
|
35
35
|
const manifestPlugin_1 = require("./manifestPlugin");
|
|
36
36
|
const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
|
|
37
37
|
const nodePolyfill_1 = require("./nodePolyfill");
|
|
38
|
+
const nodePrefixPlugin_1 = require("./nodePrefixPlugin");
|
|
38
39
|
const progressPlugin_1 = require("./progressPlugin");
|
|
39
40
|
const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
|
|
40
41
|
const svgRules_1 = require("./svgRules");
|
|
@@ -153,6 +154,8 @@ function getConfig(opts) {
|
|
|
153
154
|
// await applyPurgeCSSWebpackPlugin(applyOpts);
|
|
154
155
|
// handle HarmonyLinkingError
|
|
155
156
|
yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
157
|
+
// remove node: prefix
|
|
158
|
+
yield (0, nodePrefixPlugin_1.addNodePrefixPlugin)(applyOpts);
|
|
156
159
|
// runtimePublicPath
|
|
157
160
|
if (userConfig.runtimePublicPath) {
|
|
158
161
|
config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
|
|
@@ -14,12 +14,12 @@ const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
|
14
14
|
function addNodePolyfill(opts) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const { config } = opts;
|
|
17
|
-
const nodeLibs = require('node-libs-browser');
|
|
18
17
|
config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
|
|
19
18
|
{
|
|
20
19
|
Buffer: ['buffer', 'Buffer'],
|
|
21
20
|
},
|
|
22
21
|
]);
|
|
22
|
+
const nodeLibs = require('node-libs-browser');
|
|
23
23
|
config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
|
|
24
24
|
if (nodeLibs[key]) {
|
|
25
25
|
memo[key] = nodeLibs[key];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
name?: string;
|
|
5
|
+
config: Config;
|
|
6
|
+
userConfig: IConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
env: Env;
|
|
9
|
+
}
|
|
10
|
+
export declare function addNodePrefixPlugin(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.addNodePrefixPlugin = void 0;
|
|
13
|
+
const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
|
|
14
|
+
function addNodePrefixPlugin(opts) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const { config } = opts;
|
|
17
|
+
config.plugin('node-prefix-plugin').use(webpack_1.NormalModuleReplacementPlugin, [
|
|
18
|
+
/^node:/,
|
|
19
|
+
(resource) => {
|
|
20
|
+
resource.request = resource.request.replace(/^node:/, '');
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.addNodePrefixPlugin = addNodePrefixPlugin;
|
|
@@ -0,0 +1,73 @@
|
|
|
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.createHttpsServer = void 0;
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const https_1 = __importDefault(require("https"));
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const defaultHttpsHosts = ['localhost', '127.0.0.1'];
|
|
21
|
+
function createHttpsServer(app, httpsConfig) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
utils_1.logger.wait('[HTTPS] Starting service in https mode...');
|
|
24
|
+
// Check if mkcert is installed
|
|
25
|
+
try {
|
|
26
|
+
yield utils_1.execa.execa('mkcert', ['--version']);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
utils_1.logger.error('[HTTPS] The mkcert has not been installed.');
|
|
30
|
+
utils_1.logger.info('[HTTPS] Please follow the guide to install manually.');
|
|
31
|
+
switch (process.platform) {
|
|
32
|
+
case 'darwin':
|
|
33
|
+
console.log(utils_1.chalk.green('$ brew install mkcert'));
|
|
34
|
+
console.log(utils_1.chalk.gray('# If you use firefox, please install nss.'));
|
|
35
|
+
console.log(utils_1.chalk.green('$ brew install nss'));
|
|
36
|
+
console.log(utils_1.chalk.green('$ mkcert -install'));
|
|
37
|
+
break;
|
|
38
|
+
case 'win32':
|
|
39
|
+
console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#windows'));
|
|
40
|
+
break;
|
|
41
|
+
case 'linux':
|
|
42
|
+
console.log(utils_1.chalk.green('Checkout https://github.com/FiloSottile/mkcert#linux'));
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`[HTTPS] mkcert not found.`);
|
|
48
|
+
}
|
|
49
|
+
let { key, cert, hosts } = httpsConfig;
|
|
50
|
+
hosts = hosts || defaultHttpsHosts;
|
|
51
|
+
if (!key || !cert) {
|
|
52
|
+
key = (0, path_1.join)(__dirname, 'umi.key.pem');
|
|
53
|
+
cert = (0, path_1.join)(__dirname, 'umi.pem');
|
|
54
|
+
}
|
|
55
|
+
// Generate cert and key files if they are not exist.
|
|
56
|
+
if (!(0, fs_1.existsSync)(key) || !(0, fs_1.existsSync)(cert)) {
|
|
57
|
+
utils_1.logger.wait('[HTTPS] Generating cert and key files...');
|
|
58
|
+
yield utils_1.execa.execa('mkcert', [
|
|
59
|
+
'-cert-file',
|
|
60
|
+
cert,
|
|
61
|
+
'-key-file',
|
|
62
|
+
key,
|
|
63
|
+
...hosts,
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
// Create server
|
|
67
|
+
return https_1.default.createServer({
|
|
68
|
+
key: (0, fs_1.readFileSync)(key, 'utf-8'),
|
|
69
|
+
cert: (0, fs_1.readFileSync)(cert, 'utf-8'),
|
|
70
|
+
}, app);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.createHttpsServer = createHttpsServer;
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Configuration } from '@umijs/bundler-webpack/compiled/webpack';
|
|
3
|
+
import http from 'http';
|
|
3
4
|
import { IConfig } from '../types';
|
|
4
5
|
interface IOpts {
|
|
5
6
|
cwd: string;
|
|
@@ -11,5 +12,5 @@ interface IOpts {
|
|
|
11
12
|
afterMiddlewares?: any[];
|
|
12
13
|
onDevCompileDone?: Function;
|
|
13
14
|
}
|
|
14
|
-
export declare function createServer(opts: IOpts): Promise<import("
|
|
15
|
+
export declare function createServer(opts: IOpts): Promise<import("https").Server | http.Server | null>;
|
|
15
16
|
export {};
|
package/dist/server/server.js
CHANGED
|
@@ -18,9 +18,10 @@ 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"));
|
|
21
22
|
const path_1 = require("path");
|
|
22
23
|
const constants_1 = require("../constants");
|
|
23
|
-
const
|
|
24
|
+
const https_1 = require("./https");
|
|
24
25
|
const ws_1 = require("./ws");
|
|
25
26
|
function createServer(opts) {
|
|
26
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -171,7 +172,9 @@ function createServer(opts) {
|
|
|
171
172
|
next();
|
|
172
173
|
}
|
|
173
174
|
});
|
|
174
|
-
const server =
|
|
175
|
+
const server = userConfig.https
|
|
176
|
+
? yield (0, https_1.createHttpsServer)(app, userConfig.https)
|
|
177
|
+
: http_1.default.createServer(app);
|
|
175
178
|
if (!server) {
|
|
176
179
|
return null;
|
|
177
180
|
}
|
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.11",
|
|
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,10 +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-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.11",
|
|
39
|
+
"@umijs/bundler-utils": "4.0.0-rc.11",
|
|
40
|
+
"@umijs/mfsu": "4.0.0-rc.11",
|
|
41
|
+
"@umijs/utils": "4.0.0-rc.11",
|
|
42
42
|
"css-loader": "6.7.1",
|
|
43
43
|
"es5-imcompatible-versions": "^0.1.73",
|
|
44
44
|
"jest-worker": "27.5.1",
|
package/dist/utils/server.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
package/dist/utils/server.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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;
|