[assets-webpack-plugin] Add type definitions (#18650)

This commit is contained in:
Michael Strobel 2017-08-09 05:20:30 +08:00 committed by Mohamed Hegazy
parent 2fc13d9e70
commit 01427d69a6
4 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,25 @@
import * as webpack from 'webpack';
import * as AssetsPlugin from 'assets-webpack-plugin';
const config: webpack.Configuration = {
plugins: [
new AssetsPlugin(),
new AssetsPlugin({
filename: 'assets.json'
}),
new AssetsPlugin({
filename: 'assets.json',
fullPath: false,
includeManifest: true,
path: '/foo/bar',
prettyPrint: true,
processOutput: (assets) => (
'window.assets = ' + JSON.stringify(assets)
),
update: true,
metadata: {
meta: 'data'
},
})
]
};

76
types/assets-webpack-plugin/index.d.ts vendored Normal file
View File

@ -0,0 +1,76 @@
// Type definitions for assets-webpack-plugin 3.5
// Project: https://github.com/sporto/assets-webpack-plugin
// Definitions by: Michael Strobel <https://github.com/kryops>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import * as webpack from 'webpack';
declare namespace AssetsWebpackPlugin {
interface Assets {
[name: string]: {
[ext: string]: string;
};
}
type ProcessOutputFn = (assets: Assets) => string;
interface Options {
/**
* Name for the created json file.
* "webpack-assets.json" by default
*/
filename?: string;
/**
* If false the output will not include the full path of the generated file.
* true by default
*/
fullPath?: boolean;
/**
* Inserts the manifest javascript as a text property in your assets.
* Accepts the name of your manifest chunk.
* A manifest is the last CommonChunk that only contains the webpack bootstrap code.
* This is useful for production use when you want to inline the manifest
* in your HTML skeleton for long-term caching.
* false by default
*/
includeManifest?: boolean;
/**
* Inject metadata into the output file. All values will be injected into the key "metadata"
*/
metadata?: object;
/**
* Path where to save the created JSON file.
* Defaults to the current directory
*/
path?: string;
/**
* Whether to format the JSON output for readability.
* false by default
*/
prettyPrint?: boolean;
/**
* Formats the assets output.
* Defaults to JSON.stringify
*/
processOutput?: ProcessOutputFn;
/**
* When set to true, the output JSON file will be updated instead of overwritten.
* false by default
*/
update?: boolean;
}
}
declare class AssetsWebpackPlugin extends webpack.Plugin {
constructor(options?: AssetsWebpackPlugin.Options);
}
export = AssetsWebpackPlugin;

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"assets-webpack-plugin-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }