@umijs/preset-umi 4.0.13 → 4.0.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.
@@ -117,12 +117,16 @@ umi build --clean
117
117
  args
118
118
  });
119
119
  };
120
+ const entry = await api.applyPlugins({
121
+ key: "modifyEntry",
122
+ initialValue: {
123
+ umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
124
+ }
125
+ });
120
126
  const opts = __spreadProps(__spreadValues({
121
127
  config: api.config,
122
128
  cwd: api.cwd,
123
- entry: {
124
- umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
125
- }
129
+ entry
126
130
  }, api.config.vite ? { modifyViteConfig } : { babelPreset, chainWebpack, modifyWebpackConfig }), {
127
131
  beforeBabelPlugins,
128
132
  beforeBabelPresets,
@@ -143,20 +147,22 @@ umi build --clean
143
147
  } else {
144
148
  stats = await bundlerWebpack.build(opts);
145
149
  }
146
- const assetsMap = api.config.vite ? {} : (0, import_getAssetsMap.getAssetsMap)({
147
- stats,
148
- publicPath: api.config.publicPath
149
- });
150
- const { vite } = api.args;
151
- const markupArgs = await (0, import_getMarkupArgs.getMarkupArgs)({ api });
152
- const markup = await (0, import_server.getMarkup)(__spreadProps(__spreadValues({}, markupArgs), {
153
- styles: markupArgs.styles.concat(api.config.vite ? [] : assetsMap["umi.css"] || []),
154
- scripts: (api.config.vite ? [] : assetsMap["umi.js"] || []).concat(markupArgs.scripts),
155
- esmScript: !!opts.config.esm || vite,
156
- path: "/"
157
- }));
158
- (0, import_fs.writeFileSync)((0, import_path.join)(api.paths.absOutputPath, "index.html"), markup, "utf-8");
159
- import_utils.logger.event("Build index.html");
150
+ if (!api.config.mpa) {
151
+ const assetsMap = api.config.vite ? {} : (0, import_getAssetsMap.getAssetsMap)({
152
+ stats,
153
+ publicPath: api.config.publicPath
154
+ });
155
+ const { vite } = api.args;
156
+ const markupArgs = await (0, import_getMarkupArgs.getMarkupArgs)({ api });
157
+ const markup = await (0, import_server.getMarkup)(__spreadProps(__spreadValues({}, markupArgs), {
158
+ styles: markupArgs.styles.concat(api.config.vite ? [] : assetsMap["umi.css"] || []),
159
+ scripts: (api.config.vite ? [] : assetsMap["umi.js"] || []).concat(markupArgs.scripts),
160
+ esmScript: !!opts.config.esm || vite,
161
+ path: "/"
162
+ }));
163
+ (0, import_fs.writeFileSync)((0, import_path.join)(api.paths.absOutputPath, "index.html"), markup, "utf-8");
164
+ import_utils.logger.event("Build index.html");
165
+ }
160
166
  await api.applyPlugins({
161
167
  key: "onBuildHtmlComplete",
162
168
  args: opts
@@ -246,16 +246,21 @@ PORT=8888 umi dev
246
246
  srcCodeCache.unwatch();
247
247
  });
248
248
  }
249
+ const entry = await api.applyPlugins({
250
+ key: "modifyEntry",
251
+ initialValue: {
252
+ umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
253
+ }
254
+ });
249
255
  const opts = __spreadProps(__spreadValues({
250
256
  config: api.config,
251
257
  pkg: api.pkg,
252
258
  cwd: api.cwd,
253
259
  rootDir: process.cwd(),
254
- entry: {
255
- umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
256
- },
260
+ entry,
257
261
  port: api.appData.port,
258
- host: api.appData.host
262
+ host: api.appData.host,
263
+ ip: api.appData.ip
259
264
  }, enableVite ? { modifyViteConfig } : { babelPreset, chainWebpack, modifyWebpackConfig }), {
260
265
  beforeBabelPlugins,
261
266
  beforeBabelPresets,
@@ -265,7 +270,7 @@ PORT=8888 umi dev
265
270
  ...beforeMiddlewares
266
271
  ]),
