rollup-plugin-hide-private
v0.4.0
Published
Remove selected private and protected members from generated declaration files.
Maintainers
Readme
rollup-plugin-hide-private
This plugin is designed for declaration build steps, especially when you bundle .d.ts output with rollup-plugin-dts.
More Rollup Plugins you might be interested in:
For more awesome packages, check out my homepage💛
Install
pnpm add -D rollup-plugin-hide-private rollup typescriptUsage
Normal
import dts from 'rollup-plugin-dts';
import hidePrivate from 'rollup-plugin-hide-private';
export default {
input: 'dist/types/index.d.ts',
output: [{ file: 'dist/index.d.ts', format: 'es', sourcemap: true }],
plugins: [
hidePrivate({
privateNames: true,
protectedNames: [/^internal/, 'debugOnly'],
publicNames: [/^debug/],
interfaces: ['__internal'],
types: [/^__typeInternal/],
allNames: ['__internal', /^debug/],
}),
dts(),
],
};The plugin only processes declaration outputs such as .d.ts, .d.mts and .d.cts.
vite-plugin-dts
Use this mode when you already have declaration files on disk and want the plugin to rewrite only selected files matched by glob patterns.
import dts from 'vite-plugin-dts';
import { stripHiddenDeclarations } from 'rollup-plugin-hide-private';
dts({
...,
beforeWriteFile: (filePath: string, content: string) => {
return { content: stripHiddenDeclarations(content, { allNames: [/^_/] }).code, filePath };
},
}),Options
interface RollupHidePrivateOptions {
// `true` by default
privateNames?: boolean | Pattern[];
// `true` by default
protectedNames?: boolean | Pattern[];
// `false` by default
publicNames?: boolean | Pattern[];
// `[]` by default
allNames?: Pattern[];
// `false` by default
interfaces?: false | Pattern[];
// `false` by default
types?: false | Pattern[];
}Effect
Before
export class AAA {
private a: number;
asdf: string = 'asdf';
_asdf: string = 'asdf';
constructor(a: number) {
this.a = a;
}
}With options:
hidePrivate({
allNames: [/^_/],
})After
declare class AAA {
asdf: string;
constructor(a: number);
}License
MIT
