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

grunt-frontend

v2.0.4

Published

CSS and JS minifier that respects source modification

Downloads

46

Readme

A Grunt.js task that compiles CSS and JS files with respect of file modification date. For JS, it uses built-in UglifyJS minifier, for CSS — Yandex’s CSSO with automatic @import inlining and url() rewriting.

Unlike basic minifiers, this task generates a hidden catalog file (.build-catalog.json) that stores state, last compilation date and checksum of minified files. Every time you call frontend-* task, it will look into this catalog and check if the state of files being minified was changed. If not, the file will not be re-minified which saves CPU time and modification date. This date (or checksum hash) can be used to modify URLs to minified files for effective caching.

Usage

This plugin provides frontend-js, frontend-css and frontend-index multi-tasks. Global config can be defined in frontend key. All tasks are file-based. Here’s example Gruntfile.js:

module.exports = function(grunt) {
    grunt.initConfig({
    	// Global config for each frontend-* task. These values can
    	// be overridden in `options` key of each task
    	frontent: {
    		// Force file minification even if they were not modified
           force: false,
        
           // Path to project sources root folder.
           // It is used to resolve absolute paths in CSS imports,
           // for example: @import "/css/file.css" will be resolved 
           // to './src/files/css/file.css'
           srcWebroot: './src/files',

           // Destination root folder.
           // Used to update minified files paths in catalog,
           // e.g. instead of storing '/Users/foo/project/out/css/minified.css' path, 
           // task will cut-out path to webroot and store '/css/minified.css' instead
           webroot: './out',
           
           // A scheme for creating versioned URLs. Versioned URLs
           // can are stored in catalog and used to rewrite paths 
           // for `url()` values of CSS.
           // Can be a string or a function.
           // A string is a template with the following placeholders:
           // * version: version tag (in most cases it’s CRC32 of file)
           // * url: absolute URL, e.g. `/path/to/file.css`
           // * dirname: absolute path to file’s directory, e.g. `/path/to/`
           // * basename: file’s full name, e.g. `file.css`
           // * filename: name of file, e.g. `file`
           // * ext: file’s extension, e.g. `css`
           rewriteScheme: '/-/<%= version %><%= url %>',
           
           // function to post-process file’s content before it will be
           // saved to disk
           postProcess: function(content, fileInfo) {}
    	},
    	
    	// Task for concatenating and minifying JS files
        'frontend-js': {
            main: {
                // task options
                options: {
                    // Minify JS
                    minify: true,
                    
                    // config for UglifyJS
                    uglify: {}
                },
                
                files: {
					'out/js/f.js': [
						'test/js/file1.js',
						'test/js/file2.js'
					]
				}
            }
        },
        
        // Task for concatenating and minifying CSS files
        'frontend-css': {
        	main: {
	        	options: {
	        		// inline @imports
	        		inline: true,
	        		
	        		// rewrite all url() to versioned ones.
	        		// the `rewriteScheme` is used to create versioned URL
	        		rewriteUrl: true,
	        		
	        		// minify CSS
	        		minify: true
	        	},
	        	files: [
					{src: 'test/css/*.css', dest: 'out/css'}
				]
        	}
        },
        
        // Task fo indexing files and storing its’ version hash
        // and verioned URL in catalog. Useful for fast lookups of 
        // versioned files
        'frontend-index': {
        	main: {
				files: [{src: 'test/css/**/*.{css,jpg,png}'}]
			}
        }
    });
};

This task can be used together with docpad-plugin-frontend to automatically generate cache-effective URLs to assets for DocPad-generated web-site.