@umijs/bundler-webpack 4.0.0-canary.20220429.3 → 4.0.0-canary.20220429.4
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.d.ts +20 -0
- package/dist/build.js +75 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +90 -0
- package/dist/client/client.d.ts +1 -0
- package/dist/client/client.js +258 -0
- package/dist/config/_sampleFeature.d.ts +10 -0
- package/dist/config/_sampleFeature.js +22 -0
- package/dist/config/assetRules.d.ts +11 -0
- package/dist/config/assetRules.js +61 -0
- package/dist/config/bundleAnalyzerPlugin.d.ts +10 -0
- package/dist/config/bundleAnalyzerPlugin.js +30 -0
- package/dist/config/compressPlugin.d.ts +10 -0
- package/dist/config/compressPlugin.js +91 -0
- package/dist/config/config.d.ts +27 -0
- package/dist/config/config.js +226 -0
- package/dist/config/copyPlugin.d.ts +10 -0
- package/dist/config/copyPlugin.js +49 -0
- package/dist/config/cssRules.d.ts +11 -0
- package/dist/config/cssRules.js +98 -0
- package/dist/config/definePlugin.d.ts +15 -0
- package/dist/config/definePlugin.js +45 -0
- 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/fastRefreshPlugin.d.ts +12 -0
- package/dist/config/fastRefreshPlugin.js +34 -0
- package/dist/config/forkTSCheckerPlugin.d.ts +11 -0
- package/dist/config/forkTSCheckerPlugin.js +34 -0
- package/dist/config/harmonyLinkingErrorPlugin.d.ts +6 -0
- package/dist/config/harmonyLinkingErrorPlugin.js +42 -0
- package/dist/config/ignorePlugin.d.ts +10 -0
- package/dist/config/ignorePlugin.js +27 -0
- package/dist/config/javaScriptRules.d.ts +16 -0
- package/dist/config/javaScriptRules.js +188 -0
- package/dist/config/manifestPlugin.d.ts +11 -0
- package/dist/config/manifestPlugin.js +25 -0
- package/dist/config/miniCSSExtractPlugin.d.ts +11 -0
- package/dist/config/miniCSSExtractPlugin.js +33 -0
- package/dist/config/nodePolyfill.d.ts +10 -0
- package/dist/config/nodePolyfill.js +35 -0
- package/dist/config/nodePrefixPlugin.d.ts +11 -0
- package/dist/config/nodePrefixPlugin.js +25 -0
- package/dist/config/progressPlugin.d.ts +11 -0
- package/dist/config/progressPlugin.js +27 -0
- package/dist/config/purgecssWebpackPlugin.d.ts +10 -0
- package/dist/config/purgecssWebpackPlugin.js +32 -0
- package/dist/config/speedMeasureWebpackPlugin.d.ts +6 -0
- package/dist/config/speedMeasureWebpackPlugin.js +34 -0
- package/dist/config/svgRules.d.ts +12 -0
- package/dist/config/svgRules.js +57 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.js +24 -0
- package/dist/dev.d.ts +25 -0
- package/dist/dev.js +145 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +20 -0
- package/dist/loader/svgr.d.ts +4 -0
- package/dist/loader/svgr.js +67 -0
- package/dist/loader/swc.d.ts +4 -0
- package/dist/loader/swc.js +79 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.d.ts +11 -0
- package/dist/plugins/ESBuildCSSMinifyPlugin.js +63 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.d.ts +10 -0
- package/dist/plugins/ParcelCSSMinifyPlugin.js +75 -0
- package/dist/plugins/ProgressPlugin.d.ts +15 -0
- package/dist/plugins/ProgressPlugin.js +44 -0
- package/dist/plugins/RuntimePublicPathPlugin.d.ts +4 -0
- package/dist/plugins/RuntimePublicPathPlugin.js +20 -0
- package/dist/plugins/_SamplePlugin.d.ts +9 -0
- package/dist/plugins/_SamplePlugin.js +14 -0
- package/dist/requireHook.d.ts +1 -0
- package/dist/requireHook.js +31 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +84 -0
- package/dist/server/server.d.ts +17 -0
- package/dist/server/server.js +202 -0
- package/dist/server/ws.d.ts +11 -0
- package/dist/server/ws.js +42 -0
- package/dist/swcPlugins/autoCSSModules.d.ts +13 -0
- package/dist/swcPlugins/autoCSSModules.js +34 -0
- package/dist/swcPlugins/changeImportFromString.d.ts +2 -0
- package/dist/swcPlugins/changeImportFromString.js +10 -0
- package/dist/swcPlugins/lockCoreJS.d.ts +6 -0
- package/dist/swcPlugins/lockCoreJS.js +24 -0
- package/dist/types.d.ts +119 -0
- package/dist/types.js +30 -0
- package/dist/utils/browsersList.d.ts +5 -0
- package/dist/utils/browsersList.js +10 -0
- package/dist/utils/depMatch.d.ts +6 -0
- package/dist/utils/depMatch.js +46 -0
- package/dist/utils/formatWebpackMessages.d.ts +12 -0
- package/dist/utils/formatWebpackMessages.js +100 -0
- package/dist/utils/getEsBuildTarget.d.ts +5 -0
- package/dist/utils/getEsBuildTarget.js +12 -0
- package/package.json +5 -5
package/dist/build.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import webpack from '../compiled/webpack';
|
|
2
|
+
import { IOpts as IConfigOpts } from './config/config';
|
|
3
|
+
import { IConfig } from './types';
|
|
4
|
+
declare type IOpts = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
rootDir?: string;
|
|
7
|
+
entry: Record<string, string>;
|
|
8
|
+
config: IConfig;
|
|
9
|
+
onBuildComplete?: Function;
|
|
10
|
+
babelPreset?: any;
|
|
11
|
+
chainWebpack?: Function;
|
|
12
|
+
modifyWebpackConfig?: Function;
|
|
13
|
+
beforeBabelPlugins?: any[];
|
|
14
|
+
beforeBabelPresets?: any[];
|
|
15
|
+
extraBabelPlugins?: any[];
|
|
16
|
+
extraBabelPresets?: any[];
|
|
17
|
+
clean?: boolean;
|
|
18
|
+
} & Pick<IConfigOpts, 'cache'>;
|
|
19
|
+
export declare function build(opts: IOpts): Promise<webpack.Stats>;
|
|
20
|
+
export {};
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
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.build = void 0;
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
17
|
+
const webpack_1 = __importDefault(require("../compiled/webpack"));
|
|
18
|
+
const config_1 = require("./config/config");
|
|
19
|
+
const types_1 = require("./types");
|
|
20
|
+
function build(opts) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const webpackConfig = yield (0, config_1.getConfig)({
|
|
23
|
+
cwd: opts.cwd,
|
|
24
|
+
rootDir: opts.rootDir,
|
|
25
|
+
env: types_1.Env.production,
|
|
26
|
+
entry: opts.entry,
|
|
27
|
+
userConfig: opts.config,
|
|
28
|
+
analyze: process.env.ANALYZE,
|
|
29
|
+
babelPreset: opts.babelPreset,
|
|
30
|
+
extraBabelPlugins: [
|
|
31
|
+
...(opts.beforeBabelPlugins || []),
|
|
32
|
+
...(opts.extraBabelPlugins || []),
|
|
33
|
+
],
|
|
34
|
+
extraBabelPresets: [
|
|
35
|
+
...(opts.beforeBabelPresets || []),
|
|
36
|
+
...(opts.extraBabelPresets || []),
|
|
37
|
+
],
|
|
38
|
+
extraBabelIncludes: opts.config.extraBabelIncludes,
|
|
39
|
+
chainWebpack: opts.chainWebpack,
|
|
40
|
+
modifyWebpackConfig: opts.modifyWebpackConfig,
|
|
41
|
+
cache: opts.cache,
|
|
42
|
+
});
|
|
43
|
+
let isFirstCompile = true;
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
utils_1.rimraf.sync(webpackConfig.output.path);
|
|
46
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
47
|
+
compiler.run((err, stats) => {
|
|
48
|
+
var _a;
|
|
49
|
+
(_a = opts.onBuildComplete) === null || _a === void 0 ? void 0 : _a.call(opts, {
|
|
50
|
+
err,
|
|
51
|
+
stats,
|
|
52
|
+
isFirstCompile,
|
|
53
|
+
time: stats ? stats.endTime - stats.startTime : null,
|
|
54
|
+
});
|
|
55
|
+
isFirstCompile = false;
|
|
56
|
+
if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
|
|
57
|
+
if (err) {
|
|
58
|
+
// console.error(err);
|
|
59
|
+
reject(err);
|
|
60
|
+
}
|
|
61
|
+
if (stats) {
|
|
62
|
+
const errorMsg = stats.toString('errors-only');
|
|
63
|
+
// console.error(errorMsg);
|
|
64
|
+
reject(new Error(errorMsg));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
resolve(stats);
|
|
69
|
+
}
|
|
70
|
+
compiler.close(() => { });
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.build = build;
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
16
|
+
const utils_1 = require("@umijs/utils");
|
|
17
|
+
const assert_1 = __importDefault(require("assert"));
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const build_1 = require("./build");
|
|
21
|
+
const dev_1 = require("./dev");
|
|
22
|
+
const args = (0, utils_1.yParser)(process.argv.slice(2), {});
|
|
23
|
+
const command = args._[0];
|
|
24
|
+
const cwd = process.cwd();
|
|
25
|
+
const entry = (0, utils_1.tryPaths)([
|
|
26
|
+
(0, path_1.join)(cwd, 'src/index.tsx'),
|
|
27
|
+
(0, path_1.join)(cwd, 'src/index.ts'),
|
|
28
|
+
(0, path_1.join)(cwd, 'index.tsx'),
|
|
29
|
+
(0, path_1.join)(cwd, 'index.ts'),
|
|
30
|
+
]);
|
|
31
|
+
let config = {};
|
|
32
|
+
const configFile = (0, path_1.join)(cwd, args.config || 'config.ts');
|
|
33
|
+
utils_1.register.register({
|
|
34
|
+
implementor: esbuild_1.default,
|
|
35
|
+
});
|
|
36
|
+
utils_1.register.clearFiles();
|
|
37
|
+
if ((0, fs_1.existsSync)(configFile)) {
|
|
38
|
+
require('./requireHook');
|
|
39
|
+
config = require(configFile).default;
|
|
40
|
+
}
|
|
41
|
+
Object.assign(config, args);
|
|
42
|
+
if (command === 'build') {
|
|
43
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
process.env.NODE_ENV = 'production';
|
|
45
|
+
(0, assert_1.default)(entry, `Build failed: entry not found.`);
|
|
46
|
+
try {
|
|
47
|
+
yield (0, build_1.build)({
|
|
48
|
+
config,
|
|
49
|
+
cwd,
|
|
50
|
+
entry: {
|
|
51
|
+
[getEntryKey(entry)]: entry,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error(e);
|
|
57
|
+
}
|
|
58
|
+
}))();
|
|
59
|
+
}
|
|
60
|
+
else if (command === 'dev') {
|
|
61
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
process.env.NODE_ENV = 'development';
|
|
63
|
+
try {
|
|
64
|
+
(0, assert_1.default)(entry, `Build failed: entry not found.`);
|
|
65
|
+
yield (0, dev_1.dev)({
|
|
66
|
+
config,
|
|
67
|
+
cwd,
|
|
68
|
+
port: process.env.PORT,
|
|
69
|
+
entry: {
|
|
70
|
+
[getEntryKey(entry)]: entry,
|
|
71
|
+
},
|
|
72
|
+
cache: {
|
|
73
|
+
buildDependencies: [].filter(Boolean),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
console.error(e);
|
|
79
|
+
}
|
|
80
|
+
}))();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
error(`Unsupported command ${command}.`);
|
|
84
|
+
}
|
|
85
|
+
function error(msg) {
|
|
86
|
+
console.error(utils_1.chalk.red(msg));
|
|
87
|
+
}
|
|
88
|
+
function getEntryKey(path) {
|
|
89
|
+
return (0, path_1.basename)(path, (0, path_1.extname)(path));
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const strip_ansi_1 = __importDefault(require("@umijs/utils/compiled/strip-ansi"));
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const ErrorOverlay = __importStar(require("react-error-overlay"));
|
|
41
|
+
const constants_1 = require("../constants");
|
|
42
|
+
const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
|
|
43
|
+
console.log('[webpack] connecting...');
|
|
44
|
+
function getHost() {
|
|
45
|
+
if (process.env.SOCKET_SERVER) {
|
|
46
|
+
return new URL(process.env.SOCKET_SERVER);
|
|
47
|
+
}
|
|
48
|
+
return location;
|
|
49
|
+
}
|
|
50
|
+
function getSocketUrl() {
|
|
51
|
+
let h = getHost();
|
|
52
|
+
const host = h.host;
|
|
53
|
+
const isHttps = h.protocol === 'https:';
|
|
54
|
+
return `${isHttps ? 'wss' : 'ws'}://${host}`;
|
|
55
|
+
}
|
|
56
|
+
function getPingUrl() {
|
|
57
|
+
const h = getHost();
|
|
58
|
+
return `${h.protocol}//${h.host}/__umi_ping`;
|
|
59
|
+
}
|
|
60
|
+
let pingTimer = null;
|
|
61
|
+
let isFirstCompilation = true;
|
|
62
|
+
let mostRecentCompilationHash = null;
|
|
63
|
+
let hasCompileErrors = false;
|
|
64
|
+
let hadRuntimeError = false;
|
|
65
|
+
const pingUrl = getPingUrl();
|
|
66
|
+
const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
|
|
67
|
+
socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
data = JSON.parse(data);
|
|
69
|
+
if (data.type === 'connected') {
|
|
70
|
+
console.log(`[webpack] connected.`);
|
|
71
|
+
// proxy(nginx, docker) hmr ws maybe caused timeout,
|
|
72
|
+
// so send ping package let ws keep alive.
|
|
73
|
+
pingTimer = setInterval(() => socket.send('ping'), 30000);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
handleMessage(data).catch(console.error);
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
function waitForSuccessfulPing(ms = 1000) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
// eslint-disable-next-line no-constant-condition
|
|
82
|
+
while (true) {
|
|
83
|
+
try {
|
|
84
|
+
yield fetch(pingUrl);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
yield new Promise((resolve) => setTimeout(resolve, ms));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
socket.addEventListener('close', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
if (pingTimer)
|
|
95
|
+
clearInterval(pingTimer);
|
|
96
|
+
console.info('[webpack] Dev server disconnected. Polling for restart...');
|
|
97
|
+
yield waitForSuccessfulPing();
|
|
98
|
+
location.reload();
|
|
99
|
+
}));
|
|
100
|
+
ErrorOverlay.startReportingRuntimeErrors({
|
|
101
|
+
onError: function () {
|
|
102
|
+
hadRuntimeError = true;
|
|
103
|
+
},
|
|
104
|
+
filename: '/static/js/bundle.js',
|
|
105
|
+
});
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
if (module.hot && typeof module.hot.dispose === 'function') {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
module.hot.dispose(function () {
|
|
110
|
+
// TODO: why do we need this?
|
|
111
|
+
ErrorOverlay.stopReportingRuntimeErrors();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// There is a newer version of the code available.
|
|
115
|
+
function handleAvailableHash(hash) {
|
|
116
|
+
// Update last known compilation hash.
|
|
117
|
+
mostRecentCompilationHash = hash;
|
|
118
|
+
}
|
|
119
|
+
function handleSuccess() {
|
|
120
|
+
const isHotUpdate = !isFirstCompilation;
|
|
121
|
+
isFirstCompilation = false;
|
|
122
|
+
hasCompileErrors = false;
|
|
123
|
+
// Attempt to apply hot updates or reload.
|
|
124
|
+
if (isHotUpdate) {
|
|
125
|
+
tryApplyUpdates(function onHotUpdateSuccess() {
|
|
126
|
+
// Only dismiss it when we're sure it's a hot update.
|
|
127
|
+
// Otherwise it would flicker right before the reload.
|
|
128
|
+
tryDismissErrorOverlay();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function handleWarnings(warnings) {
|
|
133
|
+
const isHotUpdate = !isFirstCompilation;
|
|
134
|
+
isFirstCompilation = false;
|
|
135
|
+
hasCompileErrors = false;
|
|
136
|
+
const formatted = (0, formatWebpackMessages_1.formatWebpackMessages)({
|
|
137
|
+
warnings,
|
|
138
|
+
errors: [],
|
|
139
|
+
});
|
|
140
|
+
// print warnings
|
|
141
|
+
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
142
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
143
|
+
if (i === 5) {
|
|
144
|
+
console.warn('There were more warnings in other files.\n' +
|
|
145
|
+
'You can find a complete log in the terminal.');
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
console.warn((0, strip_ansi_1.default)(formatted.warnings[i]));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Attempt to apply hot updates or reload.
|
|
152
|
+
if (isHotUpdate) {
|
|
153
|
+
tryApplyUpdates(function onSuccessfulHotUpdate() {
|
|
154
|
+
// Only dismiss it when we're sure it's a hot update.
|
|
155
|
+
// Otherwise it would flicker right before the reload.
|
|
156
|
+
tryDismissErrorOverlay();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function handleErrors(errors) {
|
|
161
|
+
isFirstCompilation = false;
|
|
162
|
+
hasCompileErrors = true;
|
|
163
|
+
const formatted = (0, formatWebpackMessages_1.formatWebpackMessages)({
|
|
164
|
+
warnings: [],
|
|
165
|
+
errors,
|
|
166
|
+
});
|
|
167
|
+
// Only show the first error.
|
|
168
|
+
ErrorOverlay.reportBuildError(formatted.errors[0]);
|
|
169
|
+
// Also log them to the console.
|
|
170
|
+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
171
|
+
for (let i = 0; i < formatted.errors.length; i++) {
|
|
172
|
+
console.error((0, strip_ansi_1.default)(formatted.errors[i]));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function tryDismissErrorOverlay() {
|
|
177
|
+
if (!hasCompileErrors) {
|
|
178
|
+
ErrorOverlay.dismissBuildError();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Is there a newer version of this code available?
|
|
182
|
+
function isUpdateAvailable() {
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
return mostRecentCompilationHash !== __webpack_hash__;
|
|
185
|
+
}
|
|
186
|
+
function canApplyUpdates() {
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
return module.hot.status() === 'idle';
|
|
189
|
+
}
|
|
190
|
+
function canAcceptErrors() {
|
|
191
|
+
// NOTE: This var is injected by Webpack's DefinePlugin, and is a boolean instead of string.
|
|
192
|
+
const hasReactRefresh = process.env.FAST_REFRESH;
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
const status = module.hot.status();
|
|
195
|
+
// React refresh can handle hot-reloading over errors.
|
|
196
|
+
// However, when hot-reload status is abort or fail,
|
|
197
|
+
// it indicates the current update cannot be applied safely,
|
|
198
|
+
// and thus we should bail out to a forced reload for consistency.
|
|
199
|
+
return hasReactRefresh && ['abort', 'fail'].indexOf(status) === -1;
|
|
200
|
+
}
|
|
201
|
+
function tryApplyUpdates(onHotUpdateSuccess) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
if (!module.hot) {
|
|
204
|
+
window.location.reload();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
211
|
+
const haveErrors = err || hadRuntimeError;
|
|
212
|
+
// When there is no error but updatedModules is unavailable,
|
|
213
|
+
// it indicates a critical failure in hot-reloading,
|
|
214
|
+
// e.g. server is not ready to serve new bundle,
|
|
215
|
+
// and hence we need to do a forced reload.
|
|
216
|
+
const needsForcedReload = !err && !updatedModules;
|
|
217
|
+
if ((haveErrors && !canAcceptErrors()) || needsForcedReload) {
|
|
218
|
+
window.location.reload();
|
|
219
|
+
}
|
|
220
|
+
if (onHotUpdateSuccess)
|
|
221
|
+
onHotUpdateSuccess();
|
|
222
|
+
// While we were updating, there was a new update! Do it again.
|
|
223
|
+
if (isUpdateAvailable()) {
|
|
224
|
+
tryApplyUpdates();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
module.hot
|
|
229
|
+
.check(/* autoApply */ true)
|
|
230
|
+
.then((updatedModules) => {
|
|
231
|
+
handleApplyUpdates(null, updatedModules);
|
|
232
|
+
})
|
|
233
|
+
.catch((err) => {
|
|
234
|
+
handleApplyUpdates(err, null);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function handleMessage(payload) {
|
|
238
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
// console.log('[payload]', payload);
|
|
240
|
+
switch (payload.type) {
|
|
241
|
+
case constants_1.MESSAGE_TYPE.hash:
|
|
242
|
+
handleAvailableHash(payload.data);
|
|
243
|
+
break;
|
|
244
|
+
case constants_1.MESSAGE_TYPE.stillOk:
|
|
245
|
+
case constants_1.MESSAGE_TYPE.ok:
|
|
246
|
+
handleSuccess();
|
|
247
|
+
break;
|
|
248
|
+
case constants_1.MESSAGE_TYPE.errors:
|
|
249
|
+
handleErrors(payload.data);
|
|
250
|
+
break;
|
|
251
|
+
case constants_1.MESSAGE_TYPE.warnings:
|
|
252
|
+
handleWarnings(payload.data);
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
// Do nothing
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
config: Config;
|
|
5
|
+
userConfig: IConfig;
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: Env;
|
|
8
|
+
}
|
|
9
|
+
export declare function addSampleFeature(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
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.addSampleFeature = void 0;
|
|
13
|
+
function addSampleFeature(opts) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { config, userConfig, cwd, env } = opts;
|
|
16
|
+
config;
|
|
17
|
+
userConfig;
|
|
18
|
+
cwd;
|
|
19
|
+
env;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
exports.addSampleFeature = addSampleFeature;
|
|
@@ -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
|
+
config: Config;
|
|
5
|
+
userConfig: IConfig;
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: Env;
|
|
8
|
+
staticPathPrefix: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function addAssetRules(opts: IOpts): Promise<void>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
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.addAssetRules = void 0;
|
|
13
|
+
function addAssetRules(opts) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { config, userConfig } = opts;
|
|
16
|
+
const inlineLimit = parseInt(userConfig.inlineLimit || '10000', 10);
|
|
17
|
+
const rule = config.module.rule('asset');
|
|
18
|
+
rule
|
|
19
|
+
.oneOf('avif')
|
|
20
|
+
.test(/\.avif$/)
|
|
21
|
+
.type('asset')
|
|
22
|
+
.mimetype('image/avif')
|
|
23
|
+
.parser({
|
|
24
|
+
dataUrlCondition: {
|
|
25
|
+
maxSize: inlineLimit,
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
.generator({
|
|
29
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
30
|
+
});
|
|
31
|
+
rule
|
|
32
|
+
.oneOf('image')
|
|
33
|
+
.test(/\.(bmp|gif|jpg|jpeg|png)$/)
|
|
34
|
+
.type('asset')
|
|
35
|
+
.parser({
|
|
36
|
+
dataUrlCondition: {
|
|
37
|
+
maxSize: inlineLimit,
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
.generator({
|
|
41
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
42
|
+
});
|
|
43
|
+
const fallback = rule
|
|
44
|
+
.oneOf('fallback')
|
|
45
|
+
.exclude.add(/^$/) /* handle data: resources */
|
|
46
|
+
.add(/\.(js|mjs|jsx|ts|tsx)$/)
|
|
47
|
+
.add(/\.(css|less|sass|scss|stylus)$/)
|
|
48
|
+
.add(/\.html$/)
|
|
49
|
+
.add(/\.json$/);
|
|
50
|
+
if (userConfig.mdx) {
|
|
51
|
+
fallback.add(/\.mdx?$/);
|
|
52
|
+
}
|
|
53
|
+
fallback
|
|
54
|
+
.end()
|
|
55
|
+
.type('asset/resource')
|
|
56
|
+
.generator({
|
|
57
|
+
filename: `${opts.staticPathPrefix}[name].[hash:8].[ext]`,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.addAssetRules = addAssetRules;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
config: Config;
|
|
5
|
+
userConfig: IConfig;
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: Env;
|
|
8
|
+
}
|
|
9
|
+
export declare function addBundleAnalyzerPlugin(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
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.addBundleAnalyzerPlugin = void 0;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
const webpack_bundle_analyzer_1 = require("@umijs/bundler-webpack/compiled/webpack-bundle-analyzer");
|
|
15
|
+
function addBundleAnalyzerPlugin(opts) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const { config } = opts;
|
|
18
|
+
config.plugin('webpack-bundle-analyzer').use(webpack_bundle_analyzer_1.BundleAnalyzerPlugin, [
|
|
19
|
+
// https://github.com/webpack-contrib/webpack-bundle-analyzer
|
|
20
|
+
{
|
|
21
|
+
analyzerMode: 'server',
|
|
22
|
+
analyzerPort: process.env.ANALYZE_PORT || 8888,
|
|
23
|
+
openAnalyzer: false,
|
|
24
|
+
logLevel: 'info',
|
|
25
|
+
defaultSizes: 'parsed',
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
exports.addBundleAnalyzerPlugin = addBundleAnalyzerPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Config from '../../compiled/webpack-5-chain';
|
|
2
|
+
import { Env, IConfig } from '../types';
|
|
3
|
+
interface IOpts {
|
|
4
|
+
config: Config;
|
|
5
|
+
userConfig: IConfig;
|
|
6
|
+
cwd: string;
|
|
7
|
+
env: Env;
|
|
8
|
+
}
|
|
9
|
+
export declare function addCompressPlugin(opts: IOpts): Promise<void>;
|
|
10
|
+
export {};
|