267
272
  afterMiddlewares: enableVite ? [] : middlewares.concat([
268
- (0, import_createRouteMiddleware.createRouteMiddleware)({ api }),
273
+ ...api.config.mpa ? [] : [(0, import_createRouteMiddleware.createRouteMiddleware)({ api })],
269
274
  import_faviconMiddleware.faviconMiddleware
270
275
  ]),
271
276
  onDevCompileDone(opts2) {
@@ -296,6 +301,9 @@ PORT=8888 umi dev
296
301
  ...((_e = api.config.mfsu) == null ? void 0 : _e.include) || []
297
302
  ])
298
303
  });
304
+ if (api.config.mf) {
305
+ opts.mfsuServerBase = `${api.config.https ? "https" : "http"}://${api.appData.ip}:${api.appData.port}`;
306
+ }
299
307
  if (enableVite) {
300
308
  await bundlerVite.dev(opts);
301
309
  } else {
@@ -308,6 +316,7 @@ PORT=8888 umi dev
308
316
  port: parseInt(String(process.env.PORT || import_constants.DEFAULT_PORT), 10)
309
317
  });
310
318
  memo.host = process.env.HOST || import_constants.DEFAULT_HOST;
319
+ memo.ip = import_utils.address.ip();
311
320
  return memo;
312
321
  });
