提交 2c3779c2 编写于 作者: fxy060608's avatar fxy060608

feat(x-ios): 发行时支持摇树

上级 8e80b0f9
......@@ -29,7 +29,11 @@ import {
createTryResolve,
} from './utils'
import { getOutputManifestJson } from './manifestJson'
import { configResolved, createUniOptions } from '../utils'
import {
configResolved,
createUniOptions,
updateManifestModules,
} from '../utils'
import { genClassName } from '../..'
const uniCloudSpaceList = getUniCloudSpaceList()
......@@ -196,20 +200,7 @@ export function uniAppPlugin(): UniVitePlugin {
const manifest = getOutputManifestJson()!
if (manifest) {
// 执行了摇树逻辑,就需要设置 modules 节点
const app = manifest.app
if (!app.distribute) {
app.distribute = {}
}
if (!app.distribute.modules) {
app.distribute.modules = {}
}
if (modules) {
modules.forEach((name) => {
const value = app.distribute.modules[name]
app.distribute.modules[name] =
typeof value === 'object' && value !== null ? value : {}
})
}
updateManifestModules(manifest, modules)
fs.outputFileSync(
path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'),
JSON.stringify(manifest, null, 2)
......
import path from 'path'
import fs from 'fs-extra'
import type { Plugin } from 'vite'
import { MANIFEST_JSON_UTS, parseJson } from '@dcloudio/uni-cli-shared'
import { isManifest, normalizeManifestJson } from '../utils'
import {
MANIFEST_JSON_UTS,
parseJson,
resolveUTSCompiler,
} from '@dcloudio/uni-cli-shared'
import {
isManifest,
normalizeManifestJson,
updateManifestModules,
} from '../utils'
let outputManifestJson: Record<string, any> | undefined = undefined
......@@ -42,11 +50,40 @@ export function uniAppManifestPlugin(): Plugin {
return `export default ${JSON.stringify(manifestJson)}`
}
},
writeBundle() {
buildEnd() {
outputManifestJson = normalizeManifestJson(manifestJson)
const manifest = outputManifestJson
if (process.env.NODE_ENV !== 'development') {
// 生产模式,记录使用到的modules
const ids = Array.from(this.getModuleIds())
const uniExtApis = new Set<string>()
ids.forEach((id) => {
const moduleInfo = this.getModuleInfo(id)
if (
moduleInfo &&
moduleInfo.meta &&
Array.isArray(moduleInfo.meta.uniExtApis)
) {
moduleInfo.meta.uniExtApis.forEach((api) => {
uniExtApis.add(api)
})
}
})
if (uniExtApis.size) {
const modules = resolveUTSCompiler().parseInjectModules(
[...uniExtApis],
{},
[]
)
// 执行了摇树逻辑,就需要设置 modules 节点
updateManifestModules(manifest, modules)
}
}
fs.outputFileSync(
path.resolve(process.env.UNI_OUTPUT_DIR, 'manifest.json'),
JSON.stringify(outputManifestJson, null, 2)
JSON.stringify(manifest, null, 2)
)
},
}
......
......@@ -158,3 +158,25 @@ export function normalizeManifestJson(userManifestJson: Record<string, any>) {
app,
}
}
export function updateManifestModules(
manifest: Record<string, any>,
modules: string[]
) {
// 执行了摇树逻辑,就需要设置 modules 节点
const app = manifest.app
if (!app.distribute) {
app.distribute = {}
}
if (!app.distribute.modules) {
app.distribute.modules = {}
}
if (modules) {
modules.forEach((name) => {
const value = app.distribute.modules[name]
app.distribute.modules[name] =
typeof value === 'object' && value !== null ? value : {}
})
}
return manifest
}
因为 它太大了无法显示 source diff 。你可以改为 查看blob
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册