前端 uni-app 重写: 9页面 H5

This commit is contained in:
zhiqui
2026-11-15 15:09:37 +08:00
parent 513b53672e
commit ea7c2529e9
24104 changed files with 3667749 additions and 0 deletions
@@ -0,0 +1,4 @@
import type { Plugin, ResolvedConfig } from 'vite';
export declare function createTransformIndexHtml(options: {
resolvedConfig: ResolvedConfig | null;
}): Plugin['transformIndexHtml'];
@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTransformIndexHtml = void 0;
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
const utils_1 = require("../../utils");
function createTransformIndexHtml(options) {
let warned = false;
return async function (html) {
const manifestJson = (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
const webManifest = (0, uni_cli_shared_1.getPlatformManifestJson)(manifestJson, 'h5');
const title = webManifest?.title || manifestJson.name || '';
const isX = process.env.UNI_APP_X === 'true';
if (isX) {
// 兼容旧版本模板
const mainJs = ` src="/main.js"`;
const mainTs = ` src="/main.ts"`;
const main = ` src="/main"`;
let oldMain = '';
if (html.includes(mainJs)) {
oldMain = mainJs;
}
else if (html.includes(mainTs)) {
oldMain = mainTs;
}
if (oldMain) {
html = html.replace(oldMain, main);
if (!warned) {
warned = true;
console.warn(`当前项目根目录 index.html 未兼容 uni-app x 的 web 平台,请将里边的${oldMain} 调整为${main}。`);
}
}
}
const config = options.resolvedConfig;
if ((0, uni_cli_shared_1.isUniAppXWebVapor)() &&
config &&
!(0, uni_cli_shared_1.isSsr)(config.command, config) &&
!(0, utils_1.isSsrManifest)(config.command, config)) {
html = html.replace('<!--app-html-->', '');
}
const tags = [];
if (process.env.NODE_ENV === 'development') {
tags.push({
tag: 'script',
children: `if (typeof globalThis === 'undefined') {
window.globalThis = window
}`,
injectTo: 'head-prepend',
});
}
return {
html: html.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`),
tags,
};
};
}
exports.createTransformIndexHtml = createTransformIndexHtml;