2.0.0 • Published 5 years ago

dts-generator-optimizer v2.0.0

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
5 years ago

dts-generator-optimizer

Integrates with gulp to optimizes typescript declaration files generated with dts-generator.

What it does

  • Remove private class members declarations;
  • Parses all dynamic import() statements, removes inline imports, and injects external import paths to the top of the file;
  • Parses all external import statements, removes duplicates among them, and injects the result in alphabetical order at the top of the file;
  • Removes /// <references /> directives;
  • Compresses all declare module 'internal/path/in/project' {...} statements inside a single declare module ${moduleName} {...} statement;
  • Exports the declarations as a commonjs, AMD, and UMD modules so it can be imported everywhere;
  • Remove unecessary blanklines;

Installation

npm i -D dts-generator-optimizer

Usage

Simple gulp configuration example.

const dtsGenerator = require('dts-generator');
const optimizeDeclarations = require('dts-generator-optimizer');

gulp.task('declarations', (done) => {
    runSequence('declarations:generate', 'declarations:optimize', done);
});

gulp.task('declarations:generate', () =>
    dtsGenerator.default({
        project: './',
        out: 'dist/my-project.d.ts',
        exclude: ['node_modules/**/*.d.ts', 'types/**/*.d.ts'],
    });
);

gulp.task('declarations:optimize', () =>
    gulp.src('dist/my-project.d.ts')
        .pipe(optimizeDeclarations({
            libraryName: 'ReactVapor',
            externalTypesToExport: ['redux-thunk'],
            internalImportPaths: ['src/', 'docs/'],
        }))
        .pipe(gulp.dest('dist'));
);

Options

  • libraryName: string: The name of the exported UMD variable.
  • internalImportPaths: RegExp[]: The import paths internal to your projects that will be parsed out and combined in a single module.
  • externalTypesToExport: string[]: The external library names whose types need to be exported.
2.0.0

5 years ago

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago