2021-06-03 13:05:21 +08:00
|
|
|
import vue from 'rollup-plugin-vue'
|
2020-09-30 18:21:47 +08:00
|
|
|
import css from 'rollup-plugin-css-only'
|
|
|
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
2021-06-03 13:05:21 +08:00
|
|
|
import esbuild from 'rollup-plugin-esbuild'
|
2020-09-30 18:21:47 +08:00
|
|
|
import path from 'path'
|
2020-10-20 11:45:44 +08:00
|
|
|
import { getPackagesSync } from '@lerna/project'
|
2020-10-29 16:13:29 +08:00
|
|
|
import pkg from '../package.json'
|
2021-06-03 13:05:21 +08:00
|
|
|
|
|
|
|
const noElPrefixFile = /(utils|directives|hooks|locale)/
|
2021-06-30 14:19:38 +08:00
|
|
|
const getOutFile = (name, dir = 'lib') => {
|
2021-06-03 13:05:21 +08:00
|
|
|
const compName = name.split('@element-plus/')[1]
|
2021-06-30 14:19:38 +08:00
|
|
|
if (noElPrefixFile.test(name)) {
|
2021-06-03 13:05:21 +08:00
|
|
|
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)
|
2020-10-20 11:45:44 +08:00
|
|
|
const inputs = getPackagesSync()
|
2021-09-04 19:29:28 +08:00
|
|
|
.map((pkg) => pkg.name)
|
|
|
|
.filter((name) => name.includes('@element-plus') && !name.includes('utils'))
|
2020-10-20 11:45:44 +08:00
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
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-')
|
|
|
|
}
|
|
|
|
},
|
2020-09-30 18:21:47 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +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-')
|
|
|
|
}
|
|
|
|
},
|
2021-06-03 13:05:21 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
],
|
2020-10-20 11:45:44 +08:00
|
|
|
plugins: [
|
|
|
|
css(),
|
|
|
|
vue({
|
|
|
|
target: 'browser',
|
2021-08-24 13:36:48 +08:00
|
|
|
// css: false,
|
2020-10-20 11:45:44 +08:00
|
|
|
}),
|
2021-06-03 13:05:21 +08:00
|
|
|
nodeResolve(),
|
|
|
|
esbuild(),
|
2020-10-20 11:45:44 +08:00
|
|
|
],
|
|
|
|
external(id) {
|
2021-09-04 19:29:28 +08:00
|
|
|
return (
|
|
|
|
/^vue/.test(id) ||
|
|
|
|
/^@element-plus/.test(id) ||
|
|
|
|
deps.some((k) => new RegExp('^' + k).test(id))
|
|
|
|
)
|
2020-10-20 11:45:44 +08:00
|
|
|
},
|
|
|
|
}))
|