mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 20:00:05 +02:00
update minify
This commit is contained in:
36
node_modules/minify/ChangeLog
generated
vendored
36
node_modules/minify/ChangeLog
generated
vendored
@@ -1,3 +1,39 @@
|
||||
2020.01.22, v5.1.0
|
||||
|
||||
feature:
|
||||
- (package) eslint-plugin-node v11.0.0
|
||||
- (package) nyc v15.0.0
|
||||
- (minify) add ability to pass options to HTML, JS, CSS and IMG parsers (#52)
|
||||
|
||||
|
||||
2019.12.18, v5.0.0
|
||||
|
||||
feature:
|
||||
- (minify) drop support of node < 10
|
||||
- (package) putout v7.3.1
|
||||
- (package) eslint-plugin-node v10.0.0
|
||||
- (package) eslint-plugin-putout v3.0.0
|
||||
- (package) madrun v5.0.1
|
||||
- (package) try-to-catch v2.0.0
|
||||
|
||||
|
||||
2019.07.11, v4.1.3
|
||||
|
||||
feature:
|
||||
- (minify) forEach -> for-of
|
||||
|
||||
|
||||
2019.06.23, v4.1.2
|
||||
|
||||
feature:
|
||||
- (package) html-minifier v4.0.0
|
||||
- (package) terser v4.0.0
|
||||
- (package) eslint v6.0.0
|
||||
- (minify) add madrun
|
||||
- (package) eslint-plugin-node v9.1.0
|
||||
- (package) nyc v14.1.1
|
||||
|
||||
|
||||
2019.02.22, v4.1.1
|
||||
|
||||
fix:
|
||||
|
2
node_modules/minify/LICENSE
generated
vendored
2
node_modules/minify/LICENSE
generated
vendored
@@ -1,6 +1,6 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012-2016 Coderaiser <mnemonic.enemy@gmail.com>
|
||||
Copyright (c) 2012-2019 Coderaiser <mnemonic.enemy@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
60
node_modules/minify/README.md
generated
vendored
60
node_modules/minify/README.md
generated
vendored
@@ -42,8 +42,14 @@ const hello="world";for(let l=0;l<hello.length;l++)console.log(hello[l]);
|
||||
|
||||
```js
|
||||
const minify = require('minify');
|
||||
const options = {
|
||||
html: {
|
||||
removeAttributeQuotes: false,
|
||||
removeOptionalTags: false
|
||||
},
|
||||
};
|
||||
|
||||
minify('./client.js')
|
||||
minify('./client.js', options)
|
||||
.then(console.log)
|
||||
.catch(console.error);
|
||||
|
||||
@@ -54,9 +60,15 @@ Or with `async-await` and [try-to-catch](https://github.com/coderaiser/try-to-ca
|
||||
```js
|
||||
const minify = require('minify');
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const options = {
|
||||
html: {
|
||||
removeAttributeQuotes: false,
|
||||
removeOptionalTags: false
|
||||
}
|
||||
};
|
||||
|
||||
async () => {
|
||||
const [error, data] = await tryToCatch(minify, './client.js');
|
||||
const [error, data] = await tryToCatch(minify, './client.js', options);
|
||||
|
||||
if (error)
|
||||
return console.error(error.message);
|
||||
@@ -65,6 +77,50 @@ async () => {
|
||||
}();
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
The options object accepts configuration for `html`, `css`, `js`, and `img` like so:
|
||||
|
||||
```js
|
||||
const options = {
|
||||
html: {
|
||||
removeAttributeQuotes: false,
|
||||
},
|
||||
css: {
|
||||
compatibility: '*',
|
||||
},
|
||||
js: {
|
||||
ecma: 5,
|
||||
},
|
||||
img: {
|
||||
maxSize: 4096,
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
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:
|
||||
- HTML: https://github.com/kangax/html-minifier
|
||||
- CSS: https://github.com/jakubpawlowicz/clean-css
|
||||
- JS: https://github.com/terser/terser
|
||||
- IMG: https://github.com/Filirom1/css-base64-images
|
||||
|
||||
Minify sets a few defaults for HTML that may differ from the base `html-minifier` settings:
|
||||
- removeComments: true
|
||||
- removeCommentsFromCDATA: true
|
||||
- removeCDATASectionsFromCDATA: true
|
||||
- collapseWhitespace: true
|
||||
- collapseBooleanAttributes: true
|
||||
- removeAttributeQuotes: true
|
||||
- removeRedundantAttributes: true
|
||||
- useShortDoctype: true
|
||||
- removeEmptyAttributes: true
|
||||
- removeEmptyElements: false
|
||||
- removeOptionalTags: true
|
||||
- removeScriptTypeAttributes: true
|
||||
- removeStyleLinkTypeAttributes: true
|
||||
- minifyJS: true
|
||||
- minifyCSS: true
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
11
node_modules/minify/bin/minify.js
generated
vendored
Normal file → Executable file
11
node_modules/minify/bin/minify.js
generated
vendored
Normal file → Executable file
@@ -14,7 +14,7 @@ const Argv = process.argv;
|
||||
const files = Argv.slice(2);
|
||||
const [In] = files;
|
||||
|
||||
log.error = function(e) {
|
||||
log.error = (e) => {
|
||||
console.error(e);
|
||||
process.stdin.pause();
|
||||
};
|
||||
@@ -27,7 +27,7 @@ process.on('uncaughtException', (error) => {
|
||||
minify();
|
||||
|
||||
function readStd(callback) {
|
||||
const stdin = process.stdin;
|
||||
const {stdin} = process;
|
||||
let chunks = '';
|
||||
const read = () => {
|
||||
const chunk = stdin.read();
|
||||
@@ -66,9 +66,10 @@ function processStream(chunks) {
|
||||
const name = In.replace('--', '');
|
||||
|
||||
const [e, data] = tryCatch(minify[name], chunks);
|
||||
|
||||
if (e)
|
||||
return log.error(e);
|
||||
|
||||
|
||||
log(data);
|
||||
}
|
||||
|
||||
@@ -93,8 +94,8 @@ function help() {
|
||||
console.log(usage);
|
||||
console.log('Options:');
|
||||
|
||||
Object.keys(bin).forEach((name) => {
|
||||
for (const name of Object.keys(bin)) {
|
||||
console.log(' %s %s', name, bin[name]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
8
node_modules/minify/lib/css.js
generated
vendored
8
node_modules/minify/lib/css.js
generated
vendored
@@ -1,4 +1,5 @@
|
||||
/* сжимаем код через clean-css */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
@@ -8,14 +9,17 @@ const Clean = require('clean-css');
|
||||
* minify css data.
|
||||
*
|
||||
* @param data
|
||||
* @param userOptions - (optional) object that may contain a `css` key with an object of options
|
||||
*/
|
||||
module.exports = (data) => {
|
||||
module.exports = (data, userOptions) => {
|
||||
assert(data);
|
||||
|
||||
const options = userOptions && userOptions.css || {};
|
||||
|
||||
const {
|
||||
styles,
|
||||
errors,
|
||||
} = new Clean().minify(data);
|
||||
} = new Clean(options).minify(data);
|
||||
|
||||
const [error] = errors;
|
||||
|
||||
|
15
node_modules/minify/lib/html.js
generated
vendored
15
node_modules/minify/lib/html.js
generated
vendored
@@ -5,7 +5,7 @@
|
||||
const assert = require('assert');
|
||||
const Minifier = require('html-minifier');
|
||||
|
||||
const Options = {
|
||||
const defaultOptions = {
|
||||
removeComments: true,
|
||||
removeCommentsFromCDATA: true,
|
||||
removeCDATASectionsFromCDATA: true,
|
||||
@@ -25,18 +25,23 @@ const Options = {
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
|
||||
minifyJS: true,
|
||||
minifyCSS: true
|
||||
minifyCSS: true,
|
||||
};
|
||||
|
||||
/**
|
||||
* minify html data.
|
||||
*
|
||||
* @param data
|
||||
* @param callback
|
||||
* @param userOptions - (optional) object that may contain an `html` key with an object of options
|
||||
*/
|
||||
module.exports = (data) => {
|
||||
module.exports = (data, userOptions) => {
|
||||
assert(data);
|
||||
|
||||
return Minifier.minify(data, Options);
|
||||
const options = {
|
||||
...defaultOptions,
|
||||
...userOptions && userOptions.html || {},
|
||||
};
|
||||
|
||||
return Minifier.minify(data, options);
|
||||
};
|
||||
|
||||
|
22
node_modules/minify/lib/img.js
generated
vendored
22
node_modules/minify/lib/img.js
generated
vendored
@@ -2,15 +2,15 @@
|
||||
|
||||
const path = require('path');
|
||||
const assert = require('assert');
|
||||
const {
|
||||
promisify,
|
||||
} = require('util');
|
||||
const {promisify} = require('util');
|
||||
|
||||
const fromString = promisify(require('css-b64-images').fromString);
|
||||
|
||||
const ONE_KB = Math.pow(2, 10);
|
||||
const ONE_KB = 2 ** 10;
|
||||
|
||||
const maxSize = 100 * ONE_KB;
|
||||
const defaultOptions = {
|
||||
maxSize: 100 * ONE_KB,
|
||||
};
|
||||
|
||||
/**
|
||||
* minify css data.
|
||||
@@ -18,16 +18,20 @@ const maxSize = 100 * ONE_KB;
|
||||
*
|
||||
* @param name
|
||||
* @param data
|
||||
* @param userOptions - (optional) object that may contain an `img` key with an object of options
|
||||
*/
|
||||
module.exports = async (name, data) => {
|
||||
module.exports = async (name, data, userOptions) => {
|
||||
const dir = path.dirname(name);
|
||||
const dirRelative = dir + '/../';
|
||||
|
||||
const options = {
|
||||
...defaultOptions,
|
||||
...userOptions && userOptions.img || {},
|
||||
};
|
||||
|
||||
assert(name);
|
||||
assert(data);
|
||||
|
||||
return fromString(data, dir, dirRelative, {
|
||||
maxSize
|
||||
});
|
||||
return fromString(data, dir, dirRelative, options);
|
||||
};
|
||||
|
||||
|
7
node_modules/minify/lib/js.js
generated
vendored
7
node_modules/minify/lib/js.js
generated
vendored
@@ -7,14 +7,17 @@ const assert = require('assert');
|
||||
* minify js data.
|
||||
*
|
||||
* @param data
|
||||
* @param userOptions - (optional) object that may contain a `js` key with an object of options
|
||||
*/
|
||||
module.exports = (data) => {
|
||||
module.exports = (data, userOptions) => {
|
||||
assert(data);
|
||||
|
||||
const options = userOptions && userOptions.js || {};
|
||||
|
||||
const {
|
||||
error,
|
||||
code,
|
||||
} = terser.minify(data);
|
||||
} = terser.minify(data, options);
|
||||
|
||||
if (error)
|
||||
throw error;
|
||||
|
34
node_modules/minify/lib/minify.js
generated
vendored
34
node_modules/minify/lib/minify.js
generated
vendored
@@ -2,20 +2,16 @@
|
||||
|
||||
const DIR = __dirname + '/';
|
||||
|
||||
const fs = require('fs');
|
||||
const {readFile} = require('fs').promises;
|
||||
const path = require('path');
|
||||
const {
|
||||
promisify,
|
||||
} = require('util');
|
||||
|
||||
const tryToCatch = require('try-to-catch');
|
||||
const readFile = promisify(fs.readFile);
|
||||
|
||||
const log = require('debug')('minify');
|
||||
|
||||
['js', 'html', 'css', 'img'].forEach((name) => {
|
||||
for (const name of ['js', 'html', 'css', 'img']) {
|
||||
minify[name] = require(DIR + name);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = minify;
|
||||
|
||||
@@ -24,7 +20,7 @@ function check(name) {
|
||||
throw Error('name could not be empty!');
|
||||
}
|
||||
|
||||
async function minify(name) {
|
||||
async function minify(name, userOptions) {
|
||||
const EXT = ['js', 'html', 'css'];
|
||||
|
||||
check(name);
|
||||
@@ -36,7 +32,7 @@ async function minify(name) {
|
||||
throw Error(`File type "${ext}" not supported.`);
|
||||
|
||||
log('optimizing ' + path.basename(name));
|
||||
return optimize(name);
|
||||
return optimize(name, userOptions);
|
||||
}
|
||||
|
||||
function getName(file) {
|
||||
@@ -51,9 +47,10 @@ function getName(file) {
|
||||
/**
|
||||
* function minificate js,css and html files
|
||||
*
|
||||
* @param files - js, css or html file path
|
||||
* @param {string} file - js, css or html file path
|
||||
* @param {object} userOptions - object with optional `html`, `css, `js`, and `img` keys, which each can contain options to be combined with defaults and passed to the respective minifier
|
||||
*/
|
||||
async function optimize(file) {
|
||||
async function optimize(file, userOptions) {
|
||||
check(file);
|
||||
|
||||
const name = getName(file);
|
||||
@@ -61,23 +58,26 @@ async function optimize(file) {
|
||||
log('reading file ' + path.basename(name));
|
||||
|
||||
const data = await readFile(name, 'utf8');
|
||||
return onDataRead(file, data);
|
||||
return onDataRead(file, data, userOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processing of files
|
||||
* @param fileData {name, data}
|
||||
* Processing of files
|
||||
* @param {string} filename
|
||||
* @param {string} data - the contents of the file
|
||||
* @param {object} userOptions - object with optional `html`, `css, `js`, and `img` keys, which each can contain options to be combined with defaults and passed to the respective minifier
|
||||
*/
|
||||
async function onDataRead(filename, data) {
|
||||
async function onDataRead(filename, data, userOptions) {
|
||||
log('file ' + path.basename(filename) + ' read');
|
||||
|
||||
const ext = path.extname(filename).replace(/^\./, '');
|
||||
|
||||
const optimizedData = await minify[ext](data);
|
||||
const optimizedData = await minify[ext](data, userOptions);
|
||||
|
||||
let b64Optimize;
|
||||
|
||||
if (ext === 'css')
|
||||
[, b64Optimize] = await tryToCatch(minify.img, filename, optimizedData);
|
||||
[, b64Optimize] = await tryToCatch(minify.img, filename, optimizedData, userOptions);
|
||||
|
||||
return b64Optimize || optimizedData;
|
||||
}
|
||||
|
60
node_modules/minify/package.json
generated
vendored
60
node_modules/minify/package.json
generated
vendored
@@ -1,27 +1,28 @@
|
||||
{
|
||||
"_from": "minify@^4.1.1",
|
||||
"_id": "minify@4.1.1",
|
||||
"_from": "minify",
|
||||
"_id": "minify@5.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-D99KM2lBtJbAAAtKkekL5R1rCFQqhx2dMeFl5etybEdTwGjMYvPsWPDH0CSxTXWSmI2Q7Tx7Gx4rRxik5ahgQA==",
|
||||
"_integrity": "sha512-qlvHtYYjhDpdp05jfxFEdZ7u37tqaltOuuH4TbqyEcjubpY5BBOesJa513wBwjOFI0GmrLVENLooGRX/j2IoDQ==",
|
||||
"_location": "/minify",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "minify@^4.1.1",
|
||||
"raw": "minify",
|
||||
"name": "minify",
|
||||
"escapedName": "minify",
|
||||
"rawSpec": "^4.1.1",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^4.1.1"
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/minify/-/minify-4.1.1.tgz",
|
||||
"_shasum": "06d7a6faf5c171ac3075b79e5afdbe606c0c1fe5",
|
||||
"_spec": "minify@^4.1.1",
|
||||
"_where": "F:\\projects\\p\\minifyfromhtml",
|
||||
"_resolved": "https://registry.npmjs.org/minify/-/minify-5.1.0.tgz",
|
||||
"_shasum": "ccfd406c8b37eecc32db49cb894f6e87d7cd4efd",
|
||||
"_spec": "minify",
|
||||
"_where": "/home/s2/Code/minifyfromhtml",
|
||||
"author": {
|
||||
"name": "coderaiser",
|
||||
"email": "mnemonic.enemy@gmail.com",
|
||||
@@ -38,24 +39,25 @@
|
||||
"clean-css": "^4.1.6",
|
||||
"css-b64-images": "~0.2.5",
|
||||
"debug": "^4.1.0",
|
||||
"html-minifier": "^3.0.1",
|
||||
"terser": "^3.16.1",
|
||||
"html-minifier": "^4.0.0",
|
||||
"terser": "^4.0.0",
|
||||
"try-catch": "^2.0.0",
|
||||
"try-to-catch": "^1.0.2"
|
||||
"try-to-catch": "^2.0.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Minifier of js, css, html and img",
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.0",
|
||||
"eslint": "^5.7.0",
|
||||
"eslint-plugin-node": "^8.0.0",
|
||||
"nyc": "^13.1.0",
|
||||
"redrun": "^7.0.2",
|
||||
"rimraf": "^2.6.1",
|
||||
"tape": "^4.2.2"
|
||||
"eslint": "^6.0.0",
|
||||
"eslint-plugin-node": "^11.0.0",
|
||||
"eslint-plugin-putout": "^3.0.0",
|
||||
"madrun": "^5.0.1",
|
||||
"nyc": "^15.0.0",
|
||||
"putout": "^7.3.1",
|
||||
"supertape": "^1.2.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8.0.0"
|
||||
"node": ">= 10"
|
||||
},
|
||||
"homepage": "http://coderaiser.github.io/minify",
|
||||
"keywords": [
|
||||
@@ -78,12 +80,14 @@
|
||||
"url": "git+ssh://git@github.com/coderaiser/minify.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "nyc npm test",
|
||||
"lint": "redrun lint:*",
|
||||
"lint:bin": "eslint --rule no-console:0 bin",
|
||||
"lint:lib": "eslint lib test",
|
||||
"report": "nyc report --reporter=text-lcov | coveralls",
|
||||
"test": "tape test/minify.js"
|
||||
"coverage": "madrun coverage",
|
||||
"fix:lint": "madrun fix:lint",
|
||||
"lint": "madrun lint",
|
||||
"lint:bin": "madrun lint:bin",
|
||||
"lint:lib": "madrun lint:lib",
|
||||
"putout": "madrun putout",
|
||||
"report": "madrun report",
|
||||
"test": "madrun test"
|
||||
},
|
||||
"version": "4.1.1"
|
||||
"version": "5.1.0"
|
||||
}
|
||||
|
Reference in New Issue
Block a user