diff --git a/types/assets-webpack-plugin/assets-webpack-plugin-tests.ts b/types/assets-webpack-plugin/assets-webpack-plugin-tests.ts new file mode 100644 index 0000000000..6851f853f2 --- /dev/null +++ b/types/assets-webpack-plugin/assets-webpack-plugin-tests.ts @@ -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' + }, + }) + ] +}; diff --git a/types/assets-webpack-plugin/index.d.ts b/types/assets-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..660fbc6052 --- /dev/null +++ b/types/assets-webpack-plugin/index.d.ts @@ -0,0 +1,76 @@ +// Type definitions for assets-webpack-plugin 3.5 +// Project: https://github.com/sporto/assets-webpack-plugin +// Definitions by: Michael Strobel +// 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; diff --git a/types/assets-webpack-plugin/tsconfig.json b/types/assets-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..0d71c8ce0b --- /dev/null +++ b/types/assets-webpack-plugin/tsconfig.json @@ -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" + ] +} diff --git a/types/assets-webpack-plugin/tslint.json b/types/assets-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/assets-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }