From 8f8904270e9443e84dd5e74f35a9e67912a02e28 Mon Sep 17 00:00:00 2001 From: Rodolphe Stoclin Date: Thu, 2 Aug 2018 11:43:32 +0200 Subject: [PATCH] feat(docs): add documentation --- .gitignore | 1 + Readme.md | 390 ++-------------------------- docs/.vuepress/config.js | 49 ++++ docs/.vuepress/public/manifest.json | 20 ++ docs/README.md | 41 +++ docs/cli.md | 21 ++ docs/compressors/babel-minify.md | 33 +++ docs/compressors/clean-css.md | 34 +++ docs/compressors/crass.md | 16 ++ docs/compressors/csso.md | 16 ++ docs/compressors/gcc.md | 101 +++++++ docs/compressors/sqwish.md | 30 +++ docs/compressors/uglify-es.md | 35 +++ docs/compressors/uglify-js.md | 39 +++ docs/compressors/yui.md | 65 +++++ docs/getting-started.md | 40 +++ docs/options.md | 69 +++++ package.json | 2 + 18 files changed, 628 insertions(+), 374 deletions(-) create mode 100644 docs/.vuepress/config.js create mode 100644 docs/.vuepress/public/manifest.json create mode 100644 docs/README.md create mode 100644 docs/cli.md create mode 100644 docs/compressors/babel-minify.md create mode 100644 docs/compressors/clean-css.md create mode 100644 docs/compressors/crass.md create mode 100644 docs/compressors/csso.md create mode 100644 docs/compressors/gcc.md create mode 100644 docs/compressors/sqwish.md create mode 100644 docs/compressors/uglify-es.md create mode 100644 docs/compressors/uglify-js.md create mode 100644 docs/compressors/yui.md create mode 100644 docs/getting-started.md create mode 100644 docs/options.md diff --git a/.gitignore b/.gitignore index 6c8620246..1a4b7bb56 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ ._* node_modules coverage +dist .history diff --git a/Readme.md b/Readme.md index bbdce692e..ce7f5729e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,4 @@ -
+

node-minify

A very light minifier Node.js module.