313
322
  api.registerMethod({
@@ -149,7 +149,7 @@ function parseMultipart(body, boundary) {
149
149
  function parseUrlEncoded(body) {
150
150
  return body.split("&").reduce((acc, cur) => {
151
151
  const [key, value] = cur.split("=");
152
- acc[key] = decodeURI(value);
152
+ acc[key] = decodeURIComponent(value);
153
153
  return acc;
154
154
  }, {});
155
155
  }
@@ -0,0 +1,3 @@
1
+ import type { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,132 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/features/legacy/legacy.ts
40
+ var legacy_exports = {};
41
+ __export(legacy_exports, {
42
+ default: () => legacy_default
43
+ });
44
+ module.exports = __toCommonJS(legacy_exports);
45
+ var import_types = require("@umijs/bundler-webpack/dist/types");
46
+ var import_utils = require("@umijs/utils");
47
+ var legacy_default = (api) => {
48
+ api.describe({
49
+ key: "legacy",
50
+ config: {
51
+ schema(Joi) {
52
+ return Joi.object({
53
+ buildOnly: Joi.boolean()
54
+ });
55
+ }
56
+ },
57
+ enableBy: api.EnableBy.config
58
+ });
59
+ api.modifyConfig({
60
+ stage: Number.MAX_SAFE_INTEGER,
61
+ fn: (memo) => {
62
+ const { userConfig } = api;
63
+ const { buildOnly = true } = api.config.legacy || userConfig.legacy || {};
64
+ if (api.env === import_types.Env.development) {
65
+ if (buildOnly) {
66
+ return memo;
67
+ }
68
+ memo.mfsu = false;
69
+ import_utils.logger.warn(`mfsu is not supported in ${import_utils.chalk.cyan("legacy")} mode, we automatically close mfsu`);
70
+ }
71
+ if (userConfig.srcTranspiler || userConfig.jsMinifier || userConfig.cssMinifier) {
72
+ import_utils.logger.fatal(`Manual configuration of ${[
73
+ "srcTranspiler",
74
+ "jsMinifier",
75
+ "cssMinifier"
76
+ ].map((i) => import_utils.chalk.yellow(i)).join(", ")} is not supported when ${import_utils.chalk.cyan("legacy")} build mode enabled.`);
77
+ throw new Error("Manual configuration of legacy mode is not supported.");
78
+ }
79
+ memo.srcTranspiler = import_types.Transpiler.babel;
80
+ memo.jsMinifier = import_types.JSMinifier.terser;
81
+ memo.cssMinifier = import_types.CSSMinifier.cssnano;
82
+ memo.targets = __spreadProps(__spreadValues({}, userConfig.targets), {
83
+ ie: 11
84
+ });
85
+ memo.extraBabelIncludes = [
86
+ ...memo.extraBabelIncludes || [],
87
+ /node_modules/
88
+ ];
89
+ import_utils.logger.ready(`${import_utils.chalk.cyan("legacy")} mode is enabled, we automatically modify the ${[
90
+ "srcTranspiler",
91
+ "jsMinifier",
92
+ "cssMinifier"
93
+ ].map((i) => import_utils.chalk.yellow(i)).join(", ")} to be compatible with IE 11`);
94
+ const originChainWebpack = userConfig.chainWebpack;
95
+ memo.chainWebpack = (memo2, ...args) => {
96
+ if (originChainWebpack) {
97
+ originChainWebpack(memo2, ...args);
98
+ }
99
+ useBabelTransformSvgr(memo2, api);
100
+ if (!import_utils.lodash.isEmpty(userConfig.externals)) {
101
+ const externalsAsString = JSON.stringify(userConfig.externals);
102
+ const externalsType = memo2.get("externalsType");
103
+ if (externalsAsString.includes("script ") || externalsType) {
104
+ import_utils.logger.warn(`Legacy browsers do not support ${import_utils.chalk.yellow("Top level await")}, ensure you are not using both ${import_utils.chalk.bold.red(`Top level sync import`)} and ${import_utils.chalk.bold.red("Async externalsType (e.g. script)")}`);
105
+ }
106
+ }
107
+ return memo2;
108
+ };
109
+ return memo;
110
+ }
111
+ });
112
+ };
113
+ function useBabelTransformSvgr(memo, api) {
114
+ memo.module.rule("svgr").use("babel-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/babel-loader")).options({
115
+ sourceType: "unambiguous",
116
+ babelrc: false,
117
+ cacheDirectory: false,
118
+ targets: api.config.targets,
119
+ presets: [
120
+ [
121
+ require.resolve("@umijs/babel-preset-umi"),
122
+ {
123
+ presetEnv: {},
124
+ presetReact: {},
125
+ presetTypeScript: {}
126
+ }
127
+ ]
128
+ ]
129
+ }).before("svgr-loader").end();
130
+ }
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {});
@@ -0,0 +1,4 @@
1
+ export declare function extractExports(opts: {
2
+ entry: string;
3
+ exportName: string;
4
+ }): Promise<Record<string, any>>;
@@ -0,0 +1,112 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/mpa/extractExports.ts
23
+ var extractExports_exports = {};
24
+ __export(extractExports_exports, {
25
+ extractExports: () => extractExports
26
+ });
27
+ module.exports = __toCommonJS(extractExports_exports);
28
+ var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
29
+ async function extractExports(opts) {
30
+ const res = await import_esbuild.default.build({
31
+ format: "cjs",
32
+ platform: "browser",
33
+ target: "esnext",
34
+ loader: {
35
+ ".aac": "text",
36
+ ".css": "text",
37
+ ".less": "text",
38
+ ".sass": "text",
39
+ ".scss": "text",
40
+ ".eot": "text",
41
+ ".flac": "text",
42
+ ".gif": "text",
43
+ ".ico": "text",
44
+ ".jpeg": "text",
45
+ ".jpg": "text",
46
+ ".js": "jsx",
47
+ ".jsx": "jsx",
48
+ ".json": "json",
49
+ ".md": "jsx",
50
+ ".mdx": "jsx",
51
+ ".mp3": "text",
52
+ ".mp4": "text",
53
+ ".ogg": "text",
54
+ ".otf": "text",
55
+ ".png": "text",
56
+ ".svg": "text",
57
+ ".ts": "ts",
58
+ ".tsx": "tsx",
59
+ ".ttf": "text",
60
+ ".wav": "text",
61
+ ".webm": "text",
62
+ ".webp": "text",
63
+ ".woff": "text",
64
+ ".woff2": "text"
65
+ },
66
+ bundle: true,
67
+ write: false,
68
+ entryPoints: [`${opts.entry}?entry`],
69
+ plugins: [
70
+ {
71
+ name: "virtual-entry",
72
+ setup(build) {
73
+ build.onResolve({ filter: /\?entry$/ }, (args) => {
74
+ return {
75
+ path: args.path.split("?")[0],
76
+ namespace: "entry"
77
+ };
78
+ });
79
+ build.onResolve({ filter: /^[@a-z0-9-_~]/ }, (args) => {
80
+ return {
81
+ path: args.path,
82
+ external: true,
83
+ sideEffects: false
84
+ };
85
+ });
86
+ build.onResolve({ filter: /^\// }, (args) => {
87
+ return {
88
+ path: args.path
89
+ };
90
+ });
91
+ build.onLoad({ filter: /.*/, namespace: "entry" }, (args) => {
92
+ return {
93
+ contents: `
94
+ import * as x from "${args.path}";
95
+ ret = x.${opts.exportName} || {};
96
+ `,
97
+ loader: "ts"
98
+ };
99
+ });
100
+ }
101
+ }
102
+ ]
103
+ });
104
+ let ret = {};
105
+ let code = res.outputFiles[0].text;
106
+ eval(`(() => { ${code}; })();`);
107
+ return ret;
108
+ }
109
+ // Annotate the CommonJS export names for ESM import in node:
110
+ 0 && (module.exports = {
111
+ extractExports
112
+ });
@@ -0,0 +1,3 @@
1
+ import { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,194 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // src/features/mpa/mpa.ts
40
+ var mpa_exports = {};
41
+ __export(mpa_exports, {
42
+ default: () => mpa_default
43
+ });
44
+ module.exports = __toCommonJS(mpa_exports);
45
+ var import_utils = require("@umijs/utils");
46
+ var import_assert = __toESM(require("assert"));
47
+ var import_fs = require("fs");
48
+ var import_html_webpack_plugin = __toESM(require("html-webpack-plugin"));
49
+ var import_path = require("path");
50
+ var import_extractExports = require("./extractExports");
51
+ var mpa_default = (api) => {
52
+ api.describe({
53
+ key: "mpa",
54
+ config: {
55
+ schema(Joi) {
56
+ return Joi.object({});
57
+ }
58
+ },
59
+ enableBy: api.EnableBy.config
60
+ });
61
+ api.onStart(() => {
62
+ import_utils.logger.warn(import_utils.chalk.yellow("[MPA] MPA Mode Enabled"));
63
+ });
64
+ api.modifyAppData(async (memo) => {
65
+ memo.mpa = {
66
+ entry: await collectEntryWithTimeCount(api.paths.absPagesPath)
67
+ };
68
+ return memo;
69
+ });
70
+ api.onGenerateFiles(async ({ isFirstTime }) => {
71
+ if (!isFirstTime) {
72
+ api.appData.mpa.entry = await collectEntryWithTimeCount(api.paths.absPagesPath);
73
+ }
74
+ const isReact18 = api.appData.react.version.startsWith("18.");
75
+ api.appData.mpa.entry.forEach((entry) => {
76
+ const layoutImport = entry.layout ? `import Layout from '${entry.layout}';` : "";
77
+ const layoutJSX = entry.layout ? `<Layout><App /></Layout>` : `<App />`;
78
+ const rootElement = `document.getElementById('${entry.mountElementId}')`;
79
+ const renderer = isReact18 ? `ReactDOM.createRoot(${rootElement}).render(${layoutJSX});` : `ReactDOM.render(${layoutJSX}, ${rootElement});`;
80
+ const reactDOMSource = isReact18 ? "react-dom/client" : "react-dom";
81
+ api.writeTmpFile({
82
+ path: entry.tmpFilePath,
83
+ noPluginDir: true,
84
+ content: `
85
+ import React from 'react';
86
+ import ReactDOM from '${reactDOMSource}';
87
+ import App from '${entry.file}';
88
+ ${layoutImport}
89
+ ${renderer}
90
+ `.trimStart()
91
+ });
92
+ });
93
+ api.writeTmpFile({
94
+ path: "mpa/template.html",
95
+ noPluginDir: true,
96
+ content: `
97
+ <!DOCTYPE html>
98
+ <html>
99
+ <head><title><%= title %></title></head>
100
+ <body>
101
+ <div id="<%= mountElementId %>"></div>
102
+ </body>
103
+ </html>
104
+ `.trimStart()
105
+ });
106
+ });
107
+ api.modifyEntry((memo) => {
108
+ if ("umi" in memo)
109
+ delete memo["umi"];
110
+ api.appData.mpa.entry.forEach((entry) => {
111
+ memo[entry.name] = (0, import_path.join)(api.paths.absTmpPath, entry.tmpFilePath);
112
+ });
113
+ return memo;
114
+ });
115
+ api.chainWebpack((memo) => {
116
+ api.appData.mpa.entry.forEach((entry) => {
117
+ memo.plugin(`html-${entry.name}`).use(import_html_webpack_plugin.default, [
118
+ {
119
+ filename: `${entry.name}.html`,
120
+ minify: false,
121
+ template: entry.template ? (0, import_path.resolve)(api.cwd, entry.template) : (0, import_path.join)(api.paths.absTmpPath, "mpa/template.html"),
122
+ templateParameters: entry,
123
+ chunks: [entry.name]
124
+ }
125
+ ]);
126
+ });
127
+ return memo;
128
+ });
129
+ };
130
+ async function collectEntryWithTimeCount(root) {
131
+ const d = new Date();
132
+ const entries = await collectEntry(root);
133
+ import_utils.logger.info(`[MPA] Collect Entries in ${new Date().getTime() - d.getTime()}ms`);
134
+ return entries;
135
+ }
136
+ async function collectEntry(root) {
137
+ return await (0, import_fs.readdirSync)(root).reduce(async (memoP, dir) => {
138
+ const memo = await memoP;
139
+ const absDir = (0, import_path.join)(root, dir);
140
+ if ((0, import_fs.existsSync)(absDir) && (0, import_fs.statSync)(absDir).isDirectory()) {
141
+ const indexFile = getIndexFile(absDir);
142
+ if (indexFile) {
143
+ const config = await getConfig(indexFile);
144
+ memo.push(__spreadProps(__spreadValues({
145
+ name: dir,
146
+ file: indexFile,
147
+ tmpFilePath: `mpa/${dir}${(0, import_path.extname)(indexFile)}`,
148
+ mountElementId: "root"
149
+ }, config), {
150
+ title: config.title || dir
151
+ }));
152
+ }
153
+ }
154
+ return memo;
155
+ }, Promise.resolve([]));
156
+ }
157
+ function getIndexFile(dir) {
158
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.tsx")))
159
+ return (0, import_path.join)(dir, "index.tsx");
160
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.ts")))
161
+ return (0, import_path.join)(dir, "index.ts");
162
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.jsx")))
163
+ return (0, import_path.join)(dir, "index.jsx");
164
+ if ((0, import_fs.existsSync)((0, import_path.join)(dir, "index.js")))
165
+ return (0, import_path.join)(dir, "index.js");
166
+ return null;
167
+ }
168
+ async function getConfig(indexFile) {
169
+ const config = await (0, import_extractExports.extractExports)({
170
+ entry: indexFile,
171
+ exportName: "config"
172
+ });
173
+ checkConfig(config);
174
+ return config;
175
+ }
176
+ function checkConfig(config) {
177
+ if (config.layout) {
178
+ (0, import_assert.default)(typeof config.layout === "string" && (config.layout.startsWith("@/") || config.layout.startsWith("/")), `layout must be an absolute path or start with '@/'`);
179
+ }
180
+ if (config.template) {
181
+ (0, import_assert.default)(typeof config.template === "string", "template must be string");
182
+ }
183
+ if (config.title) {
184
+ (0, import_assert.default)(typeof config.title === "string", "title must be string");
185
+ }
186
+ if (config.head) {
187
+ (0, import_assert.default)(Array.isArray(config.head), "head must be string");
188
+ }
189
+ if (config.scripts) {
190
+ (0, import_assert.default)(Array.isArray(config.scripts), "scripts must be string");
191
+ }
192
+ }
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {});
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ var src_default = () => {
39
39
  require.resolve("./features/esmi/esmi"),
40
40
  require.resolve("./features/favicons/favicons"),
41
41
  require.resolve("./features/mock/mock"),
42
+ require.resolve("./features/mpa/mpa"),
42
43
  require.resolve("./features/polyfill/polyfill"),
43
44
  require.resolve("./features/polyfill/publicPathPolyfill"),
44
45
  require.resolve("./features/routePrefetch/routePrefetch"),
@@ -52,6 +53,7 @@ var src_default = () => {
52
53
  require.resolve("./features/apiRoute/apiRoute"),
53
54
  require.resolve("./features/monorepo/redirect"),
54
55
  require.resolve("./features/clickToComponent/clickToComponent"),
56
+ require.resolve("./features/legacy/legacy"),
55
57
  require.resolve("./commands/build"),
56
58
  require.resolve("./commands/config/config"),
57
59
  require.resolve("./commands/dev/dev"),
@@ -71,7 +73,8 @@ var src_default = () => {
71
73
  require.resolve("./commands/generators/api"),
72
74
  require.resolve("./commands/plugin"),
73
75
  require.resolve("./commands/verify-commit"),
74
- require.resolve("./commands/preview")
76
+ require.resolve("./commands/preview"),
77
+ require.resolve("@umijs/plugin-run")
75
78
  ]
76
79
  };
77
80
  };
@@ -66,6 +66,7 @@ var registerMethods_default = (api) => {
66
66
  "addHTMLScripts",
67
67
  "addTmpGenerateWatcherPaths",
68
68
  "chainWebpack",
69
+ "modifyEntry",
69
70
  "modifyHTMLFavicon",
70
71
  "modifyHTML",
71
72
  "modifyWebpackConfig",
package/dist/types.d.ts CHANGED
@@ -90,6 +90,7 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
90
90
  }): void;
91
91
  };
