Files
element-plus/build/plugins/rollup-plugin-entry.ts
三咲智子 fb94222bb4 build!: simplify build & support native esm import (#3900)
* build: refactor build

* refactor: reorganize files

* refactor: refactor build

* build: improve perf

* fix: scripts

* build: add rollup-plugin-filesize

* chore: scripts ignore no-console

* build: disable tree-shaking

* build: improve code

* build: add sourcemap

* build: add banner

* refactor: remove annotation
2021-10-18 14:45:57 +08:00

33 lines
923 B
TypeScript

import path from 'path'
import { pkgRoot } from '../utils/paths'
import { EP_PKG, EP_PREFIX } from '../utils/constants'
import { getWorkspaceNames } from '../utils/pkg'
import type { Plugin } from 'rollup'
export async function RollupResolveEntryPlugin(): Promise<Plugin> {
const pkgs = (await getWorkspaceNames(pkgRoot))
.filter((pkg) => pkg.startsWith(`${EP_PREFIX}/`))
.map((pkg) => pkg.replace(`${EP_PREFIX}/`, ''))
return {
name: 'element-plus-entry-plugin',
transform(code, id) {
if (id.includes('packages')) {
code = code.replaceAll(
`${EP_PREFIX}/theme-chalk`,
`${EP_PKG}/theme-chalk`
)
code = code.replace(
new RegExp(`@element-plus\\/(${pkgs.join('|')})`, 'g'),
`${path.relative(path.dirname(id), path.resolve(pkgRoot))}/$1`
)
return {
code,
map: null,
}
}
},
}
}