element-plus/build/utils/rollup.ts
2022-01-20 15:31:33 +08:00

36 lines
928 B
TypeScript

import { epPackage } from './paths'
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[] = peerDependencies
if (!options.full) {
packages.push('element-plus/theme-chalk')
// dependencies
packages.push('@vue', ...dependencies)
}
return [...new Set(packages)].some(
(pkg) => id === pkg || id.startsWith(`${pkg}/`)
)
}
}
export function writeBundles(bundle: RollupBuild, options: OutputOptions[]) {
return Promise.all(options.map((option) => bundle.write(option)))
}
export function formatBundleFilename(
name: string,
minify: boolean,
ext: string
) {
return `${name}${minify ? '.min' : ''}.${ext}`
}