feat(minify): new definition (#47290)

- definition file
- tests

https://github.com/coderaiser/minify

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-09-08 14:00:00 +02:00 committed by GitHub
parent 8d3bdc7cde
commit b4596f89b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 0 deletions

46
types/minify/index.d.ts vendored Normal file
View File

@ -0,0 +1,46 @@
// Type definitions for minify 5.1
// Project: http://coderaiser.github.io/minify
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// 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<string>;
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;

View File

@ -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<string>
minify('./client.js', options); // $ExpectType Promise<string>
(async () => {
const data = await minify('./client.js', options); // $ExpectType string
})();

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"terser": "^5.3.0"
}
}

View File

@ -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"
]
}

1
types/minify/tslint.json Normal file
View File

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