perf(build): optimizition build time (#5507)

This commit is contained in:
Valar103769 2022-01-20 15:31:33 +08:00 committed by GitHub
parent 47fdd4f542
commit 621d8c7a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -19,10 +19,16 @@ export const getPackageManifest = (pkgPath: string) => {
return require(pkgPath) as ProjectManifest
}
export const getPackageDependencies = (pkgPath: string): string[] => {
export const getPackageDependencies = (
pkgPath: string
): Record<'dependencies' | 'peerDependencies', string[]> => {
const manifest = getPackageManifest(pkgPath)
const { dependencies } = manifest
return Object.keys(dependencies ?? {})
const { dependencies = {}, peerDependencies = {} } = manifest
return {
dependencies: Object.keys(dependencies),
peerDependencies: Object.keys(peerDependencies),
}
}
/** used for type generator */

View File

@ -4,12 +4,16 @@ import { getPackageDependencies } from './pkg'
import type { OutputOptions, RollupBuild } from 'rollup'
export const generateExternal = async (options: { full: boolean }) => {
const { dependencies, peerDependencies } = await getPackageDependencies(
epPackage
)
return (id: string) => {
const packages: string[] = ['vue']
const packages: string[] = peerDependencies
if (!options.full) {
packages.push('element-plus/theme-chalk')
// dependencies
packages.push('@vue', ...getPackageDependencies(epPackage))
packages.push('@vue', ...dependencies)
}
return [...new Set(packages)].some(

View File

@ -28,7 +28,7 @@ if (process.env.DOC_ENV !== 'production') {
}
export default async () => {
const deps = getPackageDependencies(epPackage)
const { dependencies } = getPackageDependencies(epPackage)
const optimizeDeps = [
'vue',
'@vue/shared',
@ -36,7 +36,7 @@ export default async () => {
'clipboard-copy',
'axios',
'nprogress',
...deps,
...dependencies,
]
optimizeDeps.push(
...(