Skip to content

Commit 48d1fd2

Browse files
committed
Add TypeScript definitions
Fixes #9
1 parent 6d83954 commit 48d1fd2

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

index.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type {Compiler, Compilation} from 'webpack';
2+
3+
/**
4+
Dynamically add an asset to the webpack graph.
5+
6+
@example
7+
```
8+
import AddAssetPlugin from 'add-asset-webpack-plugin';
9+
10+
export default {
11+
// …
12+
plugins: [
13+
new AddAssetPlugin('file.js', `
14+
console.log('This is a dynamically created file');
15+
`)
16+
]
17+
};
18+
```
19+
*/
20+
declare class AddAssetPlugin {
21+
/**
22+
@param filePath - Relative file path for the asset.
23+
@param source - Asset source or a function that returns the asset source. If a function, it will receive the compilation instance.
24+
*/
25+
constructor(
26+
filePath: string,
27+
source: string | ((compilation: Compilation) => string | Promise<string>)
28+
);
29+
30+
apply(compiler: Compiler): void;
31+
}
32+
33+
export default AddAssetPlugin;

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "Dynamically add an asset to the Webpack graph",
55
"license": "MIT",
66
"repository": "sindresorhus/add-asset-webpack-plugin",
7-
"funding": {
8-
"url": "https://github.com/sponsors/sindresorhus"
9-
},
7+
"funding": "https://github.com/sponsors/sindresorhus",
108
"author": {
119
"name": "Sindre Sorhus",
1210
"email": "[email protected]",
1311
"url": "https://sindresorhus.com"
1412
},
1513
"type": "module",
16-
"exports": "./index.js",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
1718
"sideEffects": false,
1819
"engines": {
1920
"node": ">=18"
@@ -22,7 +23,8 @@
2223
"test": "xo && ava"
2324
},
2425
"files": [
25-
"index.js"
26+
"index.js",
27+
"index.d.ts"
2628
],
2729
"keywords": [
2830
"webpack-plugin",

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Type: `string | (compilation => string | Promise<string>)`
3939

4040
Asset source or a function that returns the asset source.
4141

42-
If a function, it will receive the [`compilation` instance](https://webpack.js.org/api/compilation/). And if the function returns a promise, it will be awaited.
42+
If a function, it will receive the [`compilation` instance](https://webpack.js.org/api/compilation/).
4343

4444
## FAQ
4545

0 commit comments

Comments
 (0)