element-plus/build/rollup.config.ts

63 lines
1.7 KiB
TypeScript
Raw Normal View History

import vue from 'rollup-plugin-vue'
import css from 'rollup-plugin-css-only'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import esbuild from 'rollup-plugin-esbuild'
import path from 'path'
import { getPackagesSync } from '@lerna/project'
2020-10-29 16:13:29 +08:00
import pkg from '../package.json'
const noElPrefixFile = /(utils|directives|hooks|locale)/
2021-06-30 14:19:38 +08:00
const getOutFile = (name, dir = 'lib') => {
const compName = name.split('@element-plus/')[1]
2021-06-30 14:19:38 +08:00
if (noElPrefixFile.test(name)) {
return `${dir}/${compName}/index.js`
}
return `${dir}/el-${compName}/index.js`
}
2020-11-04 11:24:36 +08:00
const deps = Object.keys(pkg.dependencies)
const inputs = getPackagesSync()
.map(pkg => pkg.name)
.filter(name =>
name.includes('@element-plus') &&
!name.includes('utils'),
)
export default inputs.map(name => ({
input: path.resolve(__dirname, `../packages/${name.split('@element-plus/')[1]}/index.ts`),
output: [{
format: 'es',
file: getOutFile(name, 'es'),
paths(id) {
if (/^@element-plus/.test(id)) {
if (noElPrefixFile.test(id)) return id.replace('@element-plus', '..')
return id.replace('@element-plus/', '../el-')
}
},
2021-06-30 14:19:38 +08:00
}, {
format: 'cjs',
file: getOutFile(name, 'lib'),
exports: 'named',
paths(id) {
if (/^@element-plus/.test(id)) {
if (noElPrefixFile.test(id)) return id.replace('@element-plus', '..')
return id.replace('@element-plus/', '../el-')
}
},
}],
plugins: [
css(),
vue({
target: 'browser',
// css: false,
}),
nodeResolve(),
esbuild(),
],
external(id) {
2020-10-29 16:13:29 +08:00
return /^vue/.test(id)
|| /^@element-plus/.test(id)
2020-11-04 11:24:36 +08:00
|| deps.some(k => new RegExp('^' + k).test(id))
},
}))