我正在尝试为HtmlWebpackPlugin
编写打字稿声明文件,但是我无法正常工作。输出类的NodeJS模块的TypeScript声明
HtmlWebpackPlugin
默认导出是类HtmlWebpackPlugin
的构造函数。我打算像这样使用它。
somefile.ts
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
new HtmlWebpackPlugin({..some options...})
我试图将其定义如下
shim.d.ts
/// <reference path="./shim.d.ts"/>
declare module 'html-webpack-plugin' {
interface Options {
title: string,
filename: string,
template: string,
inject: (boolean | 'head' | 'body'),
favicon: string,
hash: boolean,
cache: boolean,
showErrors: boolean,
chunks: any,
chunksSortMode: ('none' | 'auto' | 'dependency'),
excludeChunks: any,
xhtml: boolean
}
class HtmlWebpackPlugin {
constructor(options: Options);
}
export default ???
}
我不知道在???
填写在这里。我尝试导出HtmlWebpackPlugin
,typeof HtmlWebpackPlugin
,但没有任何效果。它给我以下类型的错误。
我不认为这项工作。 HtmlWebpackPlugin是Node.JS中的默认导出,因此声明中HtmlWebpackPlugin的导出也应该是默认的。 –
我已经更新了我的问题,以防你想看看 –
是的,你是对的,这将无法正常工作'new HtmlWebpackPlugin({.. some options ...})',我检查了是否使用'import * as X从“html-webpack-plugin”;'然后'new X.HtmlWebpackPlugin({..})'工作。让我试试看它是否可以直接使用。 –