11import fs from 'node:fs' ;
22import path from 'node:path' ;
33import url from 'node:url' ;
4- import terser from '@rollup/plugin-terser' ;
4+ import terser , { type Options as TerserOptions } from '@rollup/plugin-terser' ;
55import typescript , { type RollupTypescriptOptions } from '@rollup/plugin-typescript' ;
66import type { OutputChunk , OutputOptions } from 'rollup' ;
77import license from 'rollup-plugin-license' ;
88import ts from 'typescript' ;
99import type { LibraryOptions , UserConfig } from 'vite' ;
1010import generateDts from './vite.plugin.dts.ts' ;
1111
12+ const terserOptions : TerserOptions = {
13+ mangle : {
14+ properties : {
15+ regex : / ^ _ /
16+ }
17+ }
18+ } ;
19+
1220const __dirname = url . fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
1321
1422let repositoryRoot = __dirname ;
@@ -128,7 +136,7 @@ export function umd(
128136 dir : 'dist/' ,
129137 format : 'umd' ,
130138 name : name ,
131- plugins : [ terser ( ) ] ,
139+ plugins : [ terser ( terserOptions ) ] ,
132140 entryFileNames : '[name].min.js' ,
133141 chunkFileNames : '[name].min.js'
134142 } ) ;
@@ -213,15 +221,15 @@ export function esm(
213221 } ,
214222 dir : 'dist/' ,
215223 format : 'es' ,
216- plugins : [ terser ( ) ] ,
224+ plugins : [ terser ( terserOptions ) ] ,
217225 entryFileNames : '[name].min.mjs' ,
218226 chunkFileNames : '[name].min.mjs'
219227 } ) ;
220228 }
221229}
222230
223231export function dtsPathsTransformer ( mapping : Record < string , string > ) {
224- const mapPath = ( filePath , input : string ) : string | undefined => {
232+ const mapPath = ( filePath : string , input : string ) : string | undefined => {
225233 for ( const [ k , v ] of Object . entries ( mapping ) ) {
226234 if ( input . startsWith ( k ) ) {
227235 const absoluteFile = path . resolve ( v , input . substring ( k . length ) ) ;
@@ -233,7 +241,7 @@ export function dtsPathsTransformer(mapping: Record<string, string>) {
233241
234242 return ( context : ts . TransformationContext ) => {
235243 return ( source : ts . SourceFile | ts . Bundle ) => {
236- const sourceFilePath = ts . isSourceFile ( source ) ? source . fileName : source . sourceFiles [ 0 ] ;
244+ const sourceFilePath = ts . isSourceFile ( source ) ? source . fileName : source . sourceFiles [ 0 ] . fileName ;
237245
238246 const visitor = ( node : ts . Node ) => {
239247 if ( ts . isExportDeclaration ( node ) && node . moduleSpecifier && ts . isStringLiteral ( node . moduleSpecifier ) ) {
0 commit comments