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

kompressor

v0.1.4

Published

Process an html page and kompress and consolidate css/js assets into a single file

Downloads

4

Readme

Kompressor

What it is?

Kompressor is a command line utility for compressing and concatenating static JS & CSS. Kompressor uses JSDOM to scrape a specified index page scripts and stylesheets. It then uses a specified program to minify (kompress) each file and pipe the output into a specified output file. By default kompressor uses Yahoo's yuicompressor for css minification, and uglifyjs for javascript minification. Extending kompressor to use another program is super simple, and simply requires extending one of the Kompressor classes and changing the exec string (see below).

Options

-h, --help                             output usage information
-V, --version                          output the version number
-i, --PROJECT-INDEX-FILE [file]        Specifies the html file to process
-r, --WEBROOT-REPLACEMENTS [patterns]  Set replacements for path [kwsvc|/home/choover/kwsvc,sugar|home/choover/sugar]
-v, --EXCLUDED-PATTERNS [patterns]     Specifies files to skip based on matching regex patterns
-d, --DRY-RUN                          Specifies dry run mode (only show output do not save file)
-l, --DISABLE-LOGGING                  Turn off logging, show only process output
-o, --OUTPUT [file]                    Specifies output file location
-w, --FAIL-EXTERNAL-URLS               Returns an error if external URLS are present
-x, --CONFIG [file]                    Run with specified config file

Caveats

Right now Kompressor only works by reading the specified index file from the filesystem. This works well for applications with a static JS frontend that communicates with an API service, it does not work as well with dynamically created pages. There are plans in the immediate future to change this, and add support for http/https scraping of the index file.

if you are using imports in your css it will break the css minifier :grimacing:

Also and this is an IMPORTANT NOTE css assets such as fonts and background images must be absolute to the webroot and not relative to the stylesheet, otherwise minification will break your links.

Extending Kompressor

In the following example you can see how easy it was to extend kompressor to use google's closure compiler instead of our default js compiler uglify.js. It was as simple as changing the execString property to the executable string that compiles each file. %s being the file which is interpolated within the string.


    /* file: src/KompressorJSClosure.js */
    
    var KompressorJS = require(__dirname + '/KompressorJS.js');
       
    function KompressorJSClosure(){
        KompressorJS.apply(this, arguments)
        this.execString = 'closure-compiler %s';
    }

    KompressorJSClosure.prototype   = new KompressorJS();
    KompressorJSClosure.constructor = KompressorJSClosure;

    module.exports = KompressorJSClosure;
    

Now we have our class, all we have to do is create a new "executable" inside of the "bin" directory which utilizes this class.

    #!/usr/local/bin/node
    
    /* file: bin/kompress-js-closure */
    var Kompressor = require(__dirname + "/../src/KompressorJSClosure.js");
    new Kompressor().init();    

And that's it! Pretty simple. For more info on how to extend Kompressor reference the documentation(coming soon...)

Todo

  • Allow scraping from webserver (not only fileread)
  • Add support for SSL
  • Add tests