赞
踩
1、modifyManifest.ts
// 读取 manifest.json ,修改后重新写入 const fs = require('fs'); const manifestPath = './src/manifest.json'; let Manifest = fs.readFileSync(manifestPath, { encoding: 'utf-8' }); function replaceManifest(path, value) { const arr = path.split('.'); const len = arr.length; const lastItem = arr[len - 1]; let i = 0; let ManifestArr = Manifest.split(/\n/); for (let index = 0; index < ManifestArr.length; index++) { const item = ManifestArr[index]; if (new RegExp(`"${arr[i]}"`).test(item)) ++i; if (i === len) { const hasComma = /,/.test(item); ManifestArr[index] = item.replace( new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`), `"${lastItem}": ${value}${hasComma ? ',' : ''}` ); break; } } Manifest = ManifestArr.join('\n'); } export const modifyManifest = ((mode = 'prod')=>{ const BASEMAP = Object.freeze({ 'dev':'/dev/', 'prod':'/prod/', }) replaceManifest('h5.router.base',`"${BASEMAP[mode]}"`); fs.writeFileSync(manifestPath, Manifest, { flag: 'w', }); })
2、vite.config.ts
import { defineConfig } from "vite";
import uni from '@dcloudio/vite-plugin-uni';
import { modifyManifest } from './modifyManifest';
export default defineConfig(({ mode }: Record<string, any>) => {
modifyManifest(mode)
return {
plugins: [uni()],
}
3、指路=>官方文档:https://uniapp.dcloud.net.cn/collocation/vite-config.html
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。