Skip to content

npm-packages01/dts-module-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dts-module-filter

Description

  • Convert module-dts to namespace-dts
  • Remove unnecessary imports from module-dts

usage

  • Definition
/**
 *convert module-dts to namespace-dts
 *
 * @export
 * @param {{
 *   src: string; // Source file path
 *   dest?: string; // Path of output file
 *   removeImport?:RegExp; // Conditions of import removal
 *   namespace?: string; // Name of the namespace
 * }} params
 */
export function DtsModuleFilter(params: {
  src: string;
  dest?: string;
  removeImport?:RegExp;
  namespace?: string;
})
  • call

When removing only a specific impot

filter.DtsModuleFilter({
  src: path.resolve(__dirname, "jwf.d.ts"),
  dest: path.resolve(__dirname, "temp.d.ts"), // Default is overwrite
  removeImport:/\.(scss|css)$/
});

When converting to namespace

filter.DtsModuleFilter({
  src: path.resolve(__dirname, "jwf.d.ts"),
  dest: path.resolve(__dirname, "temp.d.ts"), // Default is overwrite
  namespace:"JWF"
});

When using from WebPack

This is the description method for converting to namespace by dts-module-filter after combining files using dts-bundle

webpack.config.js

class DtsBundlePlugin {
  constructor(params) {
    this.params = params;
  }
  apply(compiler) {
    compiler.hooks.afterEmit.tap("DtsBundlePlugin", () => {
      const params = this.params;
      require("dts-bundle").bundle(params);
      require("dts-module-filter").DtsModuleFilter({
        src: params.out,
        namespace: params.name
      });
    });
  }
}

module.exports = {
  plugins: [
    new DtsBundlePlugin({
      name: "JWF",
      main: path.resolve(__dirname, "SRC-DTS"),
      out: path.resolve(__dirname, "DEST-DTS")
    })
  ]
};

License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published