@@ -3,6 +3,7 @@ import commonjs from '@rollup/plugin-commonjs';
3
3
import typescript from '@rollup/plugin-typescript' ;
4
4
import json from '@rollup/plugin-json' ;
5
5
import fs from 'fs' ;
6
+ import path from 'path' ;
6
7
7
8
function getBrowserConfig ( ) {
8
9
const packageJson = JSON . parse ( fs . readFileSync ( './package.json' , 'utf-8' ) ) ;
@@ -45,6 +46,32 @@ function replaceFiles(options = {}) {
45
46
} ;
46
47
}
47
48
49
+ function cleanupTypeScript ( options = { } ) {
50
+ const { tsconfig } = options ;
51
+ const tsconfigFile = JSON . parse ( fs . readFileSync ( tsconfig , 'utf-8' ) ) ;
52
+ let tsOutputDir ;
53
+
54
+ return {
55
+ name : 'cleanup-typescript' ,
56
+ generateBundle ( outputOptions ) {
57
+ const outputDir =
58
+ outputOptions . dir ||
59
+ ( outputOptions . file
60
+ ? outputOptions . file . substring ( 0 , outputOptions . file . lastIndexOf ( '/' ) )
61
+ : 'dist' ) ;
62
+ tsOutputDir = path . resolve (
63
+ outputDir ,
64
+ tsconfigFile . compilerOptions . outDir ,
65
+ ) ;
66
+ } ,
67
+ closeBundle ( ) {
68
+ if ( tsOutputDir ) {
69
+ fs . rmSync ( tsOutputDir , { recursive : true , force : true } ) ;
70
+ }
71
+ } ,
72
+ } ;
73
+ }
74
+
48
75
export default {
49
76
input : 'src/index.ts' ,
50
77
output : {
@@ -67,5 +94,8 @@ export default {
67
94
tsconfig : './tsconfig.rollup.json' ,
68
95
} ) , // Compiles TypeScript
69
96
json ( ) , // Converts JSON files to ES6 modules
97
+ cleanupTypeScript ( {
98
+ tsconfig : './tsconfig.rollup.json' ,
99
+ } ) ,
70
100
] ,
71
101
} ;
0 commit comments