dts-module-filter
Description
- Convert module-dts to namespace-dts
- Remove unnecessary imports from module-dts
usage
/**
*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;
})
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