Skip to content

Commit

Permalink
Merge pull request #410 from srod/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master: 3.4.0
  • Loading branch information
srod authored Aug 23, 2018
2 parents d407b21 + 2d0e6b7 commit bc93aba
Show file tree
Hide file tree
Showing 15 changed files with 605 additions and 146 deletions.
21 changes: 17 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,30 @@

# Features

It allow you to compress JavaScript and CSS files.
It allow you to compress JavaScript, CSS and HTML files.

**JavaScript:**

- [babel-minify](https://node-minify.2clics.net/compressors/babel-minify.html)
- [YUI Compressor](https://node-minify.2clics.net/compressors/yui.html)
- [Google Closure Compiler](https://node-minify.2clics.net/compressors/gcc.html)
- [uglify-es](https://node-minify.2clics.net/compressors/uglify-es.html)
- [uglify-js](https://node-minify.2clics.net/compressors/uglify-js.html)
- [uglify-es](https://node-minify.2clics.net/compressors/uglify-es.html)
- [YUI Compressor](https://node-minify.2clics.net/compressors/yui.html)

**CSS:**

- [clean-css](https://node-minify.2clics.net/compressors/clean-css.html)
- [crass](https://node-minify.2clics.net/compressors/crass.html)
- [CSSO](https://node-minify.2clics.net/compressors/csso.html)
- [sqwish](https://node-minify.2clics.net/compressors/sqwish.html)
- [crass](https://node-minify.2clics.net/compressors/crass.html)
- [YUI Compressor](https://node-minify.2clics.net/compressors/yui.html)

**HTML:**

- [html-minifier](https://node-minify.2clics.net/compressors/html-minifier.html)

**Command Line Interface:**

- [CLI](https://node-minify.2clics.net/cli.html) :tada: new in version 3

## Installation
Expand Down
99 changes: 99 additions & 0 deletions __tests__/node-minify-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ var fileCSSArrayWithWildcards2 = [
__dirname + '/**/*.css'
];
var fileCSSOut = __dirname + '/../examples/public/dist/sample.css';
var oneFileHTML = __dirname + '/../examples/public/index.html';
var fileHTMLOut = __dirname + '/../examples/public/dist/index.min.html';
var filesHTMLArray = [__dirname + '/../examples/public/index.html', __dirname + '/../examples/public/index.html'];
var filesHTMLArrayWithWildcards = [
__dirname + '/../examples/public/index.html',
__dirname + '/../examples/public/index.html',
__dirname + '/../examples/public/**/*.html'
];
var filesHTMLArrayWithWildcards2 = ['index.html', 'index.html', '**/*.html'];

var tests = {
concat: [
Expand Down Expand Up @@ -403,6 +412,87 @@ var tests = {
}
}
}
],
commonhtml: [
{
it: 'should compress html with {compressor} and a single file',
minify: {
compressor: '{compressor}',
input: oneFileHTML,
output: fileHTMLOut
}
},
{
it: 'should compress html with {compressor} and a single file with a custom public folder',
minify: {
compressor: '{compressor}',
input: 'index.html',
output: fileHTMLOut,
publicFolder: __dirname + '/../examples/public/'
}
},
{
it: 'should compress html with {compressor} and a single file with empty options',
minify: {
compressor: '{compressor}',
input: oneFileHTML,
output: fileHTMLOut,
options: {}
}
},
{
it: 'should compress html with {compressor} and an array of file',
minify: {
compressor: '{compressor}',
input: filesHTMLArray,
output: fileHTMLOut
}
},
{
it: 'should compress html with {compressor} and an array of file with a custom public folder',
minify: {
compressor: '{compressor}',
input: ['index.html', 'index.html'],
output: fileHTMLOut,
publicFolder: __dirname + '/../examples/public/'
}
},
{
it: 'should compress javascript with {compressor} and wildcards path',
minify: {
compressor: '{compressor}',
input: __dirname + '/../examples/public/**/*.html',
output: fileHTMLOut
}
},
{
it: 'should compress html with {compressor} and wildcards path with a custom public folder',
minify: {
compressor: '{compressor}',
input: '**/*.html',
output: fileHTMLOut,
publicFolder: __dirname + '/../examples/public/'
}
},
{
it: 'should compress html with {compressor} and an array of strings and wildcards path',
minify: {
compressor: '{compressor}',
input: filesHTMLArrayWithWildcards,
output: fileHTMLOut
}
},
{
it:
'should compress html with {compressor} and an array of strings and wildcards path' +
' with a custom public folder',
minify: {
compressor: '{compressor}',
input: filesHTMLArrayWithWildcards2,
output: fileHTMLOut,
publicFolder: __dirname + '/../examples/public/'
}
}
]
};

Expand Down Expand Up @@ -887,6 +977,15 @@ describe('node-minify', function() {
});
});

describe('html-minifier', function() {
tests.commonhtml.forEach(function(o) {
runOneTest(o, 'html-minifier');
});
tests.commonhtml.forEach(function(o) {
runOneTest(o, 'html-minifier', true);
});
});

describe('YUI', function() {
tests.commonjs.forEach(function(o) {
runOneTest(o, 'yui-js');
Expand Down
2 changes: 2 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ program
.option('-c, --compressor [compressor]', 'use the specified compressor [uglifyjs]', 'uglifyjs')
.option('-i, --input [file]', 'input file path')
.option('-o, --output [file]', 'output file path')
.option('-s, --silence', 'no output will be printed')
.option('-O, --option [option]', 'option for the compressor as JSON object', '');

program.on('--help', function() {
Expand All @@ -26,6 +27,7 @@ program.on('--help', function() {
console.log(' - babel-minify');
console.log(' - butternut');
console.log(' - gcc');
console.log(' - html-minifier');
console.log(' - uglifyjs');
console.log(' - uglify-es');
console.log(' - yui');
Expand Down
6 changes: 5 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Features

It allow you to compress JavaScript and CSS files.
It allow you to compress JavaScript, CSS and HTML files.

**JavaScript:**

Expand All @@ -22,6 +22,10 @@ It allow you to compress JavaScript and CSS files.
- [sqwish](/compressors/sqwish.md)
- [YUI Compressor](/compressors/yui.md)

**HTML:**

- [html-minifier](/compressors/html-minifier.md)

**Command Line Interface:**

- [CLI](/cli.md) :tada: new in version 3
Expand Down
32 changes: 32 additions & 0 deletions docs/compressors/html-minifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# html-minifier

`html-minifier` can compress only HTML files.

[https://github.com/kangax/html-minifier](https://github.com/kangax/html-minifier)

## Usage

```js
compressor.minify({
compressor: 'html-minifier',
input: 'foo.html',
output: 'bar.html',
callback: function(err, min) {}
});
```

## Options

```js
compressor.minify({
compressor: 'html-minifier',
input: 'foo.html',
output: 'bar.html',
options: {
removeAttributeQuotes: true
},
callback: function(err, min) {}
});
```

[Check all options](https://github.com/kangax/html-minifier)
53 changes: 53 additions & 0 deletions examples/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link href="/favicons/favicon.ico" rel="shortcut icon">
<link rel="apple-touch-icon" sizes="57x57" href="/favicons/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/favicons/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/favicons/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/favicons/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/favicons/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/favicons/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/favicons/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/favicons/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/favicons/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicons/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/favicons/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<title></title>
<link rel="stylesheet" href="/styles.css">
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js').then(function () {
console.log("Service Worker Registered");
});
}
</script>
<link rel="manifest" href="/manifest.json">
</head>

<body>
<section class="container">
<div class="content">
</div>
</section>

<script src="https://unpkg.com/tippy.js@2.5.4/dist/tippy.all.min.js"></script>
<script async src="/scripts.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-65399-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
</script>
</body>

</html>
14 changes: 14 additions & 0 deletions examples/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ compressor.minify({
});
console.log('sync 3');

compressor
.minify({
compressor: 'html-minifier',
input: 'public/index.html',
output: 'public/dist/index.min.html',
options: {
minifyJS: false
}
})
.then(function(min) {
console.log('html min');
console.log(min);
});

compressor
.minify({
compressor: 'butternut',
Expand Down
33 changes: 23 additions & 10 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var chalk = require('chalk');
var deprecate = require('depd')('node-minify');
var compress = require('./compress');
var spinner = require('./spinner');
var silence = false;

/**
* Run one compressor.
Expand All @@ -31,15 +32,21 @@ function runOne(cli, compressor) {
options.options = JSON.parse(cli.option);
}

spinner.start(options);
if (!silence) {
spinner.start(options);
}

return compress(options)
.then(function(result) {
spinner.stop(result);
if (!silence) {
spinner.stop(result);
}
resolve(result);
})
.catch(function(err) {
spinner.error(options);
if (!silence) {
spinner.error(options);
}
reject(err);
});
});
Expand All @@ -50,22 +57,28 @@ function runOne(cli, compressor) {
*/

function run(cli) {
console.log('');
console.log(chalk.bgBlue.black(' INFO '), 'Starting compression...');
console.log('');
silence = !!cli.silence;

if (!silence) {
console.log('');
console.log(chalk.bgBlue.black(' INFO '), 'Starting compression...');
console.log('');
}

return new Promise(function(resolve, reject) {
if (cli.compressor === 'all') {
deprecate('all is deprecated, babel-minify will be used be default');
deprecate('all is deprecated, babel-minify will be used by default');
console.log('');
cli.compressor = 'babel-minify';
}

runOne(cli, cli.compressor)
.then(function() {
console.log('');
console.log(chalk.bgGreen.black(' DONE '), chalk.green('Done!'));
console.log('');
if (!silence) {
console.log('');
console.log(chalk.bgGreen.black(' DONE '), chalk.green('Done!'));
console.log('');
}
})
.then(resolve)
.catch(reject);
Expand Down
2 changes: 2 additions & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var cleanCSS = require('./compressors/clean-css');
var csso = require('./compressors/csso');
var gcc;
var gccJava = require('./compressors/gcc-java');
var HTMLMinifier = require('./compressors/html-minifier');
var noCompress = require('./compressors/no-compress');
var sqwish = require('./compressors/sqwish');
var uglifyjs = require('./compressors/uglifyjs');
Expand Down Expand Up @@ -56,6 +57,7 @@ var compressorsMap = {
'gcc-legacy': function(settings, data, callback) {
return gccJava(settings, data, callback, true);
},
'html-minifier': HTMLMinifier,
uglifyjs: uglifyjs,
'uglify-es': uglifyES,
sqwish: sqwish,
Expand Down
1 change: 1 addition & 0 deletions lib/compressors/gcc-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var execCompressor = require('../runner');
/**
* Module variables.
*/

var binGcc = path.normalize(__dirname + '/../binaries/google_closure_compiler-v20151216.jar');
var binGccLegacy = path.normalize(__dirname + '/../binaries/google_closure_compiler-v20131014-legacy-java-1.6.jar');

Expand Down
Loading

0 comments on commit bc93aba

Please sign in to comment.