Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create concatenated .d.ts with webpack

I'd wish to build my TypeScript project (in Visual Studio) with the following automated steps:

  1. compile each .ts file as an AMD module, separately
  2. bundle each created .js file with webpack, into release/my-app.js

As part of step 1, .d.ts files are also created for each .ts file (in addition to the output Javascript files). How may I bundle these definition files together as well, so that they provide type definitions for what gets bundled into the my-app.js output file?


project layout

MyApp
|-- lib
|   |-- foo.ts
|   |-- foo.js
|   |-- foo.d.ts
|   `-- ...
|-- release
|   `-- my-app.js
|-- main.ts
|-- main.js
|-- main.d.ts
`-- webpack.config.js

webpack.config.js

module.exports = {
    context: __dirname,
    entry: './main.js',
    output: {
        path: path.join(__dirname, 'release'),
        filename: 'my-app.js'
    }
}
like image 661
John Weisz Avatar asked Oct 30 '22 05:10

John Weisz


1 Answers

You could try https://www.npmjs.com/package/dts-bundle, but this is experimental and it does not work well with awesome-typescript-loader.

like image 160
Stef Heyenrath Avatar answered Nov 09 '22 07:11

Stef Heyenrath