@umijs/preset-umi 4.2.4 → 4.2.6-alpha.0
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/commands/build.js +12 -11
- package/dist/commands/dev/createRouteMiddleware.js +3 -3
- package/dist/commands/dev/dev.js +11 -7
- package/dist/commands/dev/getBabelOpts.js +4 -1
- package/dist/features/appData/umiInfo.js +6 -4
- package/dist/features/configPlugins/configPlugins.js +2 -5
- package/dist/features/devTool/devTool.js +1 -1
- package/dist/features/esbuildHelperChecker/esbuildHelperChecker.d.ts +0 -1
- package/dist/features/esbuildHelperChecker/esbuildHelperChecker.js +17 -24
- package/dist/features/exportStatic/exportStatic.js +2 -20
- package/dist/features/mako/mako.js +14 -3
- package/dist/features/mpa/mpa.js +3 -3
- package/dist/features/okam/okam.js +1 -1
- package/dist/features/prepare/prepare.js +4 -5
- package/dist/features/ssr/mako/mako.d.ts +1 -0
- package/dist/features/ssr/mako/mako.js +90 -0
- package/dist/features/ssr/ssr.js +42 -2
- package/dist/features/ssr/utils.d.ts +1 -0
- package/dist/features/ssr/utils.js +15 -2
- package/dist/features/tmpFiles/routes.js +3 -7
- package/dist/features/tmpFiles/tmpFiles.js +61 -34
- package/dist/index.js +0 -1
- package/dist/types.d.ts +1 -0
- package/package.json +17 -18
- package/templates/history.tpl +0 -6
- package/templates/server.tpl +36 -17
- package/templates/umi.tpl +1 -0
- package/dist/features/forget/forget.d.ts +0 -3
- package/dist/features/forget/forget.js +0 -77
package/dist/commands/build.js
CHANGED
|
@@ -48,7 +48,7 @@ COMPRESS=none umi build
|
|
|
48
48
|
umi build --clean
|
|
49
49
|
`,
|
|
50
50
|
fn: async function() {
|
|
51
|
-
var _a;
|
|
51
|
+
var _a, _b;
|
|
52
52
|
import_utils.logger.info(import_utils.chalk.cyan.bold(`Umi v${api.appData.umi.version}`));
|
|
53
53
|
import_utils.rimraf.sync(api.paths.absTmpPath);
|
|
54
54
|
await api.applyPlugins({
|
|
@@ -105,15 +105,16 @@ umi build --clean
|
|
|
105
105
|
umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
const shouldUseAutomaticRuntime = ((_a = api.appData.react) == null ? void 0 : _a.version) &&
|
|
109
|
-
// it will break the config of externals, when externals
|
|
110
|
-
// does not handle the react/runtime
|
|
111
|
-
import_utils.semver.gte(api.appData.react.version, "17.0.0");
|
|
108
|
+
const shouldUseAutomaticRuntime = ((_a = api.appData.react) == null ? void 0 : _a.version) && import_utils.semver.gte(api.appData.react.version, "16.14.0");
|
|
112
109
|
const opts = {
|
|
113
110
|
react: {
|
|
114
111
|
runtime: shouldUseAutomaticRuntime ? "automatic" : "classic"
|
|
115
112
|
},
|
|
116
|
-
config:
|
|
113
|
+
config: {
|
|
114
|
+
outputPath: api.userConfig.outputPath || "dist",
|
|
115
|
+
...api.config,
|
|
116
|
+
hooks: ((_b = api.config.mako) == null ? void 0 : _b.hooks) || {}
|
|
117
|
+
},
|
|
117
118
|
cwd: api.cwd,
|
|
118
119
|
entry,
|
|
119
120
|
...api.config.vite ? { modifyViteConfig } : { babelPreset, chainWebpack, modifyWebpackConfig },
|
|
@@ -138,7 +139,7 @@ umi build --clean
|
|
|
138
139
|
let stats;
|
|
139
140
|
if (api.config.vite) {
|
|
140
141
|
stats = await bundlerVite.build(opts);
|
|
141
|
-
} else if (
|
|
142
|
+
} else if (api.config.mako) {
|
|
142
143
|
require("@umijs/bundler-webpack/dist/requireHook");
|
|
143
144
|
const { build } = require(process.env.OKAM);
|
|
144
145
|
stats = await build(opts);
|
|
@@ -164,13 +165,13 @@ umi build --clean
|
|
|
164
165
|
publicPath: api.config.publicPath
|
|
165
166
|
});
|
|
166
167
|
const { vite } = api.args;
|
|
167
|
-
const
|
|
168
|
+
const args = await (0, import_getMarkupArgs.getMarkupArgs)({ api });
|
|
168
169
|
const finalMarkUpArgs = {
|
|
169
|
-
...
|
|
170
|
-
styles:
|
|
170
|
+
...args,
|
|
171
|
+
styles: args.styles.concat(
|
|
171
172
|
api.config.vite ? [] : [...(assetsMap["umi.css"] || []).map((src) => ({ src }))]
|
|
172
173
|
),
|
|
173
|
-
scripts: (api.config.vite ? [] : [...(assetsMap["umi.js"] || []).map((src) => ({ src }))]).concat(
|
|
174
|
+
scripts: (api.config.vite ? [] : [...(assetsMap["umi.js"] || []).map((src) => ({ src }))]).concat(args.scripts),
|
|
174
175
|
esmScript: !!opts.config.esm || vite,
|
|
175
176
|
path: "/"
|
|
176
177
|
};
|
|
@@ -33,8 +33,8 @@ function createRouteMiddleware(opts) {
|
|
|
33
33
|
webpackStats = stats;
|
|
34
34
|
onStats == null ? void 0 : onStats(stats);
|
|
35
35
|
});
|
|
36
|
-
async function getStats() {
|
|
37
|
-
if (!compiler &&
|
|
36
|
+
async function getStats(api) {
|
|
37
|
+
if (!compiler && api.config.mako) {
|
|
38
38
|
return {
|
|
39
39
|
compilation: { assets: { "umi.js": "umi.js", "umi.css": "umi.css" } },
|
|
40
40
|
hasErrors: () => false
|
|
@@ -52,7 +52,7 @@ function createRouteMiddleware(opts) {
|
|
|
52
52
|
var _a;
|
|
53
53
|
const markupArgs = await (0, import_getMarkupArgs.getMarkupArgs)(opts);
|
|
54
54
|
let assetsMap = {};
|
|
55
|
-
const stats = await getStats();
|
|
55
|
+
const stats = await getStats(opts.api);
|
|
56
56
|
assetsMap = (0, import_getAssetsMap.getAssetsMap)({
|
|
57
57
|
stats,
|
|
58
58
|
publicPath: opts.api.config.publicPath
|
package/dist/commands/dev/dev.js
CHANGED
|
@@ -70,7 +70,7 @@ umi dev
|
|
|
70
70
|
PORT=8888 umi dev
|
|
71
71
|
`,
|
|
72
72
|
async fn() {
|
|
73
|
-
var _a, _b, _c, _d, _e, _f;
|
|
73
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
74
74
|
import_utils.logger.info(import_utils.chalk.cyan.bold(`Umi v${api.appData.umi.version}`));
|
|
75
75
|
const enableVite = !!api.config.vite;
|
|
76
76
|
import_utils.rimraf.sync(api.paths.absTmpPath);
|
|
@@ -309,12 +309,16 @@ PORT=8888 umi dev
|
|
|
309
309
|
umi: (0, import_path.join)(api.paths.absTmpPath, "umi.ts")
|
|
310
310
|
}
|
|
311
311
|
});
|
|
312
|
-
const shouldUseAutomaticRuntime = ((_c = api.appData.react) == null ? void 0 : _c.version) && import_utils.semver.gte(api.appData.react.version, "
|
|
312
|
+
const shouldUseAutomaticRuntime = ((_c = api.appData.react) == null ? void 0 : _c.version) && import_utils.semver.gte(api.appData.react.version, "16.14.0");
|
|
313
313
|
const opts = {
|
|
314
314
|
react: {
|
|
315
315
|
runtime: shouldUseAutomaticRuntime ? "automatic" : "classic"
|
|
316
316
|
},
|
|
317
|
-
config:
|
|
317
|
+
config: {
|
|
318
|
+
outputPath: api.userConfig.outputPath || "dist",
|
|
319
|
+
...api.config,
|
|
320
|
+
hooks: ((_d = api.config.mako) == null ? void 0 : _d.hooks) || {}
|
|
321
|
+
},
|
|
318
322
|
pkg: api.pkg,
|
|
319
323
|
cwd: api.cwd,
|
|
320
324
|
rootDir: process.cwd(),
|
|
@@ -354,8 +358,8 @@ PORT=8888 umi dev
|
|
|
354
358
|
...opts2
|
|
355
359
|
};
|
|
356
360
|
},
|
|
357
|
-
mfsuWithESBuild: (
|
|
358
|
-
mfsuStrategy: (
|
|
361
|
+
mfsuWithESBuild: (_e = api.config.mfsu) == null ? void 0 : _e.esbuild,
|
|
362
|
+
mfsuStrategy: (_f = api.config.mfsu) == null ? void 0 : _f.strategy,
|
|
359
363
|
cache: {
|
|
360
364
|
buildDependencies: [
|
|
361
365
|
api.pkgPath,
|
|
@@ -365,7 +369,7 @@ PORT=8888 umi dev
|
|
|
365
369
|
srcCodeCache,
|
|
366
370
|
mfsuInclude: import_utils.lodash.union([
|
|
367
371
|
...MFSU_EAGER_DEFAULT_INCLUDE,
|
|
368
|
-
...((
|
|
372
|
+
...((_g = api.config.mfsu) == null ? void 0 : _g.include) || []
|
|
369
373
|
]),
|
|
370
374
|
startBuildWorker,
|
|
371
375
|
onBeforeMiddleware(app) {
|
|
@@ -383,7 +387,7 @@ PORT=8888 umi dev
|
|
|
383
387
|
});
|
|
384
388
|
if (enableVite) {
|
|
385
389
|
await bundlerVite.dev(opts);
|
|
386
|
-
} else if (
|
|
390
|
+
} else if (api.config.mako) {
|
|
387
391
|
require("@umijs/bundler-webpack/dist/requireHook");
|
|
388
392
|
const { dev } = require(process.env.OKAM);
|
|
389
393
|
await dev(opts);
|
|
@@ -34,7 +34,10 @@ __export(getBabelOpts_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(getBabelOpts_exports);
|
|
35
35
|
var import_utils = require("@umijs/utils");
|
|
36
36
|
async function getBabelOpts(opts) {
|
|
37
|
-
const shouldUseAutomaticRuntime = import_utils.semver.gte(
|
|
37
|
+
const shouldUseAutomaticRuntime = import_utils.semver.gte(
|
|
38
|
+
opts.api.appData.react.version,
|
|
39
|
+
"16.14.0"
|
|
40
|
+
);
|
|
38
41
|
const babelPresetOpts = await opts.api.applyPlugins({
|
|
39
42
|
key: "modifyBabelPresetOpts",
|
|
40
43
|
initialValue: {
|
|
@@ -25,9 +25,11 @@ module.exports = __toCommonJS(umiInfo_exports);
|
|
|
25
25
|
var umiInfo_default = (api) => {
|
|
26
26
|
api.addEntryCode(() => [
|
|
27
27
|
`
|
|
28
|
-
window
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
window.g_umi = {
|
|
30
|
+
version: '${api.appData.umi.version}',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
`
|
|
32
34
|
]);
|
|
33
35
|
};
|
|
@@ -55,11 +55,8 @@ var configPlugins_default = (api) => {
|
|
|
55
55
|
cwd: api.cwd,
|
|
56
56
|
dep: "react-dom"
|
|
57
57
|
}) || (0, import_path.dirname)(require.resolve("react-dom/package.json"));
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
const majorVersion = parseInt(reactDOMVersion.split(".")[0], 10);
|
|
61
|
-
return majorVersion < 18;
|
|
62
|
-
})();
|
|
58
|
+
const reactDOMVersion = require((0, import_path.join)(reactDOMPath, "package.json")).version;
|
|
59
|
+
const isLT18 = !reactDOMVersion.startsWith("18.");
|
|
63
60
|
const configDefaults = {
|
|
64
61
|
alias: {
|
|
65
62
|
umi: "@@/exports",
|
|
@@ -29,7 +29,7 @@ var devToolAppDist = (0, import_path.join)(__dirname, "../../../devToolAppDist")
|
|
|
29
29
|
var assetsDir = (0, import_path.join)(__dirname, "../../../assets");
|
|
30
30
|
var devTool_default = (api) => {
|
|
31
31
|
api.addBeforeMiddlewares(async () => {
|
|
32
|
-
if (
|
|
32
|
+
if (api.config.mako)
|
|
33
33
|
return [];
|
|
34
34
|
const $ = await api.applyPlugins({
|
|
35
35
|
key: "modifyDevToolLoadingHTML",
|
|
@@ -47,8 +47,7 @@ async function checkDir(opts) {
|
|
|
47
47
|
const varMap = {};
|
|
48
48
|
for (const jsFile of jsFiles) {
|
|
49
49
|
const vars = await getGlobalVars({
|
|
50
|
-
content: import_fs.default.readFileSync(import_path.default.join(opts.dir, jsFile), "utf-8")
|
|
51
|
-
fileName: jsFile
|
|
50
|
+
content: import_fs.default.readFileSync(import_path.default.join(opts.dir, jsFile), "utf-8")
|
|
52
51
|
});
|
|
53
52
|
for (const v of vars) {
|
|
54
53
|
varMap[v] = varMap[v] || [];
|
|
@@ -70,29 +69,23 @@ async function checkDir(opts) {
|
|
|
70
69
|
import_utils.logger.info(`[esbuildHelperChecker] No conflicts found.`);
|
|
71
70
|
}
|
|
72
71
|
async function getGlobalVars(opts) {
|
|
72
|
+
const ast = parser.parse(opts.content, {
|
|
73
|
+
sourceType: "module",
|
|
74
|
+
sourceFilename: "foo.js",
|
|
75
|
+
plugins: []
|
|
76
|
+
});
|
|
73
77
|
const vars = [];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
ast.program.body.forEach((node) => {
|
|
81
|
-
if (t.isVariableDeclaration(node)) {
|
|
82
|
-
node.declarations.forEach((declaration) => {
|
|
83
|
-
if (t.isVariableDeclarator(declaration)) {
|
|
84
|
-
if (t.isIdentifier(declaration.id)) {
|
|
85
|
-
vars.push(declaration.id.name);
|
|
86
|
-
}
|
|
78
|
+
ast.program.body.forEach((node) => {
|
|
79
|
+
if (t.isVariableDeclaration(node)) {
|
|
80
|
+
node.declarations.forEach((declaration) => {
|
|
81
|
+
if (t.isVariableDeclarator(declaration)) {
|
|
82
|
+
if (t.isIdentifier(declaration.id)) {
|
|
83
|
+
vars.push(declaration.id.name);
|
|
87
84
|
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
import_utils.logger.error(
|
|
93
|
-
`[esbuildHelperChecker] Failed to parse ${opts.fileName}, ${error.message}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
96
89
|
return vars;
|
|
97
90
|
}
|
|
98
91
|
var esbuildHelperChecker_default = (api) => {
|
|
@@ -111,7 +104,7 @@ var esbuildHelperChecker_default = (api) => {
|
|
|
111
104
|
api.onBuildComplete(async ({ err }) => {
|
|
112
105
|
if (api.config.vite)
|
|
113
106
|
return;
|
|
114
|
-
if (
|
|
107
|
+
if (api.config.mako)
|
|
115
108
|
return;
|
|
116
109
|
if (err)
|
|
117
110
|
return;
|
|
@@ -64,23 +64,14 @@ function getExportHtmlData(routes) {
|
|
|
64
64
|
return Array.from(map.values());
|
|
65
65
|
}
|
|
66
66
|
async function getPreRenderedHTML(api, htmlTpl, path) {
|
|
67
|
-
var _a, _b;
|
|
68
67
|
const {
|
|
69
68
|
exportStatic: { ignorePreRenderError = false }
|
|
70
69
|
} = api.config;
|
|
71
70
|
markupRender ?? (markupRender = require((0, import_utils2.absServerBuildPath)(api))._markupGenerator);
|
|
72
71
|
try {
|
|
73
|
-
const
|
|
74
|
-
const [mainTpl, extraTpl = ""] = markup.split("</html>");
|
|
75
|
-
const helmetContent = (_a = mainTpl.match(
|
|
76
|
-
/<head>[^]*?(<[^>]+data-rh[^]+)<\/head>/
|
|
77
|
-
)) == null ? void 0 : _a[1];
|
|
78
|
-
const bodyContent = (_b = mainTpl.match(/<body[^>]*>([^]+?)<\/body>/)) == null ? void 0 : _b[1];
|
|
79
|
-
htmlTpl = htmlTpl.replace("</head>", `${helmetContent || ""}</head>`).replace(
|
|
80
|
-
new RegExp(`<div id="${api.config.mountElementId}"[^>]*>.*?</div>`),
|
|
81
|
-
bodyContent
|
|
82
|
-
).replace(/$/, `${extraTpl}`);
|
|
72
|
+
const html = await markupRender(path);
|
|
83
73
|
import_utils.logger.info(`Pre-render for ${path}`);
|
|
74
|
+
return html;
|
|
84
75
|
} catch (err) {
|
|
85
76
|
import_utils.logger.error(`Pre-render ${path} error: ${err}`);
|
|
86
77
|
if (!ignorePreRenderError) {
|
|
@@ -125,17 +116,8 @@ var exportStatic_default = (api) => {
|
|
|
125
116
|
const htmlData = api.appData.exportHtmlData;
|
|
126
117
|
const htmlFiles = [];
|
|
127
118
|
const { markupArgs: defaultMarkupArgs } = opts;
|
|
128
|
-
let asyncMarkupArgs;
|
|
129
119
|
for (const { file, route, prerender } of htmlData) {
|
|
130
120
|
let markupArgs = defaultMarkupArgs;
|
|
131
|
-
if (api.config.ssr && prerender) {
|
|
132
|
-
markupArgs = asyncMarkupArgs ?? (asyncMarkupArgs = {
|
|
133
|
-
...markupArgs,
|
|
134
|
-
scripts: markupArgs.scripts.map(
|
|
135
|
-
(script) => script.src ? { ...script, async: true } : script
|
|
136
|
-
)
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
121
|
if (publicPath.startsWith(".")) {
|
|
140
122
|
(0, import_assert.default)(
|
|
141
123
|
api.config.runtimePublicPath,
|
|
@@ -32,14 +32,19 @@ __export(mako_exports, {
|
|
|
32
32
|
default: () => mako_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(mako_exports);
|
|
35
|
-
var import_path = __toESM(require("path"));
|
|
36
35
|
var import_utils = require("@umijs/utils");
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
37
|
var mako_default = (api) => {
|
|
38
38
|
api.describe({
|
|
39
39
|
key: "mako",
|
|
40
40
|
config: {
|
|
41
41
|
schema({ zod }) {
|
|
42
|
-
return zod.object({
|
|
42
|
+
return zod.object({
|
|
43
|
+
hooks: zod.object({
|
|
44
|
+
load: zod.function(),
|
|
45
|
+
generateEnd: zod.function()
|
|
46
|
+
})
|
|
47
|
+
}).partial();
|
|
43
48
|
}
|
|
44
49
|
},
|
|
45
50
|
enableBy: api.EnableBy.config
|
|
@@ -61,7 +66,13 @@ var mako_default = (api) => {
|
|
|
61
66
|
api.logger.info(`Using mako@${pkg.version}`);
|
|
62
67
|
const isBigfish = process.env.BIGFISH_INFO;
|
|
63
68
|
if (!isBigfish) {
|
|
64
|
-
api.logger.warn(
|
|
69
|
+
api.logger.warn(
|
|
70
|
+
import_utils.chalk.yellow(
|
|
71
|
+
import_utils.chalk.bold(
|
|
72
|
+
`Mako is an extremely fast, production-grade web bundler based on Rust. And it's still under active development and is not yet ready for production use. If you encounter any issues, please checkout https://makojs.dev/ to join the community and report the issue.`
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
);
|
|
65
76
|
}
|
|
66
77
|
} catch (e) {
|
|
67
78
|
console.error(e);
|
package/dist/features/mpa/mpa.js
CHANGED
|
@@ -72,14 +72,14 @@ var mpa_default = (api) => {
|
|
|
72
72
|
api.userConfig.mountElementId
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const isReact18 = api.appData.react.version.startsWith("18.");
|
|
76
76
|
api.appData.mpa.entry.forEach((entry) => {
|
|
77
77
|
const layout = entry.layout || api.config.mpa.layout;
|
|
78
78
|
const layoutImport = layout ? `import Layout from '${layout}';` : "";
|
|
79
79
|
const layoutJSX = layout ? `<Layout><App /></Layout>` : `<App />`;
|
|
80
80
|
const rootElement = `document.getElementById('${entry.mountElementId}')`;
|
|
81
|
-
const renderer =
|
|
82
|
-
const reactDOMSource =
|
|
81
|
+
const renderer = isReact18 ? `ReactDOM.createRoot(${rootElement}).render(${layoutJSX});` : `ReactDOM.render(${layoutJSX}, ${rootElement});`;
|
|
82
|
+
const reactDOMSource = isReact18 ? "react-dom/client" : "react-dom";
|
|
83
83
|
api.writeTmpFile({
|
|
84
84
|
path: entry.tmpFilePath,
|
|
85
85
|
noPluginDir: true,
|
|
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(okam_exports);
|
|
|
25
25
|
var import_utils = require("@umijs/utils");
|
|
26
26
|
var okam_default = (api) => {
|
|
27
27
|
api.describe({
|
|
28
|
-
enableBy: () => Boolean(
|
|
28
|
+
enableBy: () => Boolean(api.config.mako)
|
|
29
29
|
});
|
|
30
30
|
api.onCheck(() => {
|
|
31
31
|
(0, import_utils.checkVersion)(16, `Node 16 is required when using mako.`);
|
|
@@ -41,11 +41,10 @@ var parser = (0, import_utils.importLazy)(
|
|
|
41
41
|
var prepare_default = (api) => {
|
|
42
42
|
function updateAppdata(prepareData) {
|
|
43
43
|
var _a;
|
|
44
|
-
const buildResult =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
44
|
+
const buildResult = import_utils.lodash.cloneDeep(prepareData.buildResult);
|
|
45
|
+
(buildResult.outputFiles || []).forEach((file) => {
|
|
46
|
+
file == null ? true : delete file.contents;
|
|
47
|
+
});
|
|
49
48
|
const nextFileImports = prepareData.fileImports ?? ((_a = api.appData.prepare) == null ? void 0 : _a.fileImports);
|
|
50
49
|
api.appData.prepare = {
|
|
51
50
|
buildResult,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const build: (api: IApi) => Promise<void>;
|
|
@@ -0,0 +1,90 @@
|
|
|
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(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/features/ssr/mako/mako.ts
|
|
30
|
+
var mako_exports = {};
|
|
31
|
+
__export(mako_exports, {
|
|
32
|
+
build: () => build
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(mako_exports);
|
|
35
|
+
var import_types = require("@umijs/bundler-webpack/dist/types");
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_fs = require("fs");
|
|
38
|
+
var import_path = __toESM(require("path"));
|
|
39
|
+
var import_utils2 = require("../utils");
|
|
40
|
+
var build = async (api) => {
|
|
41
|
+
import_utils.logger.wait("[SSR] Compiling by mako...");
|
|
42
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
43
|
+
const absOutputFile = (0, import_utils2.absServerBuildPath)(api);
|
|
44
|
+
require("@umijs/bundler-webpack/dist/requireHook");
|
|
45
|
+
const { build: build2 } = require(process.env.OKAM);
|
|
46
|
+
const useHash = api.config.hash && api.env === import_types.Env.production;
|
|
47
|
+
const entry = import_path.default.resolve(api.paths.absTmpPath, "umi.server.ts");
|
|
48
|
+
const options = {
|
|
49
|
+
cwd: api.cwd,
|
|
50
|
+
entry: {
|
|
51
|
+
"umi.server": entry
|
|
52
|
+
},
|
|
53
|
+
config: {
|
|
54
|
+
...api.config,
|
|
55
|
+
JSMinifier: "none",
|
|
56
|
+
hash: useHash,
|
|
57
|
+
outputPath: import_path.default.dirname(absOutputFile),
|
|
58
|
+
manifest: {
|
|
59
|
+
fileName: "build-manifest.json"
|
|
60
|
+
},
|
|
61
|
+
devtool: false,
|
|
62
|
+
cjs: true,
|
|
63
|
+
dynamicImportToRequire: true
|
|
64
|
+
},
|
|
65
|
+
chainWebpack: async (memo) => {
|
|
66
|
+
memo.target("node");
|
|
67
|
+
return memo;
|
|
68
|
+
},
|
|
69
|
+
onBuildComplete: () => {
|
|
70
|
+
const finalJsonObj = {};
|
|
71
|
+
const jsonFilePath = (0, import_path.join)((0, import_path.dirname)(absOutputFile), "build-manifest.json");
|
|
72
|
+
const json = (0, import_fs.existsSync)(jsonFilePath) ? import_utils.fsExtra.readJSONSync(jsonFilePath) : {};
|
|
73
|
+
finalJsonObj.assets = {
|
|
74
|
+
...json,
|
|
75
|
+
"umi.js": json["umi.server.js"],
|
|
76
|
+
"umi.css": json["umi.server.css"]
|
|
77
|
+
};
|
|
78
|
+
(0, import_fs.writeFileSync)(jsonFilePath, JSON.stringify(finalJsonObj, null, 2), {
|
|
79
|
+
flag: "w"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
await build2(options);
|
|
84
|
+
const diff = (/* @__PURE__ */ new Date()).getTime() - now;
|
|
85
|
+
import_utils.logger.info(`[SSR] Compiled in ${diff}ms`);
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
build
|
|
90
|
+
});
|
package/dist/features/ssr/ssr.js
CHANGED
|
@@ -45,14 +45,23 @@ var ssr_default = (api) => {
|
|
|
45
45
|
const webpackBuilder = (0, import_utils.importLazy)(
|
|
46
46
|
require.resolve("./webpack/webpack")
|
|
47
47
|
);
|
|
48
|
+
const makoBuiler = (0, import_utils.importLazy)(
|
|
49
|
+
require.resolve("./mako/mako")
|
|
50
|
+
);
|
|
51
|
+
let serverBuildTarget;
|
|
48
52
|
api.describe({
|
|
49
53
|
key: "ssr",
|
|
50
54
|
config: {
|
|
51
55
|
schema({ zod }) {
|
|
52
56
|
return zod.object({
|
|
53
57
|
serverBuildPath: zod.string(),
|
|
58
|
+
serverBuildTarget: zod.enum(["express", "worker"]),
|
|
54
59
|
platform: zod.string(),
|
|
55
|
-
builder: zod.enum(["esbuild", "webpack"])
|
|
60
|
+
builder: zod.enum(["esbuild", "webpack", "mako"]),
|
|
61
|
+
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: zod.object({
|
|
62
|
+
pureApp: zod.boolean(),
|
|
63
|
+
pureHtml: zod.boolean()
|
|
64
|
+
})
|
|
56
65
|
}).deepPartial();
|
|
57
66
|
}
|
|
58
67
|
},
|
|
@@ -69,6 +78,25 @@ var ssr_default = (api) => {
|
|
|
69
78
|
api.onStart(() => {
|
|
70
79
|
import_utils.logger.warn(`SSR feature is in beta, may be unstable`);
|
|
71
80
|
});
|
|
81
|
+
api.modifyDefaultConfig((memo) => {
|
|
82
|
+
if (serverBuildTarget === "worker") {
|
|
83
|
+
const oReactDom = memo.alias["react-dom"];
|
|
84
|
+
delete memo.alias["react-dom"];
|
|
85
|
+
memo.alias["react-dom/server$"] = (0, import_utils.winPath)(
|
|
86
|
+
(0, import_path.join)(
|
|
87
|
+
api.service.configDefaults.alias["react-dom"],
|
|
88
|
+
"server.browser.js"
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
memo.alias["react-dom"] = oReactDom;
|
|
92
|
+
}
|
|
93
|
+
return memo;
|
|
94
|
+
});
|
|
95
|
+
api.modifyConfig((memo) => {
|
|
96
|
+
memo.define ?? (memo.define = {});
|
|
97
|
+
serverBuildTarget = memo.define["process.env.SSR_BUILD_TARGET"] = memo.ssr.serverBuildTarget || "express";
|
|
98
|
+
return memo;
|
|
99
|
+
});
|
|
72
100
|
api.addMiddlewares(() => [
|
|
73
101
|
async (req, res, next) => {
|
|
74
102
|
const modulePath = (0, import_utils2.absServerBuildPath)(api);
|
|
@@ -133,7 +161,7 @@ export type {
|
|
|
133
161
|
});
|
|
134
162
|
});
|
|
135
163
|
api.onBeforeCompiler(async ({ opts }) => {
|
|
136
|
-
const { builder = "
|
|
164
|
+
const { builder = "webpack" } = api.config.ssr;
|
|
137
165
|
if (builder === "esbuild") {
|
|
138
166
|
await esbuildBuilder.build({
|
|
139
167
|
api,
|
|
@@ -145,6 +173,18 @@ export type {
|
|
|
145
173
|
`The \`vite\` config is now allowed when \`ssr.builder\` is webpack!`
|
|
146
174
|
);
|
|
147
175
|
await webpackBuilder.build(api, opts);
|
|
176
|
+
} else if (api.config.mako && builder === "mako") {
|
|
177
|
+
await makoBuiler.build(api);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
api.onDevCompileDone(() => {
|
|
181
|
+
if (api.config.mako) {
|
|
182
|
+
(0, import_utils2.generateBuildManifest)(api);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
api.onBuildComplete(() => {
|
|
186
|
+
if (api.config.mako) {
|
|
187
|
+
(0, import_utils2.generateBuildManifest)(api);
|
|
148
188
|
}
|
|
149
189
|
});
|
|
150
190
|
api.onBuildComplete(async ({ err }) => {
|
|
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var utils_exports = {};
|
|
21
21
|
__export(utils_exports, {
|
|
22
22
|
absServerBuildPath: () => absServerBuildPath,
|
|
23
|
-
esbuildUmiPlugin: () => esbuildUmiPlugin
|
|
23
|
+
esbuildUmiPlugin: () => esbuildUmiPlugin,
|
|
24
|
+
generateBuildManifest: () => generateBuildManifest
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(utils_exports);
|
|
27
|
+
var import_utils = require("@umijs/utils");
|
|
26
28
|
var import_fs = require("fs");
|
|
27
29
|
var import_path = require("path");
|
|
28
30
|
function esbuildUmiPlugin(api) {
|
|
@@ -53,8 +55,19 @@ function absServerBuildPath(api) {
|
|
|
53
55
|
const manifest = require(manifestPath);
|
|
54
56
|
return (0, import_path.join)(api.paths.cwd, "server", (0, import_path.basename)(manifest.assets["umi.js"]));
|
|
55
57
|
}
|
|
58
|
+
var generateBuildManifest = (api) => {
|
|
59
|
+
const finalJsonObj = {};
|
|
60
|
+
const assetFilePath = (0, import_path.join)(api.paths.absOutputPath, "asset-manifest.json");
|
|
61
|
+
const buildFilePath = (0, import_path.join)(api.paths.absOutputPath, "build-manifest.json");
|
|
62
|
+
const json = (0, import_fs.existsSync)(assetFilePath) ? import_utils.fsExtra.readJSONSync(assetFilePath) : {};
|
|
63
|
+
finalJsonObj.assets = json;
|
|
64
|
+
(0, import_fs.writeFileSync)(buildFilePath, JSON.stringify(finalJsonObj, null, 2), {
|
|
65
|
+
flag: "w"
|
|
66
|
+
});
|
|
67
|
+
};
|
|
56
68
|
// Annotate the CommonJS export names for ESM import in node:
|
|
57
69
|
0 && (module.exports = {
|
|
58
70
|
absServerBuildPath,
|
|
59
|
-
esbuildUmiPlugin
|
|
71
|
+
esbuildUmiPlugin,
|
|
72
|
+
generateBuildManifest
|
|
60
73
|
});
|
|
@@ -181,20 +181,16 @@ async function getRoutes(opts) {
|
|
|
181
181
|
});
|
|
182
182
|
return routes;
|
|
183
183
|
}
|
|
184
|
-
var IMPORT_EMPTY_ROUTE_CJS = `() => Promise.resolve(require('./EmptyRoute'))`;
|
|
185
|
-
var IMPORT_EMPTY_ROUTE_ESM = `() => import('./EmptyRoute')`;
|
|
186
184
|
async function getRouteComponents(opts) {
|
|
187
185
|
const imports = Object.keys(opts.routes).map((key) => {
|
|
188
186
|
var _a;
|
|
189
187
|
const useSuspense = opts.api.appData.framework === "react" ? true : false;
|
|
190
188
|
const route = opts.routes[key];
|
|
191
|
-
const useCjsModule = ((_a = opts.api.config.routeLoader) == null ? void 0 : _a.moduleType) === "cjs";
|
|
192
189
|
if (!route.file) {
|
|
193
190
|
if (process.env.NODE_ENV === "test") {
|
|
194
|
-
return `'${key}': require('./EmptyRoute').default,`;
|
|
191
|
+
return `'${key}': require( './EmptyRoute').default,`;
|
|
195
192
|
}
|
|
196
|
-
|
|
197
|
-
return useSuspense ? `'${key}': React.lazy(${importEmptyRoute}),` : `'${key}': ${importEmptyRoute},`;
|
|
193
|
+
return useSuspense ? `'${key}': React.lazy(() => import( './EmptyRoute')),` : `'${key}': () => import( './EmptyRoute'),`;
|
|
198
194
|
}
|
|
199
195
|
if (route.hasClientLoader) {
|
|
200
196
|
route.file = (0, import_path.join)(
|
|
@@ -217,7 +213,7 @@ async function getRouteComponents(opts) {
|
|
|
217
213
|
if (process.env.NODE_ENV === "test") {
|
|
218
214
|
return `'${key}': require('${(0, import_utils.winPath)(path)}').default,`;
|
|
219
215
|
}
|
|
220
|
-
if (
|
|
216
|
+
if (((_a = opts.api.config.routeLoader) == null ? void 0 : _a.moduleType) === "cjs") {
|
|
221
217
|
return useSuspense ? `'${key}': React.lazy(() => Promise.resolve(require('${(0, import_utils.winPath)(
|
|
222
218
|
path
|
|
223
219
|
)}'))),` : `'${key}': () => Promise.resolve(require('${(0, import_utils.winPath)(path)}')),`;
|
|
@@ -36,6 +36,7 @@ var import_utils = require("@umijs/utils");
|
|
|
36
36
|
var import_fs = require("fs");
|
|
37
37
|
var import_path = require("path");
|
|
38
38
|
var import_umi = require("umi");
|
|
39
|
+
var import_getMarkupArgs = require("../../commands/dev/getMarkupArgs");
|
|
39
40
|
var import_constants = require("../../constants");
|
|
40
41
|
var import_getModuleExports = require("./getModuleExports");
|
|
41
42
|
var import_importsToStr = require("./importsToStr");
|
|
@@ -53,7 +54,7 @@ var tmpFiles_default = (api) => {
|
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
api.onGenerateFiles(async (opts) => {
|
|
56
|
-
var _a, _b, _c;
|
|
57
|
+
var _a, _b, _c, _d;
|
|
57
58
|
const rendererPath = (0, import_utils.winPath)(
|
|
58
59
|
await api.applyPlugins({
|
|
59
60
|
key: "modifyRendererPath",
|
|
@@ -111,7 +112,6 @@ var tmpFiles_default = (api) => {
|
|
|
111
112
|
},
|
|
112
113
|
include: [
|
|
113
114
|
`${baseUrl}.${frameworkName}rc.ts`,
|
|
114
|
-
`${baseUrl}.${frameworkName}rc.*.ts`,
|
|
115
115
|
`${baseUrl}**/*.d.ts`,
|
|
116
116
|
`${baseUrl}**/*.ts`,
|
|
117
117
|
`${baseUrl}**/*.tsx`,
|
|
@@ -269,6 +269,33 @@ declare module '*.txt' {
|
|
|
269
269
|
}
|
|
270
270
|
`.trimEnd()
|
|
271
271
|
});
|
|
272
|
+
const entryCode = (await api.applyPlugins({
|
|
273
|
+
key: "addEntryCode",
|
|
274
|
+
initialValue: []
|
|
275
|
+
})).join("\n");
|
|
276
|
+
const entryCodeAhead = (await api.applyPlugins({
|
|
277
|
+
key: "addEntryCodeAhead",
|
|
278
|
+
initialValue: []
|
|
279
|
+
})).join("\n");
|
|
280
|
+
const importsAhead = (0, import_importsToStr.importsToStr)(
|
|
281
|
+
await api.applyPlugins({
|
|
282
|
+
key: "addEntryImportsAhead",
|
|
283
|
+
initialValue: [
|
|
284
|
+
api.appData.globalCSS.length && {
|
|
285
|
+
source: api.appData.globalCSS[0]
|
|
286
|
+
},
|
|
287
|
+
api.appData.globalJS.length && {
|
|
288
|
+
source: api.appData.globalJS[0]
|
|
289
|
+
}
|
|
290
|
+
].filter(Boolean)
|
|
291
|
+
})
|
|
292
|
+
).join("\n");
|
|
293
|
+
const imports = (0, import_importsToStr.importsToStr)(
|
|
294
|
+
await api.applyPlugins({
|
|
295
|
+
key: "addEntryImports",
|
|
296
|
+
initialValue: []
|
|
297
|
+
})
|
|
298
|
+
).join("\n");
|
|
272
299
|
api.writeTmpFile({
|
|
273
300
|
noPluginDir: true,
|
|
274
301
|
path: "umi.ts",
|
|
@@ -278,39 +305,16 @@ declare module '*.txt' {
|
|
|
278
305
|
rendererPath,
|
|
279
306
|
publicPath: api.config.publicPath,
|
|
280
307
|
runtimePublicPath: api.config.runtimePublicPath ? "true" : "false",
|
|
281
|
-
entryCode
|
|
282
|
-
|
|
283
|
-
initialValue: []
|
|
284
|
-
})).join("\n"),
|
|
285
|
-
entryCodeAhead: (await api.applyPlugins({
|
|
286
|
-
key: "addEntryCodeAhead",
|
|
287
|
-
initialValue: []
|
|
288
|
-
})).join("\n"),
|
|
308
|
+
entryCode,
|
|
309
|
+
entryCodeAhead,
|
|
289
310
|
polyfillImports: (0, import_importsToStr.importsToStr)(
|
|
290
311
|
await api.applyPlugins({
|
|
291
312
|
key: "addPolyfillImports",
|
|
292
313
|
initialValue: []
|
|
293
314
|
})
|
|
294
315
|
).join("\n"),
|
|
295
|
-
importsAhead
|
|
296
|
-
|
|
297
|
-
key: "addEntryImportsAhead",
|
|
298
|
-
initialValue: [
|
|
299
|
-
api.appData.globalCSS.length && {
|
|
300
|
-
source: api.appData.globalCSS[0]
|
|
301
|
-
},
|
|
302
|
-
api.appData.globalJS.length && {
|
|
303
|
-
source: api.appData.globalJS[0]
|
|
304
|
-
}
|
|
305
|
-
].filter(Boolean)
|
|
306
|
-
})
|
|
307
|
-
).join("\n"),
|
|
308
|
-
imports: (0, import_importsToStr.importsToStr)(
|
|
309
|
-
await api.applyPlugins({
|
|
310
|
-
key: "addEntryImports",
|
|
311
|
-
initialValue: []
|
|
312
|
-
})
|
|
313
|
-
).join("\n"),
|
|
316
|
+
importsAhead,
|
|
317
|
+
imports,
|
|
314
318
|
basename: api.config.base,
|
|
315
319
|
historyType: api.config.history.type,
|
|
316
320
|
hydrate: !!api.config.ssr,
|
|
@@ -422,9 +426,6 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
422
426
|
const validKeys = await api.applyPlugins({
|
|
423
427
|
key: "addRuntimePluginKey",
|
|
424
428
|
initialValue: [
|
|
425
|
-
// why add default?
|
|
426
|
-
// ref: https://github.com/umijs/mako/issues/1026
|
|
427
|
-
...process.env.OKAM ? ["default"] : [],
|
|
428
429
|
"patchRoutes",
|
|
429
430
|
"patchClientRoutes",
|
|
430
431
|
"modifyContextOpts",
|
|
@@ -460,6 +461,11 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
460
461
|
if (api.config.ssr) {
|
|
461
462
|
const umiPluginPath = (0, import_utils.winPath)((0, import_path.join)(umiDir, "client/client/plugin.js"));
|
|
462
463
|
const umiServerPath = (0, import_utils.winPath)(require.resolve("@umijs/server/dist/ssr"));
|
|
464
|
+
const __INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ((_d = api.config.ssr) == null ? void 0 : _d.__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) ?? {
|
|
465
|
+
pureApp: false,
|
|
466
|
+
pureHtml: false
|
|
467
|
+
};
|
|
468
|
+
const mountElementId = api.config.mountElementId;
|
|
463
469
|
const routesWithServerLoader = Object.keys(routes).reduce((memo, id) => {
|
|
464
470
|
if (routes[id].hasServerLoader) {
|
|
465
471
|
memo.push({
|
|
@@ -469,6 +475,7 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
469
475
|
}
|
|
470
476
|
return memo;
|
|
471
477
|
}, []);
|
|
478
|
+
const { headScripts, scripts, styles, title, favicons, links, metas } = await (0, import_getMarkupArgs.getMarkupArgs)({ api });
|
|
472
479
|
api.writeTmpFile({
|
|
473
480
|
noPluginDir: true,
|
|
474
481
|
path: "umi.server.ts",
|
|
@@ -478,7 +485,12 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
478
485
|
/"component": "await import\((.*)\)"/g,
|
|
479
486
|
'"component": await import("$1")'
|
|
480
487
|
),
|
|
488
|
+
version: api.appData.umi.version,
|
|
489
|
+
entryCode,
|
|
490
|
+
entryCodeAhead,
|
|
481
491
|
routesWithServerLoader,
|
|
492
|
+
importsAhead,
|
|
493
|
+
imports,
|
|
482
494
|
umiPluginPath,
|
|
483
495
|
serverRendererPath,
|
|
484
496
|
umiServerPath,
|
|
@@ -486,7 +498,20 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
486
498
|
assetsPath: (0, import_utils.winPath)(
|
|
487
499
|
(0, import_path.join)(api.paths.absOutputPath, "build-manifest.json")
|
|
488
500
|
),
|
|
489
|
-
env: JSON.stringify(api.env)
|
|
501
|
+
env: JSON.stringify(api.env),
|
|
502
|
+
htmlPageOpts: JSON.stringify({
|
|
503
|
+
headScripts,
|
|
504
|
+
styles,
|
|
505
|
+
title,
|
|
506
|
+
favicons,
|
|
507
|
+
links,
|
|
508
|
+
metas,
|
|
509
|
+
scripts: scripts || []
|
|
510
|
+
}),
|
|
511
|
+
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: JSON.stringify(
|
|
512
|
+
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
|
513
|
+
),
|
|
514
|
+
mountElementId
|
|
490
515
|
}
|
|
491
516
|
});
|
|
492
517
|
}
|
|
@@ -553,7 +578,9 @@ if (process.env.NODE_ENV === 'development') {
|
|
|
553
578
|
exportMembers
|
|
554
579
|
})).join(", ")} } from '${rendererPath}';`
|
|
555
580
|
);
|
|
556
|
-
exports.push(
|
|
581
|
+
exports.push(
|
|
582
|
+
`export type { History, ClientLoader } from '${rendererPath}'`
|
|
583
|
+
);
|
|
557
584
|
exports.push("// umi/client/client/plugin");
|
|
558
585
|
const umiPluginPath = (0, import_utils.winPath)((0, import_path.join)(umiDir, "client/client/plugin.js"));
|
|
559
586
|
exports.push(
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,6 @@ var src_default = () => {
|
|
|
88
88
|
require.resolve("./features/mako/mako"),
|
|
89
89
|
require.resolve("./features/hmrGuardian/hmrGuardian"),
|
|
90
90
|
require.resolve("./features/routePreloadOnLoad/routePreloadOnLoad"),
|
|
91
|
-
require.resolve("./features/forget/forget"),
|
|
92
91
|
// commands
|
|
93
92
|
require.resolve("./commands/build"),
|
|
94
93
|
require.resolve("./commands/config/config"),
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/preset-umi",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.6-alpha.0",
|
|
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",
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@iconify/utils": "2.1.1",
|
|
23
23
|
"@svgr/core": "6.5.1",
|
|
24
|
-
"@umijs/bundler-mako": "0.4.
|
|
24
|
+
"@umijs/bundler-mako": "0.4.18-canary.20240520.1",
|
|
25
25
|
"@umijs/es-module-parser": "0.0.7",
|
|
26
26
|
"@umijs/history": "5.3.1",
|
|
27
27
|
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
28
|
-
"babel-plugin-react-compiler": "0.0.0-experimental-c23de8d-20240515",
|
|
29
28
|
"click-to-react-component": "^1.0.8",
|
|
30
29
|
"core-js": "3.34.0",
|
|
31
30
|
"current-script-polyfill": "1.0.0",
|
|
@@ -41,21 +40,21 @@
|
|
|
41
40
|
"react-router": "6.3.0",
|
|
42
41
|
"react-router-dom": "6.3.0",
|
|
43
42
|
"regenerator-runtime": "0.13.11",
|
|
44
|
-
"@umijs/
|
|
45
|
-
"@umijs/bundler-
|
|
46
|
-
"@umijs/bundler-utils": "4.2.
|
|
47
|
-
"@umijs/
|
|
48
|
-
"@umijs/bundler-
|
|
49
|
-
"@umijs/
|
|
50
|
-
"@umijs/
|
|
51
|
-
"@umijs/
|
|
52
|
-
"@umijs/server": "4.2.
|
|
53
|
-
"@umijs/
|
|
54
|
-
"@umijs/
|
|
55
|
-
"@umijs/zod2ts": "4.2.
|
|
56
|
-
"@umijs/
|
|
57
|
-
"@umijs/
|
|
58
|
-
"@umijs/
|
|
43
|
+
"@umijs/babel-preset-umi": "4.2.6-alpha.0",
|
|
44
|
+
"@umijs/bundler-esbuild": "4.2.6-alpha.0",
|
|
45
|
+
"@umijs/bundler-utils": "4.2.6-alpha.0",
|
|
46
|
+
"@umijs/ast": "4.2.6-alpha.0",
|
|
47
|
+
"@umijs/bundler-vite": "4.2.6-alpha.0",
|
|
48
|
+
"@umijs/did-you-know": "1.0.3",
|
|
49
|
+
"@umijs/renderer-react": "4.2.6-alpha.0",
|
|
50
|
+
"@umijs/bundler-webpack": "4.2.6-alpha.0",
|
|
51
|
+
"@umijs/server": "4.2.6-alpha.0",
|
|
52
|
+
"@umijs/utils": "4.2.6-alpha.0",
|
|
53
|
+
"@umijs/plugin-run": "4.2.6-alpha.0",
|
|
54
|
+
"@umijs/zod2ts": "4.2.6-alpha.0",
|
|
55
|
+
"@umijs/mfsu": "4.2.6-alpha.0",
|
|
56
|
+
"@umijs/core": "4.2.6-alpha.0",
|
|
57
|
+
"@umijs/ui": "3.0.1"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
60
|
"@manypkg/get-packages": "1.1.3",
|
package/templates/history.tpl
CHANGED
|
@@ -41,12 +41,6 @@ export function createHistory(opts: any) {
|
|
|
41
41
|
return h;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function setHistory(h: UmiHistory) {
|
|
45
|
-
if (h) {
|
|
46
|
-
history = h;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
44
|
// Patch `to` to support basename
|
|
51
45
|
// Refs:
|
|
52
46
|
// https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
|
package/templates/server.tpl
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
{{{ importsAhead }}}
|
|
1
2
|
import { getClientRootComponent } from '{{{ serverRendererPath }}}';
|
|
2
3
|
import { getRoutes } from './core/route';
|
|
3
4
|
import { createHistory as createClientHistory } from './core/history';
|
|
4
|
-
import { getPlugins as getClientPlugins } from './core/plugin';
|
|
5
5
|
import { ServerInsertedHTMLContext } from './core/serverInsertedHTMLContext';
|
|
6
|
-
import {
|
|
7
|
-
import createRequestHandler, { createMarkupGenerator, createUmiHandler, createUmiServerLoader } from '{{{ umiServerPath }}}';
|
|
8
|
-
|
|
6
|
+
import { createPluginManager } from './core/plugin';
|
|
7
|
+
import createRequestHandler, { createMarkupGenerator, createUmiHandler, createUmiServerLoader, createAppRootElement } from '{{{ umiServerPath }}}';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
{{{ imports }}}
|
|
11
|
+
{{{ entryCodeAhead }}}
|
|
9
12
|
let helmetContext;
|
|
10
13
|
|
|
11
14
|
try {
|
|
@@ -18,17 +21,19 @@ const routesWithServerLoader = {
|
|
|
18
21
|
{{/routesWithServerLoader}}
|
|
19
22
|
};
|
|
20
23
|
|
|
21
|
-
export function getPlugins() {
|
|
22
|
-
return getClientPlugins();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getValidKeys() {
|
|
26
|
-
return [{{#validKeys}}'{{{ . }}}',{{/validKeys}}];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
24
|
export function getManifest(sourceDir) {
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
let manifestPath;
|
|
26
|
+
if (process.env.SSR_MANIFEST) {
|
|
27
|
+
return JSON.parse(process.env.SSR_MANIFEST)
|
|
28
|
+
}
|
|
29
|
+
if (sourceDir) {
|
|
30
|
+
manifestPath = path.join(sourceDir,'build-manifest.json')
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
manifestPath = '{{{ assetsPath }}}'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return JSON.parse(fs.readFileSync(manifestPath), 'utf-8');
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
export function createHistory(opts) {
|
|
@@ -42,20 +47,34 @@ global.g_getAssets = (fileName) => {
|
|
|
42
47
|
};
|
|
43
48
|
const createOpts = {
|
|
44
49
|
routesWithServerLoader,
|
|
45
|
-
|
|
46
|
-
getPlugins,
|
|
47
|
-
getValidKeys,
|
|
50
|
+
pluginManager: createPluginManager(),
|
|
48
51
|
getRoutes,
|
|
49
52
|
manifest: getManifest,
|
|
50
53
|
getClientRootComponent,
|
|
51
54
|
helmetContext,
|
|
52
55
|
createHistory,
|
|
53
56
|
ServerInsertedHTMLContext,
|
|
57
|
+
htmlPageOpts: {{{htmlPageOpts}}},
|
|
58
|
+
__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {{{__INTERNAL_DO_NOT_USE_OR_YOU_WILL_BE_FIRED}}},
|
|
59
|
+
mountElementId: '{{{mountElementId}}}'
|
|
60
|
+
|
|
54
61
|
};
|
|
55
62
|
const requestHandler = createRequestHandler(createOpts);
|
|
63
|
+
/**
|
|
64
|
+
* @deprecated Please use `requestHandler` instead.
|
|
65
|
+
*/
|
|
56
66
|
export const renderRoot = createUmiHandler(createOpts);
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Please use `requestHandler` instead.
|
|
69
|
+
*/
|
|
57
70
|
export const serverLoader = createUmiServerLoader(createOpts);
|
|
58
71
|
|
|
59
72
|
export const _markupGenerator = createMarkupGenerator(createOpts);
|
|
60
73
|
|
|
74
|
+
export const getAppRootElement = createAppRootElement.bind(null, createOpts)();
|
|
75
|
+
|
|
61
76
|
export default requestHandler;
|
|
77
|
+
|
|
78
|
+
export const g_umi = '{{{version}}}'
|
|
79
|
+
|
|
80
|
+
{{{ entryCode }}}
|
package/templates/umi.tpl
CHANGED
|
@@ -56,6 +56,7 @@ async function render() {
|
|
|
56
56
|
routes,
|
|
57
57
|
routeComponents,
|
|
58
58
|
pluginManager,
|
|
59
|
+
mountElementId: '{{{mountElementId}}}',
|
|
59
60
|
rootElement: contextOpts.rootElement || document.getElementById('{{{ mountElementId }}}'),
|
|
60
61
|
{{#loadingComponent}}
|
|
61
62
|
loadingComponent: Loading,
|
|
@@ -1,77 +0,0 @@
|
|
|
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(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/features/forget/forget.ts
|
|
30
|
-
var forget_exports = {};
|
|
31
|
-
__export(forget_exports, {
|
|
32
|
-
default: () => forget_default
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(forget_exports);
|
|
35
|
-
var forget_default = (api) => {
|
|
36
|
-
api.describe({
|
|
37
|
-
key: "forget",
|
|
38
|
-
config: {
|
|
39
|
-
schema({ zod }) {
|
|
40
|
-
return zod.object({
|
|
41
|
-
ReactCompilerConfig: zod.object({}).optional()
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
enableBy: api.EnableBy.config
|
|
46
|
-
});
|
|
47
|
-
api.onCheckConfig(() => {
|
|
48
|
-
if (api.config.mfsu) {
|
|
49
|
-
throw new Error(
|
|
50
|
-
`forget is not compatible with mfsu, please disable mfsu first.`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
if (api.config.mako) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`forget is not compatible with mako, please disable mako first.`
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
api.onCheck(() => {
|
|
60
|
-
let reactMajorVersion = api.appData.react.version.split(".")[0];
|
|
61
|
-
if (reactMajorVersion < 19) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`forget is only compatible with React 19 and above, please upgrade your React version.`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
api.modifyConfig((memo) => {
|
|
68
|
-
let ReactCompilerConfig = api.userConfig.forget.ReactCompilerConfig || {};
|
|
69
|
-
return {
|
|
70
|
-
...memo,
|
|
71
|
-
extraBabelPlugins: [
|
|
72
|
-
...memo.extraBabelPlugins || [],
|
|
73
|
-
[require.resolve("babel-plugin-react-compiler"), ReactCompilerConfig]
|
|
74
|
-
]
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
};
|