Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
dtsbundler-webpack-plugin
Advanced tools
Generates a single module declaration file from separate generated declaration files from an EXTERNAL module
This library takes separate declaration asset files generated by the webpack build process and bundles them into one single declaration file. Inspired by @floyon
This plugin, with a setup as below, flattens class hierarchies in a module to a single d.ts file used by the entry point (usually index.ts) The usecase allows a module to have a single d.ts file at the root or dist/ level rather than many d.ts files scattered throughout the source folder
This plugin was developed as an extention to the ts-loader which - when declaration
is set to true
in tsconfig.json
- generates separate declaration files for each source file. In theory though, it should work with any loader which generates declaration files as output.
Here is an example setup:
//index.ts
export {default as Foo} './src/foo';
export {default as Foo2} './src/foo2';
//src/foo.ts
export default class Foo
{
bar():boolean
{
return true;
}
}
//src/foo2.ts
import Foo './foo';
export default class Foo2 extends Foo
{
bar():boolean
{
return true;
}
}
Which generates (when using the declaration=true flag for the typescript compiler)
//index.d.ts
export {default as Foo} './src/foo';
export {default as Foo2} './src/foo2';
//foo.d.ts
declare class Foo {
bar():boolean;
}
export default Foo;
//foo2.d.ts
import Foo './foo';
declare class Foo2 extends Foo {
bar():boolean;
}
export default Foo2;
Which with the following webpack.config.js
var DtsBundlerPlugin = require('dtsbundler-webpack-plugin');
module.exports = {
entry: './index.ts',
output: {
filename: './dist/index.js'
},
resolve: {
extensions: ['', '.ts', '.tsx','.webpack.js', '.web.js', '.js']
},
module: {
loaders: [
{ test: /\.ts(x?)$/, loader: 'ts-loader' }
]
},
watch:true,
plugins: [
new DtsBundlerPlugin({
out:'./dist/index.d.ts',
})
]
}
Will be turned into:
//index.d.ts
declare class Foo {
bar():boolean;
}
declare class Foo2 extends Foo {
bar():boolean;
}
With this setup and generated declaration file, other modules that want to use this module can add a reference to the generated index.d.ts. They can then access all classes of the module as if they are defined in the index.ts of the module
FAQs
Generates a single module declaration file from separate generated declaration files from an EXTERNAL module
We found that dtsbundler-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.