Files
element-plus/build/utils/rollup.ts
jeremywu 16f069ebbe Revert "build!: simplify build & support native esm import (#3900)" (#3945)
* Revert "build!: simplify build & support native esm import (#3900)"

This reverts commit fb94222bb4.

* remove module

* Fix linter

* Add @element-plus/icons as dependency

* update pnpm lock file

* temporary lock element-plus at 1.1.0-beta.20
2021-10-20 09:42:32 +08:00

53 lines
1.4 KiB
TypeScript

import { EP_PREFIX } from '../constants'
import { epPackage } from './paths'
import {
getWorkspacePackages,
getPackageDependencies,
getWorkspaceNames,
pathRewriter,
} from './pkg'
import type { Module } from '../info'
import type { OutputOptions, RollupBuild } from 'rollup'
export const generateExternal = async (options: { full: boolean }) => {
const monoPackages = (await getWorkspacePackages())
.map((pkg) => pkg.manifest.name)
// filter root package
.filter((name): name is string => !!name)
return (id: string) => {
const packages: string[] = ['vue']
if (!options.full) {
const depPackages = getPackageDependencies(epPackage)
packages.push('@vue', ...monoPackages, ...depPackages)
}
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 const rollupPathRewriter = async () => {
const workspacePkgs = (await getWorkspaceNames()).filter((pkg) =>
pkg.startsWith(EP_PREFIX)
)
return (module: Module) => {
const rewriter = pathRewriter(module, false)
return (id: string) => {
if (workspacePkgs.some((pkg) => id.startsWith(pkg))) {
return rewriter(id)
} else {
return ''
}
}
}
}