Skip to content

Commit 6637857

Browse files
committed
Add TypeScript definitions
1 parent 0768e38 commit 6637857

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.0.15",
44
"description": "lets you define html tags to inject with html-webpack-plugin",
55
"main": "index.js",
6+
"types": "typings.d.ts",
67
"engines": {
78
"node": ">=8"
89
},

typings.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Compiler } from 'webpack';
2+
3+
export = HtmlWebpackTagsPlugin;
4+
5+
declare class HtmlWebpackTagsPlugin {
6+
constructor(options?: HtmlWebpackTagsPlugin.Options);
7+
8+
apply(compiler: Compiler): void;
9+
}
10+
11+
declare namespace HtmlWebpackTagsPlugin {
12+
type AddHashFunction = (assetPath: string, hash: string) => string;
13+
type AddPublicPathFunction = (assetPath: string, publicPath: string) => string;
14+
type TypeString = 'css' | 'js';
15+
type AttributesObject = { [attributeName: string]: string | boolean | number };
16+
17+
interface CommonOptions {
18+
append?: boolean;
19+
useHash?: boolean;
20+
addHash?: AddHashFunction
21+
hash?: boolean | string | AddHashFunction;
22+
usePublicPath?: boolean;
23+
addPublicPath?: AddPublicPathFunction
24+
publicPath?: boolean | string | AddPublicPathFunction;
25+
}
26+
27+
interface Options extends CommonOptions {
28+
append?: boolean;
29+
prependExternals?: boolean;
30+
jsExtensions?: string | string[];
31+
cssExtensions?: string | string[];
32+
files?: string[];
33+
tags?: string | MaybeLinkTagOptions | MaybeScriptTagOptions | Array<string | MaybeLinkTagOptions | MaybeScriptTagOptions>;
34+
links?: string | LinkTagOptions | Array<string | LinkTagOptions>;
35+
scripts?: string | ScriptTagOptions | Array<string | ScriptTagOptions>;
36+
metas?: string | MetaTagOptions | Array<string | MetaTagOptions>;
37+
}
38+
39+
interface ExternalObject {
40+
packageName: string;
41+
variableName: string;
42+
}
43+
44+
interface BaseTagOptions extends CommonOptions {
45+
glob?: string;
46+
globPath?: string;
47+
globFlatten?: boolean;
48+
sourcePath?: string;
49+
}
50+
51+
interface LinkTagOptions extends BaseTagOptions {
52+
path: string;
53+
attributes?: AttributesObject;
54+
}
55+
56+
interface ScriptTagOptions extends BaseTagOptions {
57+
path: string;
58+
attributes?: AttributesObject;
59+
external?: ExternalObject
60+
}
61+
62+
interface MaybeLinkTagOptions extends LinkTagOptions {
63+
type?: TypeString;
64+
}
65+
66+
interface MaybeScriptTagOptions extends ScriptTagOptions {
67+
type?: TypeString;
68+
}
69+
70+
interface MetaTagOptions extends BaseTagOptions {
71+
path?: string;
72+
attributes: AttributesObject;
73+
}
74+
}

0 commit comments

Comments
 (0)