npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ls-minifier

v2.2.0

Published

A tool that minifies all .js, css and html files in a folder recursivelly using https://www.npmjs.com/package/node-minify

Downloads

85

Readme

ls-minifier

Codacy Badge npm version Node.js Package

A tool that minifies all .js, css and html files in a folder recursivelly using https://www.npmjs.com/package/node-minify

Installation

> npm install -g ls-minifier

Run CLI

> ls-minifier --version --input=./your/files/path --js-compressor=gcc --language-in=ECMASCRIPT_2018 --language-out=ECMASCRIPT5 --css-compressor=yui --html-compressor=html-minifier --silent --throwErrors --override --signature-file=./path/to/signature.txt --replacers=[VERSION]|v1.0.0;{{YEAR}}|2019

Compressors Configuration File

You can specify some configurations for each compressor using a .ls-minifyrc file the must be located at the root of the command execution path. The file must contain a valid JSON object like this:

{
    "js_compressor_options": {
        ...
    },
    "css_compressor_options": {
        ...
    },
    "html_compressor_options": {
        ...
    }
}

The options for each compressor you can see at the here

Signature File

You can also create a .ls-minify-sign file at the root of the command execution to use as a signature to sign each minification. This file must contain just plain text and will omit the --signature-file command flag.

Run in your code

lsMinifier function has 3 parts: input-path, options, and callback, such that

lsMinifier([input-path], [options], [callback])
  • input-path: Can be a directory or a single file

The callback outputs 2 options:

  • err: the error of each file
  • min: the output of the minified file
  • silent: true or false depending if the silent mode is enabled or not
  • shouldThrowErrors: true or false depending if the throwErrors is enabled or not

ATTENTION: Using a callback for the outputs will invalidate the option throwErrors since you can decide what to do with the errors instead

Example
const lsMinifier = require('ls-minifier')
const input_path = './'
const options = {
    silent: true,
    throwErrors: false,
    js_language_in: 'ECMASCRIPT_2018',
    js_language_out: 'ECMASCRIPT5',
    js_compressor: 'gcc',
    css_compressor: 'yui',
    html_compressor: 'html-minifier',
    override: false,
    signature_file: '',
    replacers: [],
    // EXTRA SPECIFIC OPTIONS FOR THE COMPRESSORS
    js_compressor_options: {
        ...
    },
    css_compressor_options: {
        ...
    },
    html_compressor_options: {
        ...
    }
}
const callback = (err, min) => (err ? console.log(err) : console.log(min))

lsMinifier(input_path, options, callback)

Options

  • silent If silent mode is on, any logs will be displayed

  • throwErrors If throwErrors mode is on, any error in the process will be thrown and stop the process, even with silent mode enabled.

  • js_language_in (ONLY FOR GCC COMPRESSOR) Determine the version of ecmascript of the input file. (Default is ECMASCRIPT_2018)

  • js_language_out (ONLY FOR GCC COMPRESSOR) Determine the version of ecmascript of the input file. (Default is ECMASCRIPT5)

  • js_compressor Determines the compression type that js files should be put through. (All js files will be ignored if this option is not set)

  • css_compressor Determines the compression type that css files should be put through. (All css files will be ignored if this option is not set)

  • html_compressor Determines the compression type that html files should be put through. (All html files will be ignored if this option is not set)

  • override Determines if will override the original input file or if will create another .min. file. (Default is false)

  • signature_file Path to a signature file with some text that you want to add to the top of the minified files.

  • version Show in console the current version of the ls-minifier package.

  • replacers Use this if you want to replace some keywords in your files. See the sample:

const replacers = [
    { from: '[VERSION]', to: 'v1.0.0' },
    { from: '{{YEAR}}', to: '2019' },
]

PS: As ls-minifier depends on node-minify v3.6.0, these types are defined by node-minify and can be found here.