@umijs/bundler-webpack 4.0.0-rc.13 → 4.0.0-rc.14
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 +15 -7
- package/dist/build.js +1 -0
- package/dist/client/client.js +15 -7
- package/dist/config/config.d.ts +1 -0
- package/dist/config/config.js +3 -2
- package/dist/config/javaScriptRules.d.ts +1 -0
- package/dist/config/javaScriptRules.js +36 -12
- package/dist/config/nodePolyfill.js +2 -1
- package/dist/dev.js +14 -0
- package/dist/schema.js +1 -0
- package/dist/server/https.d.ts +1 -2
- package/dist/server/https.js +3 -2
- package/dist/server/server.js +0 -12
- package/dist/server/ws.d.ts +3 -1
- package/dist/types.d.ts +1 -0
- package/package.json +10 -8
package/client/client/client.js
CHANGED
|
@@ -13,21 +13,29 @@ 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
|
|
17
|
-
let l = location;
|
|
16
|
+
function getHost() {
|
|
18
17
|
if (process.env.SOCKET_SERVER) {
|
|
19
|
-
|
|
18
|
+
return new URL(process.env.SOCKET_SERVER);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
return location;
|
|
21
|
+
}
|
|
22
|
+
function getSocketUrl() {
|
|
23
|
+
let h = getHost();
|
|
24
|
+
const host = h.host;
|
|
25
|
+
const isHttps = h.protocol === 'https:';
|
|
23
26
|
return `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
24
27
|
}
|
|
28
|
+
function getPingUrl() {
|
|
29
|
+
const h = getHost();
|
|
30
|
+
return `${h.protocol}//${h.host}/__umi_ping`;
|
|
31
|
+
}
|
|
25
32
|
let pingTimer = null;
|
|
26
33
|
let isFirstCompilation = true;
|
|
27
34
|
let mostRecentCompilationHash = null;
|
|
28
35
|
let hasCompileErrors = false;
|
|
29
36
|
let hadRuntimeError = false;
|
|
30
|
-
const
|
|
37
|
+
const pingUrl = getPingUrl();
|
|
38
|
+
const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
|
|
31
39
|
socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
40
|
data = JSON.parse(data);
|
|
33
41
|
if (data.type === 'connected') {
|
|
@@ -45,7 +53,7 @@ function waitForSuccessfulPing(ms = 1000) {
|
|
|
45
53
|
// eslint-disable-next-line no-constant-condition
|
|
46
54
|
while (true) {
|
|
47
55
|
try {
|
|
48
|
-
yield fetch(
|
|
56
|
+
yield fetch(pingUrl);
|
|
49
57
|
break;
|
|
50
58
|
}
|
|
51
59
|
catch (e) {
|
package/dist/build.js
CHANGED
|
@@ -35,6 +35,7 @@ function build(opts) {
|
|
|
35
35
|
...(opts.beforeBabelPresets || []),
|
|
36
36
|
...(opts.extraBabelPresets || []),
|
|
37
37
|
],
|
|
38
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
38
39
|
chainWebpack: opts.chainWebpack,
|
|
39
40
|
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
40
41
|
cache: opts.cache,
|
package/dist/client/client.js
CHANGED
|
@@ -41,21 +41,29 @@ 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
|
|
45
|
-
let l = location;
|
|
44
|
+
function getHost() {
|
|
46
45
|
if (process.env.SOCKET_SERVER) {
|
|
47
|
-
|
|
46
|
+
return new URL(process.env.SOCKET_SERVER);
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
return location;
|
|
49
|
+
}
|
|
50
|
+
function getSocketUrl() {
|
|
51
|
+
let h = getHost();
|
|
52
|
+
const host = h.host;
|
|
53
|
+
const isHttps = h.protocol === 'https:';
|
|
51
54
|
return `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
52
55
|
}
|
|
56
|
+
function getPingUrl() {
|
|
57
|
+
const h = getHost();
|
|
58
|
+
return `${h.protocol}//${h.host}/__umi_ping`;
|
|
59
|
+
}
|
|
53
60
|
let pingTimer = null;
|
|
54
61
|
let isFirstCompilation = true;
|
|
55
62
|
let mostRecentCompilationHash = null;
|
|
56
63
|
let hasCompileErrors = false;
|
|
57
64
|
let hadRuntimeError = false;
|
|
58
|
-
const
|
|
65
|
+
const pingUrl = getPingUrl();
|
|
66
|
+
const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
|
|
59
67
|
socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
68
|
data = JSON.parse(data);
|
|
61
69
|
if (data.type === 'connected') {
|
|
@@ -73,7 +81,7 @@ function waitForSuccessfulPing(ms = 1000) {
|
|
|
73
81
|
// eslint-disable-next-line no-constant-condition
|
|
74
82
|
while (true) {
|
|
75
83
|
try {
|
|
76
|
-
yield fetch(
|
|
84
|
+
yield fetch(pingUrl);
|
|
77
85
|
break;
|
|
78
86
|
}
|
|
79
87
|
catch (e) {
|
package/dist/config/config.d.ts
CHANGED
package/dist/config/config.js
CHANGED
|
@@ -35,7 +35,6 @@ 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");
|
|
39
38
|
const progressPlugin_1 = require("./progressPlugin");
|
|
40
39
|
const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
|
|
41
40
|
const svgRules_1 = require("./svgRules");
|
|
@@ -55,6 +54,7 @@ function getConfig(opts) {
|
|
|
55
54
|
babelPreset: opts.babelPreset,
|
|
56
55
|
extraBabelPlugins: opts.extraBabelPlugins || [],
|
|
57
56
|
extraBabelPresets: opts.extraBabelPresets || [],
|
|
57
|
+
extraBabelIncludes: opts.extraBabelIncludes || [],
|
|
58
58
|
extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
|
|
59
59
|
browsers: (0, browsersList_1.getBrowsersList)({
|
|
60
60
|
targets: userConfig.targets,
|
|
@@ -155,7 +155,8 @@ function getConfig(opts) {
|
|
|
155
155
|
// handle HarmonyLinkingError
|
|
156
156
|
yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
|
|
157
157
|
// remove node: prefix
|
|
158
|
-
|
|
158
|
+
// disable for performance
|
|
159
|
+
// await addNodePrefixPlugin(applyOpts);
|
|
159
160
|
// runtimePublicPath
|
|
160
161
|
if (userConfig.runtimePublicPath) {
|
|
161
162
|
config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.addJavaScriptRules = void 0;
|
|
13
13
|
const mfsu_1 = require("@umijs/mfsu");
|
|
14
14
|
const utils_1 = require("@umijs/utils");
|
|
15
|
+
const path_1 = require("path");
|
|
15
16
|
const webpack_1 = require("../../compiled/webpack");
|
|
16
17
|
const constants_1 = require("../constants");
|
|
17
18
|
const types_1 = require("../types");
|
|
@@ -40,18 +41,41 @@ function addJavaScriptRules(opts) {
|
|
|
40
41
|
config.module
|
|
41
42
|
.rule('extra-src')
|
|
42
43
|
.test(/\.(js|mjs)$/)
|
|
43
|
-
.include.add(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
.include.add([
|
|
45
|
+
// support extraBabelIncludes
|
|
46
|
+
...opts.extraBabelIncludes.map((p) => {
|
|
47
|
+
// handle absolute path
|
|
48
|
+
if ((0, path_1.isAbsolute)(p)) {
|
|
49
|
+
return p;
|
|
50
|
+
}
|
|
51
|
+
// resolve npm package name
|
|
52
|
+
try {
|
|
53
|
+
if (p.startsWith('./')) {
|
|
54
|
+
return require.resolve(p, { paths: [cwd] });
|
|
55
|
+
}
|
|
56
|
+
return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
60
|
+
throw new Error('Cannot resolve extraBabelIncludes: ' + p);
|
|
61
|
+
}
|
|
62
|
+
throw e;
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
// support es5ImcompatibleVersions
|
|
66
|
+
(path) => {
|
|
67
|
+
try {
|
|
68
|
+
// do src transform for bundler-webpack/client/client/client.js
|
|
69
|
+
if (path.includes('client/client/client'))
|
|
70
|
+
return true;
|
|
71
|
+
return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error(utils_1.chalk.red(e));
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
])
|
|
55
79
|
.end(),
|
|
56
80
|
];
|
|
57
81
|
if (userConfig.mdx) {
|
|
@@ -14,12 +14,13 @@ 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');
|
|
17
18
|
config.plugin('node-polyfill-provider').use(webpack_1.ProvidePlugin, [
|
|
18
19
|
{
|
|
19
20
|
Buffer: ['buffer', 'Buffer'],
|
|
21
|
+
process: nodeLibs['process'],
|
|
20
22
|
},
|
|
21
23
|
]);
|
|
22
|
-
const nodeLibs = require('node-libs-browser');
|
|
23
24
|
config.resolve.fallback.merge(Object.assign(Object.assign({}, Object.keys(nodeLibs).reduce((memo, key) => {
|
|
24
25
|
if (nodeLibs[key]) {
|
|
25
26
|
memo[key] = nodeLibs[key];
|
package/dist/dev.js
CHANGED
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.dev = exports.stripUndefined = void 0;
|
|
16
16
|
const mfsu_1 = require("@umijs/mfsu");
|
|
17
17
|
const utils_1 = require("@umijs/utils");
|
|
18
|
+
const fs_1 = require("fs");
|
|
18
19
|
const path_1 = require("path");
|
|
19
20
|
const webpack_1 = __importDefault(require("../compiled/webpack"));
|
|
20
21
|
const config_1 = require("./config/config");
|
|
@@ -80,6 +81,7 @@ function dev(opts) {
|
|
|
80
81
|
...(opts.beforeBabelPresets || []),
|
|
81
82
|
...(opts.extraBabelPresets || []),
|
|
82
83
|
],
|
|
84
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
83
85
|
extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
|
|
84
86
|
chainWebpack: opts.chainWebpack,
|
|
85
87
|
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
@@ -112,6 +114,18 @@ function dev(opts) {
|
|
|
112
114
|
config: webpackConfig,
|
|
113
115
|
depConfig: depConfig,
|
|
114
116
|
}));
|
|
117
|
+
if (mfsu &&
|
|
118
|
+
webpackConfig.cache &&
|
|
119
|
+
typeof webpackConfig.cache === 'object' &&
|
|
120
|
+
webpackConfig.cache.type === 'filesystem') {
|
|
121
|
+
const webpackCachePath = (0, path_1.join)(webpackConfig.cache.cacheDirectory, `default-development`, 'index.pack');
|
|
122
|
+
const mfsuCacheExists = (0, fs_1.existsSync)(mfsu.depInfo.cacheFilePath);
|
|
123
|
+
const webpackCacheExists = (0, fs_1.existsSync)(webpackCachePath);
|
|
124
|
+
if (webpackCacheExists && !mfsuCacheExists) {
|
|
125
|
+
utils_1.logger.warn(`Invalidate webpack cache since mfsu cache is missing`);
|
|
126
|
+
utils_1.rimraf.sync(webpackConfig.cache.cacheDirectory);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
115
129
|
yield (0, server_1.createServer)({
|
|
116
130
|
webpackConfig,
|
|
117
131
|
userConfig: opts.config,
|
package/dist/schema.js
CHANGED
|
@@ -40,6 +40,7 @@ function getSchemas() {
|
|
|
40
40
|
devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
|
|
41
41
|
esm: (Joi) => Joi.object(),
|
|
42
42
|
externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
|
|
43
|
+
extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
|
|
43
44
|
extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
44
45
|
extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
|
|
45
46
|
extraPostCSSPlugins: (Joi) => Joi.array(),
|
package/dist/server/https.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { RequestListener } from 'http';
|
|
3
|
-
import https from 'https';
|
|
4
3
|
import { HttpsParams } from '../types';
|
|
5
|
-
export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsParams): Promise<https.Server>;
|
|
4
|
+
export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsParams): Promise<import("https").Server>;
|
package/dist/server/https.js
CHANGED
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.createHttpsServer = void 0;
|
|
16
16
|
const utils_1 = require("@umijs/utils");
|
|
17
17
|
const fs_1 = require("fs");
|
|
18
|
-
const https_1 = __importDefault(require("https"));
|
|
19
18
|
const path_1 = require("path");
|
|
19
|
+
const spdy_1 = __importDefault(require("spdy"));
|
|
20
20
|
const defaultHttpsHosts = ['localhost', '127.0.0.1'];
|
|
21
21
|
function createHttpsServer(app, httpsConfig) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -64,10 +64,11 @@ function createHttpsServer(app, httpsConfig) {
|
|
|
64
64
|
]);
|
|
65
65
|
}
|
|
66
66
|
// Create server
|
|
67
|
-
|
|
67
|
+
const http2Service = spdy_1.default.createServer({
|
|
68
68
|
key: (0, fs_1.readFileSync)(key, 'utf-8'),
|
|
69
69
|
cert: (0, fs_1.readFileSync)(cert, 'utf-8'),
|
|
70
70
|
}, app);
|
|
71
|
+
return http2Service;
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
exports.createHttpsServer = createHttpsServer;
|
package/dist/server/server.js
CHANGED
|
@@ -28,18 +28,6 @@ function createServer(opts) {
|
|
|
28
28
|
const { webpackConfig, userConfig } = opts;
|
|
29
29
|
const { proxy } = userConfig;
|
|
30
30
|
const app = (0, express_1.default)();
|
|
31
|
-
// basename middleware
|
|
32
|
-
app.use((req, _res, next) => {
|
|
33
|
-
const { url, path } = req;
|
|
34
|
-
const { basename, history } = userConfig;
|
|
35
|
-
if ((history === null || history === void 0 ? void 0 : history.type) === 'browser' &&
|
|
36
|
-
basename !== '/' &&
|
|
37
|
-
url.startsWith(basename)) {
|
|
38
|
-
req.url = url.slice(basename.length);
|
|
39
|
-
req.path = path.slice(basename.length);
|
|
40
|
-
}
|
|
41
|
-
next();
|
|
42
|
-
});
|
|
43
31
|
// cros
|
|
44
32
|
app.use((_req, res, next) => {
|
|
45
33
|
res.header('Access-Control-Allow-Origin', '*');
|
package/dist/server/ws.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server as HttpServer } from 'http';
|
|
3
|
+
import { Http2Server } from 'http2';
|
|
3
4
|
import { Server as HttpsServer } from 'https';
|
|
5
|
+
import { Server } from 'spdy';
|
|
4
6
|
import WebSocket from '../../compiled/ws';
|
|
5
|
-
export declare function createWebSocketServer(server: HttpServer | HttpsServer): {
|
|
7
|
+
export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
|
|
6
8
|
send(message: string): void;
|
|
7
9
|
wss: WebSocket.Server;
|
|
8
10
|
close(): void;
|
package/dist/types.d.ts
CHANGED
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.14",
|
|
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",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "pnpm tsc",
|
|
25
25
|
"build:client": "pnpm tsc --project ./tsconfig.client.json",
|
|
26
|
-
"build:deps": "
|
|
26
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
27
27
|
"dev": "pnpm build -- --watch",
|
|
28
28
|
"generate:webpackPackages": "zx ./scripts/generateWebpackPackages.mjs",
|
|
29
|
-
"test": "
|
|
29
|
+
"test": "umi-scripts jest-turbo"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@parcel/css": "1.8.1",
|
|
@@ -35,20 +35,22 @@
|
|
|
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.14",
|
|
39
|
+
"@umijs/bundler-utils": "4.0.0-rc.14",
|
|
40
|
+
"@umijs/mfsu": "4.0.0-rc.14",
|
|
41
|
+
"@umijs/utils": "4.0.0-rc.14",
|
|
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"
|
|
48
|
+
"react-error-overlay": "6.0.9",
|
|
49
|
+
"spdy": "^4.0.2"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@swc/core": "1.2.165",
|
|
53
|
+
"@types/spdy": "^3.4.5",
|
|
52
54
|
"@types/webpack-sources": "3.2.0",
|
|
53
55
|
"@types/ws": "8.5.3",
|
|
54
56
|
"autoprefixer": "10.4.4",
|