92
92
  modifyBabelPresetOpts: IModify<any, null>;
93
+ modifyEntry: IModify<Record<string, string>, null>;
93
94
  modifyHTML: IModify<CheerioAPI, {
94
95
  path: string;
95
96
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.13",
3
+ "version": "4.0.14",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -26,20 +26,22 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@types/multer": "1.4.7",
29
- "@umijs/ast": "4.0.13",
30
- "@umijs/babel-preset-umi": "4.0.13",
31
- "@umijs/bundler-utils": "4.0.13",
32
- "@umijs/bundler-vite": "4.0.13",
33
- "@umijs/bundler-webpack": "4.0.13",
34
- "@umijs/core": "4.0.13",
35
- "@umijs/renderer-react": "4.0.13",
36
- "@umijs/server": "4.0.13",
37
- "@umijs/utils": "4.0.13",
29
+ "@umijs/ast": "4.0.14",
30
+ "@umijs/babel-preset-umi": "4.0.14",
31
+ "@umijs/bundler-utils": "4.0.14",
32
+ "@umijs/bundler-vite": "4.0.14",
33
+ "@umijs/bundler-webpack": "4.0.14",
34
+ "@umijs/core": "4.0.14",
35
+ "@umijs/plugin-run": "4.0.14",
36
+ "@umijs/renderer-react": "4.0.14",
37
+ "@umijs/server": "4.0.14",
38
+ "@umijs/utils": "4.0.14",
38
39
  "click-to-react-component": "^1.0.8",
39
40
  "core-js": "3.22.4",
40
41
  "current-script-polyfill": "1.0.0",
41
42
  "enhanced-resolve": "5.9.3",
42
43
  "fast-glob": "^3.2.11",
44
+ "html-webpack-plugin": "5.5.0",
43
45
  "magic-string": "0.26.2",
44
46
  "path-to-regexp": "1.7.0",
45
47
  "react": "18.1.0",