Typescript+webpack: typescript emmited no output for index.d.ts

后端 未结 2 1908
长发绾君心
长发绾君心 2021-01-19 03:23

I followed this tutorial to setup typescript+webpack (no react) with success. It all works great until I add index.d.ts file my components folder, which I use to export all

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 04:13

    In this particular question the content of index.d.ts was not a definition but a module and should have been moved into index.ts file. I've also ran into error "typescript emmited no output for index.d.ts" but with valid declaration files.

    It seems ts-loader tries to add .d.ts files to final bundle but finds nothing to add since they contain only declarations needed for type-checking during build.

    Working solution for me is not to pass .d.ts files to ts-loader but to some loader that does nothing, e. g. ignore-loader. Corresponding rules in my webpack.config.js are:

    {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        exclude: /node_modules|\.d\.ts$/
    },
    {
        test: /\.d\.ts$/,
        loader: 'ignore-loader'
    },
    

    ts-loader can be configured slightly differently if you use ES2018, where negative lookbehind for regular expressions was added:

    {
        test: /(?

提交回复
热议问题