Giter Site home page Giter Site logo

raphaeleidus / grunt-hashres Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luismahou/grunt-hashres

0.0 1.0 1.0 2.15 MB

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.

License: MIT License

JavaScript 100.00%

grunt-hashres's Introduction

grunt-hashres

Hashes your js and css files and rename the <script> and <link> declarations that refer to them in your html/php/etc files.

Getting Started

Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-hashres

Then add this line to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-hashres');

Documentation

Add the following to your grunt.js file, inside the initConfig function:

hashres: {
  // hashres is a multitask. Here 'prod' is the name of the subtask. You can have as many as you want.
  prod: {
    // Files to hash
    files: [
      // WARNING: These files will be renamed!
      'dist/prod/scripts/my-compressed-and-minified-scripts.js',
      'dist/prod/styles/my-compressed-and-minified-styles.css'],
    // File that refers to above files and needs to be updated with the hashed name
    out: 'dist/prod/home.php',
    // Optional. Encoding used to read/write files. Default value 'utf8'
    encoding: 'utf8',
    // Optional. Format used to name the files specified in 'files' property. 
    // Default value: '${hash}.${name}.cache.${ext}'
    fileNameFormat: '${hash}.${name}.cache.${ext}'
  }
}

The way this task works follows my workflow: I only hash the .js and .css files of my production release files, which are first both uglified and minified. If you want to hash a different set of files for a different environment, simply add another subtask under hashres.

Properties

  • files: A single file expression or an array of file expressions. Something like myscripts/*.js would be valid.
  • out: The file expression(s) that refer to the hashed files and that will be updated with the new names. You can update more than one file specifying an array of output files: [out/fileOne.html, out/fileTwo.html]
  • encoding: Encoding used to read and write files. Using utf8 by default.
  • fileNameFormat: The files specified in property files will be renamed according to the pattern specified in this property. The following variables are allowed:
    • ${hash}: the first 8 digits of the md5 of the file.
    • ${name}: the original name of the file.
    • ${ext}: the original extension of the file.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

  • 14/11/12 - 0.1.5: Feature request #1: fileNameFormat property added.
  • 02/11/12 - 0.1.3: First working release.

License

Copyright (c) 2012 Luismahou
Licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.