generated from thzxcx/vue3
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
/*
|
|
* @Author: zhaojinfeng 121016171@qq.com
|
|
* @Date: 2023-06-19 10:38:07
|
|
* @LastEditors: zhaojinfeng 121016171@qq.com
|
|
* @LastEditTime: 2023-06-20 16:41:47
|
|
* @FilePath: \tianheng-design\bin\build.ts
|
|
* @Description:
|
|
*
|
|
*/
|
|
/* eslint-env node */
|
|
import { resolve } from 'node:path'
|
|
import { outputFile, readdir, remove } from 'fs-extra'
|
|
import { build } from 'vite'
|
|
import { renderFile } from 'ejs'
|
|
import consola from 'consola'
|
|
|
|
function buildAComponent(name: string) {
|
|
build({
|
|
build: {
|
|
outDir: `es/${name}`,
|
|
lib: {
|
|
name: 'tianheng-design',
|
|
entry: resolve(process.cwd(), 'packages', name, 'index.vue'),
|
|
fileName: 'index',
|
|
},
|
|
rollupOptions: {
|
|
output: [
|
|
{
|
|
dir: `es/${name}`,
|
|
entryFileNames: '[name].mjs',
|
|
format: 'es',
|
|
},
|
|
{
|
|
dir: `lib/${name}`,
|
|
format: 'cjs',
|
|
// 不用打包成.mjs
|
|
entryFileNames: '[name].js',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
async function renderDTSwithESM(dir: string[]) {
|
|
const text = await renderFile(resolve(process.cwd(), './ejs/index.esm.ts.ejs'), { dir })
|
|
return Promise.all([
|
|
outputFile(resolve(process.cwd(), './es/index.mjs'), text),
|
|
outputFile(resolve(process.cwd(), './es/index.d.ts'), text),
|
|
])
|
|
}
|
|
async function renderDTSwithUMD(dir: string[]) {
|
|
const text = await renderFile(resolve(process.cwd(), './ejs/index.umd.ts.ejs'), { dir })
|
|
return Promise.all([
|
|
outputFile(resolve(process.cwd(), './lib/index.d.ts'), text),
|
|
])
|
|
}
|
|
|
|
(async function () {
|
|
const dir = await readdir(resolve(process.cwd(), './packages'))
|
|
consola.info('扫描到的目录:', dir)
|
|
|
|
await Promise.all([
|
|
remove(resolve(process.cwd(), 'es')),
|
|
remove(resolve(process.cwd(), 'lib')),
|
|
])
|
|
|
|
await Promise.all(dir.map(buildAComponent))
|
|
return Promise.all([
|
|
renderDTSwithESM(dir),
|
|
renderDTSwithUMD(dir),
|
|
])
|
|
})()
|