@@ -19,25 +19,21 @@ It allow you to compress JavaScript and CSS files. -- [Babel-minify](#options-for-babel-minify) -- [Butternut](#options-for-butternut) -- [YUI Compressor](#options-for-yui-compressor) -- [Google Closure Compiler](#options-for-google-closure-compiler) -- [UglifyJS](#options-for-uglifyjs) -- [Clean-css](#options-for-clean-css) -- [CSSO](#options-for-csso) -- [Sqwish](#options-for-sqwish) -- [Crass](#options-for-crass) -- [CLI](#cli) :tada: new in version 3 - -CSS benchmark : http://goalsmashers.github.io/css-minification-benchmark/ - -I recommend to execute it at boot time for production use. +- [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) +- [clean-css](https://node-minify.2clics.net/compressors/clean-css.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) +- [CLI](https://node-minify.2clics.net/cli.html) :tada: new in version 3 ## Installation ```bash -npm install node-minify +npm install node-minify # OR yarn add node-minify ``` ## Quick Start @@ -53,7 +49,7 @@ compressor.minify({ callback: function(err, min) {} }); -// Using UglifyJS +// Using UglifyJS with wildcards compressor.minify({ compressor: 'uglifyjs', input: './**/*.js', @@ -61,7 +57,7 @@ compressor.minify({ callback: function(err, min) {} }); -// Using Promise +// With Promise var promise = compressor.minify({ compressor: 'uglifyjs', input: './**/*.js', @@ -73,363 +69,9 @@ promise.then(function(min) {}); [More examples](https://github.com/srod/node-minify/blob/master/examples/server.js) -## CLI - -You can compress files using the command line. - -Usage for one or multiple compressors : - -```bash -node-minify --compressor babel-minify --input 'input.js' --output 'output.js' -``` - -```bash -node-minify --compressor 'babel-minify, uglifyjs, gcc' --input 'input.js' --output 'output.js' -``` - -Usage for all the compressors : - -```bash -node-minify --compressor all --input 'input.js' --output 'output.js' -``` - - - -## Concatenate Files - -In order to concatenate files, simply pass in an array with the type `no-compress`. - -```js -compressor.minify({ - compressor: 'no-compress', - input: ['foo.js', 'foo2.js', 'foo3.js'], - output: 'bar.js', - callback: function(err, min) {} -}); -``` - -## Using wildcards - -```js -compressor.minify({ - compressor: 'gcc', - input: 'public/**/*.js', - output: 'bar.js', - callback: function(err, min) {} -}); -``` - -## Using sync option - -```js -compressor.minify({ - compressor: 'yui-js', - input: 'foo.js', - output: 'bar.js', - sync: true, - callback: function(err, min) {} -}); -``` - -## Using public folder - -`publicFolder` allow you to specify an input and output folder. - -It avoids you to specify the folder for each file. - -```js -compressor.minify({ - compressor: 'gcc', - publicFolder: './public/', - input: ['foo.js', 'foo2.js'], - output: 'bar.js', - callback: function(err, min) {} -}); -``` - -## Max Buffer Size - -In some cases you might need a bigger max buffer size (for example when minifying really large files). -By default the buffer is `1000 * 1024` which should be enough. If you however need more buffer, you can simply pass in the desired buffer size as an argument to `compressor.minify` like so: - -```js -compressor.minify({ - compressor: 'gcc', - input: 'foo.js', - output: 'bar.js', - sync: true, - buffer: 1000 * 1024, - callback: function(err, min) {} -}); -``` - -## Passing options - -You can pass an object to the compressor. - -Please check available options. - -### Options for Babel-minify - -```js -compressor.minify({ - compressor: 'babel-minify', - input: 'foo.js', - output: 'bar.js', - options: { - babelrc: 'public/.babelrc', - presets: ['env'] - }, - callback: function(err, min) {} -}); -``` - -[More informations](https://github.com/babel/minify) - -### Options for Butternut - -```js -compressor.minify({ - compressor: 'butternut', - input: 'foo.js', - output: 'bar.js', - options: { - check: false, - allowDangerousEval: false, - sourceMap: true - }, - callback: function(err, min) {} -}); -``` - -[More informations](https://github.com/Rich-Harris/butternut) - -### Options for YUI Compressor - -```js -compressor.minify({ - compressor: 'yui-js', - input: 'foo.js', - output: 'bar.js', - options: { - 'line-break': 80, - charset: 'utf8' - ... // See more information link below - }, - callback: function (err, min) {} -}); -``` - -[More informations](http://yui.github.io/yuicompressor) - -### Options for Google Closure Compiler - -```js -compressor.minify({ - compressor: 'gcc', - input: 'foo.js', - output: 'bar.js', - options: { - createSourceMap: true, - compilationLevel: 'WHITESPACE_ONLY', - languageIn: 'ECMASCRIPT6' - ... // See more information link below - }, - callback: function (err, min) {} -}); -``` - -[More informations](https://github.com/google/closure-compiler-js#flags) - -### Options for Google Closure Compiler Legacy (java version) - -```js -compressor.minify({ - compressor: 'gcc', - input: 'foo.js', - output: 'bar.js', - options: { - createSourceMap: true, - compilation_level: 'WHITESPACE_ONLY', - language: 'ECMASCRIPT6' - ... // See more information link below - }, - callback: function (err, min) {} -}); -``` - -[More informations](https://developers.google.com/closure/compiler/docs/api-ref) - -### Options for UglifyJS - -```js -compressor.minify({ - compressor: 'uglifyjs', - input: 'foo.js', - output: 'bar.js', - options: { - warnings: true, // pass true to display compressor warnings. - mangle: false // pass false to skip mangling names. - output: {} // pass an object if you wish to specify additional output options. The defaults are optimized for best compression. - compress: false // pass false to skip compressing entirely. Pass an object to specify custom compressor options. - }, - callback: function (err, min) {} -}); -``` - -[More informations](https://github.com/mishoo/UglifyJS2) - -### Options for clean-css - -```js -compressor.minify({ - compressor: 'clean-css', - input: 'foo.css', - output: 'bar.css', - options: { - advanced: false, // set to false to disable advanced optimizations - selector & property merging, reduction, etc. - aggressiveMerging: false // set to false to disable aggressive merging of properties. - ... // See more information link below - }, - callback: function (err, min) {} -}); -``` - -[More informations](https://github.com/jakubpawlowicz/clean-css/tree/3.4) - -### Options for CSSO - -```js -compressor.minify({ - compressor: 'csso', - input: 'foo.css', - output: 'bar.css', - options: { - restructureOff: true // turns structure minimization off - }, - callback: function(err, min) {} -}); -``` - -[More informations](https://github.com/css/csso/blob/master/docs/usage/usage.en.md) - -### Options for Sqwish - -```js -compressor.minify({ - compressor: 'sqwish', - input: 'foo.css', - output: 'bar.css', - options: { - strict: true // strict optimizations - }, - callback: function(err, min) {} -}); -``` - -[More informations](https://github.com/ded/sqwish) - -### Options for Crass - -```js -compressor.minify({ - compressor: 'crass', - input: 'foo.css', - output: 'bar.css', - callback: function(err, min) {} -}); -``` - -[More informations](https://github.com/mattbasta/crass) - -## Babel-minify - -Babel-minify can compress only JavaScript files. - -[https://github.com/babel/minify](https://github.com/babel/minify) - -## Butternut - -Butternut can compress only JavaScript files. - -[https://github.com/Rich-Harris/butternut](https://github.com/Rich-Harris/butternut) - -## YUI Compressor - -Yahoo Compressor can compress both JavaScript and CSS files. - -[http://developer.yahoo.com/yui/compressor/](http://developer.yahoo.com/yui/compressor/) - -## Google Closure Compiler - -Google Closure Compiler can compress only JavaScript files. - -It will throw an error if you try with CSS files. - -GCC latest version requires Java 1.8 -You can use the legacy version that use Java 1.6 - -```js -var compressor = require('node-minify'); - -// Using Google Closure Compiler legacy version for Java 1.6 -compressor.minify({ - compressor: 'gcc-legacy', - input: 'foo.js', - output: 'bar.js', - callback: function(err, min) {} -}); -``` - -[https://developers.google.com/closure/compiler/](https://developers.google.com/closure/compiler/) - -## UglifyJS - -UglifyJS can compress only JavaScript files. - -It will throw an error if you try with CSS files. - -[https://github.com/mishoo/UglifyJS2](https://github.com/mishoo/UglifyJS2) - -## Clean-css - -Clean-css can compress only CSS files. - -[https://github.com/GoalSmashers/clean-css](https://github.com/GoalSmashers/clean-css) - -## CSSO - -CSSO can compress only CSS files. - -[https://github.com/css/csso](https://github.com/css/csso) - -## Sqwish - -Sqwish can compress only CSS files. - -[https://github.com/ded/sqwish](https://github.com/ded/sqwish) - -## Crass - -Crass can compress only CSS files. - -[https://github.com/mattbasta/crass](https://github.com/mattbasta/crass) - -## Warning - -It assumes that you have Java installed on your environment for both GCC and YUI Compressor. To check, run: - -```bash -java -version -``` - -How to install: - -Mac: [https://java.com/en/download/help/mac_install.xml](https://java.com/en/download/help/mac_install.xml) - -Windows: [https://java.com/en/download/help/windows_manual_download.xml](https://java.com/en/download/help/windows_manual_download.xml) +## Documentation -Linux: [https://www.java.com/en/download/help/linux_x64_install.xml](https://www.java.com/en/download/help/linux_x64_install.xml) +Visit https://node-minify.2clics.net for full documentation ## Windows support diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js new file mode 100644 index 000000000..8dc0352ad --- /dev/null +++ b/docs/.vuepress/config.js @@ -0,0 +1,49 @@ +module.exports = { + title: 'Node-minify', + description: 'Full documentation of node-minify', + head: [['link', { rel: 'manifest', href: '/manifest.json' }], ['meta', { name: 'theme-color', content: '#3eaf7c' }]], + serviceWorker: true, + evergreen: true, + ga: 'UA-65399-7', + themeConfig: { + serviceWorker: { + updatePopup: true + }, + nav: [ + { + text: 'Releases', + link: 'https://github.com/srod/node-minify/releases' + }, + { + text: 'GitHub', + link: 'https://github.com/srod/node-minify' + }, + { + text: 'NPM', + link: 'https://www.npmjs.com/package/node-minify' + } + ], + sidebar: [ + { + title: '', + collapsable: false, + children: [['', 'Introduction'], 'getting-started', 'options', 'cli'] + }, + { + title: 'Compressors', + collapsable: false, + children: [ + 'compressors/babel-minify', + 'compressors/clean-css', + 'compressors/crass', + 'compressors/csso', + 'compressors/gcc', + 'compressors/sqwish', + 'compressors/uglify-es', + 'compressors/uglify-js', + 'compressors/yui' + ] + } + ] + } +}; diff --git a/docs/.vuepress/public/manifest.json b/docs/.vuepress/public/manifest.json new file mode 100644 index 000000000..58e554d40 --- /dev/null +++ b/docs/.vuepress/public/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "node-minify", + "short_name": "node-minify", + "icons": [ + { + "src": "/icons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icons/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "start_url": "/index.html", + "display": "standalone", + "background_color": "#fff", + "theme_color": "#3eaf7c" +} diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 000000000..da23d0d84 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,41 @@ +
node-minify
+ +

A very light minifier Node.js module.

+ +## Features + +It allow you to compress JavaScript and CSS files. + +**JavaScript:** + +- [babel-minify](/compressors/babel-minify.md) +- [Google Closure Compiler](/compressors/gcc.md) +- [uglify-js](/compressors/uglify-js.md) +- [uglify-es](/compressors/uglify-es.md) +- [YUI Compressor](/compressors/yui.md) + +**CSS:** + +- [clean-css](/compressors/clean-css.md) +- [crass](/compressors/crass.md) +- [CSSO](/compressors/csso.md) +- [sqwish](/compressors/sqwish.md) +- [YUI Compressor](/compressors/yui.md) + +**Command Line Interface:** + +- [CLI](/cli.md) :tada: new in version 3 + +CSS benchmark: [http://goalsmashers.github.io/css-minification-benchmark/](http://goalsmashers.github.io/css-minification-benchmark/) + +::: tip +I recommend to execute it at boot time for production use. +::: + +## Windows support + +Since v0.5.0, a windows support is available for the no-compress option and uglify-js (thanks to pieces029 and benpusherhq) + +## License + +[MIT](https://github.com/srod/node-minify/blob/master/LICENSE) diff --git a/docs/cli.md b/docs/cli.md new file mode 100644 index 000000000..b72fa84f1 --- /dev/null +++ b/docs/cli.md @@ -0,0 +1,21 @@ +# CLI + +You can compress files using the command line. + +Usage for one or multiple compressors : + +```bash +node-minify --compressor babel-minify --input 'input.js' --output 'output.js' +``` + +```bash +node-minify --compressor 'babel-minify, uglifyjs, gcc' --input 'input.js' --output 'output.js' +``` + +Usage for all the compressors : + +```bash +node-minify --compressor all --input 'input.js' --output 'output.js' +``` + +cli diff --git a/docs/compressors/babel-minify.md b/docs/compressors/babel-minify.md new file mode 100644 index 000000000..0f9964910 --- /dev/null +++ b/docs/compressors/babel-minify.md @@ -0,0 +1,33 @@ +# babel-minify + +`babel-minify` can compress only JavaScript files. + +[https://github.com/babel/minify](https://github.com/babel/minify) + +## Usage + +```js +compressor.minify({ + compressor: 'babel-minify', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` + +## Options + +```js +compressor.minify({ + compressor: 'babel-minify', + input: 'foo.js', + output: 'bar.js', + options: { + babelrc: 'public/.babelrc', + presets: ['env'] + }, + callback: function(err, min) {} +}); +``` + +[Check all options](https://github.com/babel/minify) diff --git a/docs/compressors/clean-css.md b/docs/compressors/clean-css.md new file mode 100644 index 000000000..34f966771 --- /dev/null +++ b/docs/compressors/clean-css.md @@ -0,0 +1,34 @@ +# clean-css + +`clean-css` can compress only CSS files. + +[https://github.com/GoalSmashers/clean-css](https://github.com/GoalSmashers/clean-css) + +## Usage + +```js +compressor.minify({ + compressor: 'clean-css', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` + +## Options + +```js +compressor.minify({ + compressor: 'clean-css', + input: 'foo.css', + output: 'bar.css', + options: { + advanced: false, // set to false to disable advanced optimizations - selector & property merging, reduction, etc. + aggressiveMerging: false // set to false to disable aggressive merging of properties. + ... // See more information link below + }, + callback: function (err, min) {} +}); +``` + +[Check all options](https://github.com/jakubpawlowicz/clean-css/tree/3.4) diff --git a/docs/compressors/crass.md b/docs/compressors/crass.md new file mode 100644 index 000000000..d89ed7057 --- /dev/null +++ b/docs/compressors/crass.md @@ -0,0 +1,16 @@ +# crass + +`crass` can compress only CSS files. + +[https://github.com/mattbasta/crass](https://github.com/mattbasta/crass) + +## Usage + +```js +compressor.minify({ + compressor: 'crass', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` diff --git a/docs/compressors/csso.md b/docs/compressors/csso.md new file mode 100644 index 000000000..6283d6324 --- /dev/null +++ b/docs/compressors/csso.md @@ -0,0 +1,16 @@ +# CSSO + +`CSSO` can compress only CSS files. + +[https://github.com/css/csso](https://github.com/css/csso) + +## Usage + +```js +compressor.minify({ + compressor: 'csso', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` diff --git a/docs/compressors/gcc.md b/docs/compressors/gcc.md new file mode 100644 index 000000000..df3c8ec9d --- /dev/null +++ b/docs/compressors/gcc.md @@ -0,0 +1,101 @@ +# GCC + +`Google Closure Compiler` can compress only JavaScript files. + +[https://developers.google.com/closure/compiler/](https://developers.google.com/closure/compiler/) + +## Usage (JavaScript version) + +```js +compressor.minify({ + compressor: 'gcc', + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +[https://www.npmjs.com/package/google-closure-compiler-js](https://www.npmjs.com/package/google-closure-compiler-js) + +## Usage (Java >= 1.8) + +```js +compressor.minify({ + compressor: 'gcc-java', + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Usage (Java <= 1.6) + +```js +// Using Google Closure Compiler legacy version for Java 1.6 +compressor.minify({ + compressor: 'gcc-legacy', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` + +## Java + +::: warning +It assumes that you have Java installed on your environment. +::: + +To check, run: + +```bash +java -version +``` + +How to install: + +Mac: [https://java.com/en/download/help/mac_install.xml](https://java.com/en/download/help/mac_install.xml) + +Windows: [https://java.com/en/download/help/windows_manual_download.xml](https://java.com/en/download/help/windows_manual_download.xml) + +Linux: [https://www.java.com/en/download/help/linux_x64_install.xml](https://www.java.com/en/download/help/linux_x64_install.xml) + +## Options + +### Options for Google Closure Compiler (JavaScript version) + +```js +compressor.minify({ + compressor: 'gcc', + input: 'foo.js', + output: 'bar.js', + options: { + createSourceMap: true, + compilationLevel: 'WHITESPACE_ONLY', + languageIn: 'ECMASCRIPT6' + ... // See more information link below + }, + callback: function (err, min) {} +}); +``` + +[Check all options](https://github.com/google/closure-compiler-js#flags) + +### Options for Google Closure Compiler (Java version) + +```js +compressor.minify({ + compressor: 'gcc', + input: 'foo.js', + output: 'bar.js', + options: { + createSourceMap: true, + compilation_level: 'WHITESPACE_ONLY', + language: 'ECMASCRIPT6' + ... // See more information link below + }, + callback: function (err, min) {} +}); +``` + +[Check all options](https://developers.google.com/closure/compiler/docs/api-ref) diff --git a/docs/compressors/sqwish.md b/docs/compressors/sqwish.md new file mode 100644 index 000000000..3b204c5cd --- /dev/null +++ b/docs/compressors/sqwish.md @@ -0,0 +1,30 @@ +# sqwish + +`sqwish` can compress only CSS files. + +[https://github.com/ded/sqwish](https://github.com/ded/sqwish) + +## Usage + +```js +compressor.minify({ + compressor: 'sqwish', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` + +## Options + +```js +compressor.minify({ + compressor: 'sqwish', + input: 'foo.css', + output: 'bar.css', + options: { + strict: true // strict optimizations + }, + callback: function(err, min) {} +}); +``` diff --git a/docs/compressors/uglify-es.md b/docs/compressors/uglify-es.md new file mode 100644 index 000000000..49ec84518 --- /dev/null +++ b/docs/compressors/uglify-es.md @@ -0,0 +1,35 @@ +# uglify-es + +`uglify-es` can compress only JavaScript files. + +[https://github.com/mishoo/UglifyJS2/tree/harmony](https://github.com/mishoo/UglifyJS2/tree/harmony) + +## Usage + +```js +compressor.minify({ + compressor: 'uglify-es', + input: 'foo.css', + output: 'bar.css', + callback: function(err, min) {} +}); +``` + +## Options + +```js +compressor.minify({ + compressor: 'uglify-es', + input: 'foo.js', + output: 'bar.js', + options: { + warnings: true, // pass true to display compressor warnings. + mangle: false // pass false to skip mangling names. + output: {} // pass an object if you wish to specify additional output options. The defaults are optimized for best compression. + compress: false // pass false to skip compressing entirely. Pass an object to specify custom compressor options. + }, + callback: function (err, min) {} +}); +``` + +[Check all options](https://github.com/mishoo/UglifyJS2/tree/harmony) diff --git a/docs/compressors/uglify-js.md b/docs/compressors/uglify-js.md new file mode 100644 index 000000000..400c6d40b --- /dev/null +++ b/docs/compressors/uglify-js.md @@ -0,0 +1,39 @@ +# uglify-js + +`uglify-js` can compress only JavaScript files. + +[https://github.com/mishoo/UglifyJS2](https://github.com/mishoo/UglifyJS2) + +::: warning +`UglifyJS` only supports JavaScript ECMAScript 5, please use [`uglify-es`](/compressors/uglify-es.md) instead. +::: + +## Usage + +```js +compressor.minify({ + compressor: 'uglifyjs', + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Options + +```js +compressor.minify({ + compressor: 'uglifyjs', + input: 'foo.js', + output: 'bar.js', + options: { + warnings: true, // pass true to display compressor warnings. + mangle: false // pass false to skip mangling names. + output: {} // pass an object if you wish to specify additional output options. The defaults are optimized for best compression. + compress: false // pass false to skip compressing entirely. Pass an object to specify custom compressor options. + }, + callback: function (err, min) {} +}); +``` + +[Check all options](https://github.com/mishoo/UglifyJS2) diff --git a/docs/compressors/yui.md b/docs/compressors/yui.md new file mode 100644 index 000000000..da79e22db --- /dev/null +++ b/docs/compressors/yui.md @@ -0,0 +1,65 @@ +# YUI Compressor + +`Yahoo Compressor` can compress both JavaScript and CSS files. + +[http://yui.github.io/yuicompressor/](http://yui.github.io/yuicompressor/) + +## Usage for JavaScript + +```js +compressor.minify({ + compressor: 'yui-js', + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Usage for CSS + +```js +compressor.minify({ + compressor: 'yui-css', // OR 'yui' + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Java + +::: warning +It assumes that you have Java installed on your environment. +::: + +To check, run: + +```bash +java -version +``` + +How to install: + +Mac: [https://java.com/en/download/help/mac_install.xml](https://java.com/en/download/help/mac_install.xml) + +Windows: [https://java.com/en/download/help/windows_manual_download.xml](https://java.com/en/download/help/windows_manual_download.xml) + +Linux: [https://www.java.com/en/download/help/linux_x64_install.xml](https://www.java.com/en/download/help/linux_x64_install.xml) + +## Options + +```js +compressor.minify({ + compressor: 'yui-js', + input: 'foo.js', + output: 'bar.js', + options: { + 'line-break': 80, + charset: 'utf8' + ... // See more information link below + }, + callback: function (err, min) {} +}); +``` + +[Check all options](http://yui.github.io/yuicompressor) diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 000000000..2d8513c98 --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,40 @@ +# Getting Started + +## Installation + +```bash +npm install node-minify # OR yarn add node-minify +``` + +## Quick Start + +```js +var compressor = require('node-minify'); + +// Using Google Closure Compiler +compressor.minify({ + compressor: 'gcc', + input: 'foo.js', + output: 'bar.js', + callback: function(err, min) {} +}); + +// Using UglifyJS +compressor.minify({ + compressor: 'uglifyjs', + input: './**/*.js', + output: 'bar.js', + callback: function(err, min) {} +}); + +// Using Promise +var promise = compressor.minify({ + compressor: 'uglifyjs', + input: './**/*.js', + output: 'bar.js' +}); + +promise.then(function(min) {}); +``` + +[More examples](https://github.com/srod/node-minify/blob/master/examples/server.js) diff --git a/docs/options.md b/docs/options.md new file mode 100644 index 000000000..69e67694f --- /dev/null +++ b/docs/options.md @@ -0,0 +1,69 @@ +# Options + +## Concatenate Files + +In order to concatenate files, simply pass in an array with the type `no-compress`. + +```js +compressor.minify({ + compressor: 'no-compress', + input: ['foo.js', 'foo2.js', 'foo3.js'], + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Using wildcards + +```js +compressor.minify({ + compressor: 'gcc', + input: 'public/**/*.js', + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Using sync option + +```js +compressor.minify({ + compressor: 'yui-js', + input: 'foo.js', + output: 'bar.js', + sync: true, + callback: function(err, min) {} +}); +``` + +## Using public folder + +`publicFolder` allow you to specify an input and output folder. + +It avoids you to specify the folder for each file. + +```js +compressor.minify({ + compressor: 'gcc', + publicFolder: './public/', + input: ['foo.js', 'foo2.js'], + output: 'bar.js', + callback: function(err, min) {} +}); +``` + +## Max Buffer Size (only for Java) + +In some cases you might need a bigger max buffer size (for example when minifying really large files). +By default the buffer is `1000 * 1024` which should be enough. If you however need more buffer, you can simply pass in the desired buffer size as an argument to `compressor.minify` like so: + +```js +compressor.minify({ + compressor: 'gcc', + input: 'foo.js', + output: 'bar.js', + sync: true, + buffer: 1000 * 1024, + callback: function(err, min) {} +}); +``` diff --git a/package.json b/package.json index 4cdc7f67f..045e0bd68 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "butternut" ], "scripts": { + "docs:dev": "vuepress dev docs", + "docs:build": "vuepress build docs", "eslint": "eslint lib __tests__ || true", "pretest": "npm run eslint", "test": "jest",