diff --git a/types/minify/index.d.ts b/types/minify/index.d.ts new file mode 100644 index 0000000000..e93e30502c --- /dev/null +++ b/types/minify/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for minify 5.1 +// Project: http://coderaiser.github.io/minify +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import htmlMinifier = require('html-minifier'); +import cleanCSS = require('clean-css'); +import terser = require('terser'); + +/** + * A minifier of js, css, html and img files. + * @async + */ +declare function minify(name: string, options?: minify.Options): Promise; + +declare namespace minify { + /** + * Full documentation for options that each file type accepts + * can be found on the pages of the libraries used by minify to process the files + */ + interface Options { + /** + * @see {@link https://github.com/kangax/html-minifier} + */ + html?: htmlMinifier.Options; + /** + * @see {@link https://github.com/jakubpawlowicz/clean-css} + */ + css?: cleanCSS.Options; + /** + * @see {@link https://github.com/terser/terser} + */ + js?: terser.MinifyOptions; + /** + * @see {@link https://github.com/Filirom1/css-base64-images} + */ + img?: { + /** + * bigger images are not base64 in the CSS + * @default 4096 + */ + maxSize?: number; + }; + } +} + +export = minify; diff --git a/types/minify/minify-tests.ts b/types/minify/minify-tests.ts new file mode 100644 index 0000000000..92d26a011f --- /dev/null +++ b/types/minify/minify-tests.ts @@ -0,0 +1,25 @@ +import minify = require('minify'); +import { Options } from 'minify'; + +const options: Options = { + html: { + removeAttributeQuotes: false, + removeOptionalTags: false, + }, + css: { + compatibility: '*', + }, + js: { + ecma: 5, + }, + img: { + maxSize: 4096, + }, +}; + +minify('./client.js'); // $ExpectType Promise +minify('./client.js', options); // $ExpectType Promise + +(async () => { + const data = await minify('./client.js', options); // $ExpectType string +})(); diff --git a/types/minify/package.json b/types/minify/package.json new file mode 100644 index 0000000000..9b579b8314 --- /dev/null +++ b/types/minify/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "terser": "^5.3.0" + } +} diff --git a/types/minify/tsconfig.json b/types/minify/tsconfig.json new file mode 100644 index 0000000000..df220331bf --- /dev/null +++ b/types/minify/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "minify-tests.ts" + ] +} diff --git a/types/minify/tslint.json b/types/minify/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/minify/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }