Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kylerush/grunt-userevvd
Replaces references in HTML to JavaScript and CSS files with their revv'd version.
https://github.com/kylerush/grunt-userevvd
Last synced: about 1 month ago
JSON representation
Replaces references in HTML to JavaScript and CSS files with their revv'd version.
- Host: GitHub
- URL: https://github.com/kylerush/grunt-userevvd
- Owner: kylerush
- License: mit
- Created: 2014-08-11T22:09:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-02-21T17:51:34.000Z (almost 9 years ago)
- Last Synced: 2023-12-08T16:25:01.192Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 336 KB
- Stars: 1
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grunt-userevvd [![Build Status](http://img.shields.io/travis/kylerush/grunt-userevvd.svg?branch=master)](https://github.com/kylerush/grunt-userevvd) [![NPM version](https://badge.fury.io/js/grunt-userevvd.svg)](http://badge.fury.io/js/grunt-userevvd)
> Replaces <script>, <link>, and <img> HTML tags with their rev'd version for client and edge server caching.
## Getting Started
This plugin requires Grunt `~0.4.5`If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```shell
npm install grunt-userevvd --save-dev
```Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
```js
grunt.loadNpmTasks('grunt-userevvd');
```## The "userevvd" task
This is a companion task for [grunt-filerev](https://github.com/yeoman/grunt-filerev). You must run the `filerev` task before running the `userevvd` task.
`grunt-userevvd` is a very lightweight and fast plugin that replaces the src/href attribute value for `` or `<link>` tags to their revv'd version.
The task reads the summary `grunt.filerev.summary` object that `grunt-filerev` creates. It replaces all the references to the newly revv'd files in the .html files you specify.
### Overview
In your project's Gruntfile, add a section named `userevvd` to the data object passed into `grunt.initConfig()`.An `html` task name replaces `script` and `link` references in .html files. Currently only .html files are supported, but .css will come in the future.
You should use the [files array format](http://gruntjs.com/configuring-tasks#files-array-format).
```js
grunt.initConfig({
userevvd: {
html: {
files: [
{
cwd: 'dist/',
src: '**/*.html',
expand: true,
dest: 'dist'
}
]
},
},
});
```### Options
####options.formatNewPath (optional)
A function that formats the new `src` or `href` value for the `script`/`link` tag. The argument is passed a string containing the original path from the `grunt.filerev.summary` object.
####options.formatOriginalPath (optional)
A function that formats the original file path from grunt-filerev. This plugin will look for the a tag with the return value from this function to replace.
### Usage Examples
Assuming you have a directory struture like this:
```
|
+- dist
| +- assets
| +- js
| +- main.js
| +- index.html
```The contents of dist/index.html are:
```html
<!doctype html>
<html>
<head>
<script src="dist/assets/js/main.js">