Skip to content

Wu-Wu/grunt-urlrevs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-urlrevs

build status

Manage revisions in CSS urls.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-urlrevs

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-urlrevs');

The "urlrevs" task

Builds image revisions tree, finds CSS files and replaces each occurences of links to images in url() directives.

Overview

In your project's Gruntfile, add a section named urlrevs to the data object passed into grunt.initConfig().

grunt.initConfig({
    urlrevs: {
        some_target: {
            options: {
                // Target-specific options go here.
            },
            src: [
                // Specify the files you want to edit
            ]
        }
    }
})

Each target defines a specific task that can be run.

Options

options.abbrev

Type: Integer Default value: 6

The length of the revision.

options.branch

Type: String Default value: HEAD

Traversed branch.

options.filter

Type: RegExp Default value: \\.(png|jpg|jpeg|gif)

Regular expression to filter files in stage of building revisions tree and replacing revisions in urls.

options.prefix

Type: String Default value: root

Prefix to cut when generate absulute image url.

options.path

Type: String Default value: root/i

Path to search files in stage of building tree. Relative to repository root directory.

options.valid

Type: Array Default value: [ '^\\/' ]

All valid URL masks represented as a list of RexExp-like strings.

options.skip

Type: Array Default value: [ '^https?:\\/\\/', '^\\/\\/', '^data:image\\/(sv|pn)g', '^%23' ]

Defined URL masks which should be excluded during processing. Represented as a list of RexExp-like strings.

options.upcased

Type: Boolean Default value: true

Use uppercased revision string like F96A722.

options.implant

Type: Boolean Default value: true

Allows embed revision into filename, e.g. /i/navigation_sprite.F96A722.png.

options.autocommit

Type: Boolean Default value: true

Fixes uncommited changes in the repository. All new files will be added to the repository. As a commit message it uses value of options.message.

options.message

Type: String Default value: Wave a magic wand (by urlrevs)

Message used at autocommit stage.

Usage Example

grunt.initConfig({
    urlrevs: {
        live: {
            options: {
                abbrev: 6,
                branch: 'HEAD',
                filter: '\\.(png|jpg|jpeg|gif|bmp)',
                prefix: 'root',
                path: 'root/i',
                valid: [ '^\\/', '^https?:\\/\\/' ],
                skip: [ '^https?:\\/\\/' ],
                upcased: true,
                implant: false
            },
            src: [
                'root/css/**/*.css'
            ]
        }
    },
});

grunt.loadNpmTasks('grunt-urlrevs');
grunt.registerTask('default', ['urlrevs:live']);

License

grunt-urlrevs is licensed under the MIT license.

About

Manage revisions in CSS urls

Resources

License

Stars

Watchers

Forks

Packages

No packages published