chore: use rollup-plugin-rm to clean dist
This commit is contained in:
parent
a48e12a9df
commit
ff23f7d44d
|
@ -88,6 +88,7 @@
|
|||
"prettier": "^3.1.0",
|
||||
"rollup": "^4.6.1",
|
||||
"rollup-plugin-dts": "^6.1.0",
|
||||
"rollup-plugin-rm": "^1.0.2",
|
||||
"simple-git-hooks": "^2.9.0",
|
||||
"tslib": "^2.6.2",
|
||||
"typescript": "^5.3.3",
|
||||
|
|
|
@ -67,6 +67,9 @@ devDependencies:
|
|||
rollup-plugin-dts:
|
||||
specifier: ^6.1.0
|
||||
version: 6.1.0(rollup@4.6.1)(typescript@5.3.3)
|
||||
rollup-plugin-rm:
|
||||
specifier: ^1.0.2
|
||||
version: 1.0.2(rollup@4.6.1)
|
||||
simple-git-hooks:
|
||||
specifier: ^2.9.0
|
||||
version: 2.9.0
|
||||
|
@ -2216,6 +2219,14 @@ packages:
|
|||
'@babel/code-frame': 7.23.5
|
||||
dev: true
|
||||
|
||||
/rollup-plugin-rm@1.0.2(rollup@4.6.1):
|
||||
resolution: {integrity: sha512-RSUFFibfkCvIeQrTg7TLs59m6S//qcmDfTNqgQ2Pd9BlABd/q74ymmg5936h0vfnjrFHhale/+f+efgp7deLEg==}
|
||||
peerDependencies:
|
||||
rollup: ^3.0.0||^4.0.0
|
||||
dependencies:
|
||||
rollup: 4.6.1
|
||||
dev: true
|
||||
|
||||
/rollup@4.6.1:
|
||||
resolution: {integrity: sha512-jZHaZotEHQaHLgKr8JnQiDT1rmatjgKlMekyksz+yk9jt/8z9quNjnKNRoaM0wd9DC2QKXjmWWuDYtM3jfF8pQ==}
|
||||
engines: {node: '>=18.0.0', npm: '>=8.0.0'}
|
||||
|
|
|
@ -1,33 +1,16 @@
|
|||
import { createRequire } from 'node:module'
|
||||
import fs from 'node:fs/promises'
|
||||
import { type Plugin, defineConfig } from 'rollup'
|
||||
import { defineConfig } from 'rollup'
|
||||
import ts from '@rollup/plugin-typescript'
|
||||
import resolve from '@rollup/plugin-node-resolve'
|
||||
import json from '@rollup/plugin-json'
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import rm from 'rollup-plugin-rm'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
const pkg = require('./package.json')
|
||||
|
||||
const external = ['esbuild', ...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})]
|
||||
|
||||
function clean(when: 'buildStart' | 'buildEnd', target: string): Plugin {
|
||||
const _clean = async (target): Promise<void> => {
|
||||
await fs.rm(target, { recursive: true, force: true }).catch(() => {})
|
||||
}
|
||||
return {
|
||||
name: 'clean',
|
||||
buildStart: async (): Promise<void> => {
|
||||
if (when !== 'buildStart') return
|
||||
await _clean(target)
|
||||
},
|
||||
buildEnd: async (): Promise<void> => {
|
||||
if (when !== 'buildEnd') return
|
||||
await _clean(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
input: ['src/index.ts', 'src/cli.ts'],
|
||||
|
@ -47,7 +30,7 @@ export default defineConfig([
|
|||
],
|
||||
external,
|
||||
plugins: [
|
||||
clean('buildStart', 'dist'),
|
||||
rm('dist', 'buildStart'),
|
||||
json(),
|
||||
ts({ compilerOptions: { rootDir: 'src', declaration: true, declarationDir: 'dist/types' } }),
|
||||
resolve()
|
||||
|
@ -59,6 +42,6 @@ export default defineConfig([
|
|||
{
|
||||
input: 'dist/types/index.d.ts',
|
||||
output: [{ file: pkg.types, format: 'es' }],
|
||||
plugins: [dts(), clean('buildEnd', 'dist/types')]
|
||||
plugins: [dts(), rm('dist/types', 'buildEnd')]
|
||||
}
|
||||
])
|
||||
|
|
Loading…
Reference in a new issue