minify-config

configuration tool for minifying your scripts/styles

npm install minify-config
15 downloads in the last week
61 downloads in the last month

minify-config.js

minify-config is a node.js configuration tool for easily minifying your scripts/stylesheets.

Installation

If you still don't have node.js installed, download it at http://nodejs.org/.

If everything went as expected, npm (Node Packaged Modules) was configured with node.js. Verify it typing the following command (in command line):

npm --version

Considering npm was successfully configured, install the minify-config lib:

npm install -g minify-config

The -g option indicates the lib minify-config will be available for command line usage, if your objective is use the lib as an API this option isn't needed.

Configuration

To configure the library to minify your application, download the default configuration file or copy it from your npm directory.

Windows: C:\Users\\AppData\Roaming\npm\node_modules\minify-config\config

config.json

{
    "javascript": {
        "files": {
            "app": [
                "js/plugins.js",
                "js/main.js"
            ]
        },
        "folders": "js/*(vendor|plugins)",
        "output": {
            "files": "js/min",
            "folders": "${folder}/min"
        }
    },
    "css": {
        "files": {
            "app": [
                "css/bootstrap.css",
                "css/bootstrap-responsive.css",
                "css/main.less"
            ]
        },
        "folders": "css/*(less)",
        "output": {
            "files": "css/",
            "folders": "${folder}/min"
        }
    }
}

Javascript / CSS

The library allows you to compact both your scripts in js extension, as your stylesheets in Less or css extension. You might minify many scripts to a single file, reducing the number of http requests your application requires.

E.g., in the default configuration file, js/plugins.js js/main.js will be minified to app.min.js, and stored in the directory defined in javascript.output.files (js/min) tag.

Besides a single file, you may configure minify-config for minifying an entire folder in folders tag. folders may receive an Array setting the directories that will be minified, or an regular expression┬╣.

[┬╣] javascript.folders and css.folders allow the use of Glob expressions for parsing your folders.

Html

Minify-config uses Google's htmlcompressor lib for compacting your html. It's required you have Java installed for minifying your templates.

The html parser follows the javascript/css parser syntax. Allowing you to compact specific files or entire directories.

Applying to your Project

To use the library in your project you must place the configuration file on the root of your application (or in the directory that you find more appropriate) with the correct path for the files location.

Command Line

Now just run the process (command line) making sure to be in the directory where the config.json is stored:

minifyconfig -f config.json

If all paths were set correctly, will be displayed on the screen which processes were executed and which files were generated.

Windows: You may also execute the automin.bat file (copy it from the config folder). This file will automatically execute the command above.

Options:

  • -h, --help Output usage information
  • -V, --version Output the version number
  • -f, --file Set the configuration file.
  • -s, --stats Show parsed commands in console
  • -a, --auto Automatically check for changes and minify configurated files
  • -u, --unique Parse configuration and minify a single specified file

Sublime Text 2

It's not required, but Sublime Text editor is highly recommended for improving your development workflow.

C:\Users\\AppData\Roaming\npm\node_modules\minify-config\config

Check it out Minify.sublime-build and minify.sublime-snippet set in the config folder.

To make the whole proccess even faster, add the build Minify.sublime-build on your Sublime. Just set the default build system as Minify (Tools> Build System) and after that perform the build. It's ready, the command will be processed through command line and your files will be generated.

Comming soon: Sublime Minify Config package

Informations

Access lmedeiros.com for more informations.

Copyright (c) 2013 Lucas Medeiros

npm loves you