UNPKG

4.77 kBMarkdownView Raw
1# broccoli-asset-rev
2
3[![Build Status](https://circleci.com/gh/rickharrison/broccoli-asset-rev.svg?style=shield)](https://circleci.com/gh/rickharrison/broccoli-asset-rev)
4[![codecov.io](https://codecov.io/github/rickharrison/broccoli-asset-rev/coverage.svg?branch=master&precision=2)](https://codecov.io/github/rickharrison/broccoli-asset-rev?branch=master)
5[![npm](https://img.shields.io/npm/v/broccoli-asset-rev.svg)](https://www.npmjs.com/package/broccoli-asset-rev)
6
7[Broccoli](https://github.com/broccolijs/broccoli) plugin to add fingerprint checksums to your files and update the source to reflect the new filenames.
8
9Turns
10
11```
12<script src="assets/appname.js">
13background: url('/images/foo.png');
14```
15
16Into
17
18```
19<script src="https://subdomain.cloudfront.net/assets/appname-342b0f87ea609e6d349c7925d86bd597.js">
20background: url('https://subdomain.cloudfront.net/images/foo-735d6c098496507e26bb40ecc8c1394d.png');
21```
22
23## Installation
24
25```js
26npm install broccoli-asset-rev --save-dev
27```
28
29## Usage
30
31```js
32var AssetRev = require('broccoli-asset-rev');
33
34var assetNode = new AssetRev(node, {
35 extensions: ['js', 'css', 'png', 'jpg', 'gif'],
36 exclude: ['fonts/169929'],
37 replaceExtensions: ['html', 'js', 'css'],
38 prepend: 'https://subdomain.cloudfront.net/'
39});
40```
41
42## Options
43
44 - `extensions` - Default: `['js', 'css', 'png', 'jpg', 'gif', 'map']` - The file types to add md5 checksums.
45 - `exclude` - Default: `[]` - An array of globs. If a filename contains any item in the exclude array, it will not be fingerprinted.
46 - `replaceExtensions` - Default: `['html', 'css', 'js']` - The file types to replace source code with new checksum file names.
47 - `prepend` - Default: `''` - A string to prepend to all of the assets. Useful for CDN urls like `https://subdomain.cloudfront.net/`
48 - `generateRailsManifest` - Default: none - If true, will generate a `manifest.json` to be used by Sprockets for the Rails Asset Pipeline. The manifest will be fingerprinted by default but this can be avoided by adding `'manifest.json'` to the `exclude` list.
49 - `railsManifestPath` - Default: `'assets/manifest-HASH.json'` - The path in the destination folder to store the Rails manifest. Only for the default value, `HASH` will be replace with the fingerprint of the file.
50 - `customHash` - Default: none - If set, overrides the md5 checksum calculation with the result of calling `customHash(buffer, pathToFile)`. If it is not a `function`, `customHash` is used as the hash value. If it is set to `null`, fingerprinting is skipped and only prepending occurs.
51 - `generateAssetMap` - Default: false. If true, will generate a `assetMap.json` file in a `assets` directory on the output node. This file contains a mapping of the original asset name to the fingerprinted asset, like the following:
52 - `assetMapPath` - Default: `'assets/assetMap-HASH.json'` - The path in the destination folder to store the `assetMap.json` in. Only for the default value, `HASH` will be replace with the fingerprint of the file.
53
54```js
55{
56 assets: {
57 css/file1.css: css/file1-sdaa7d6a87d6ada78ds.css,
58 images/image1.png: images/image1-sdaa7d6a87d6ada78ds.css,
59 }
60}
61```
62 - `fingerprintAssetMap` - Default: false. If true, will fingerprint `assetMap.json`.
63 - `ignore` - Default: `[]` - An array of strings. If a filename contains any item in the ignore array, the contents of the file will not be processed for fingerprinting.
64 - `annotation` - Default: null. A human-readable description for this plugin instance.
65
66## Default settings
67
68The default [settings](https://github.com/rickharrison/broccoli-asset-rev/blob/master/lib/default-options.js) are available if needed in your application or addon via:
69`var broccoliAssetRevDefaults = require( 'broccoli-asset-rev/lib/default-options' );`
70
71## Ember CLI addon usage
72
73```js
74var app = new EmberApp({
75 fingerprint: {
76 exclude: ['fonts/169929'],
77 prepend: 'https://sudomain.cloudfront.net/'
78 }
79});
80```
81
82## Ember CLI addon options
83
84 - `enabled` - Default: `app.env === 'production'` - Boolean. Enables fingerprinting if true. **True by default if current environment is production.**
85 - `exclude` - Default: `[]` - An array of globs. If a filename contains any item in the exclude array, it will not be fingerprinted.
86 - `extensions` - Default: `['js', 'css', 'png', 'jpg', 'gif', 'map']` - The file types to add md5 checksums.
87 - `prepend` - Default: `''` - A string to prepend to all of the assets. Useful for CDN urls like `https://subdomain.cloudfront.net/`
88 - `replaceExtensions` - Default: `['html', 'css', 'js']` - The file types to replace source code with new checksum file names.
89
90[![ghit.me](https://ghit.me/badge.svg?repo=rickharrison/broccoli-asset-rev)](https://ghit.me/repo/rickharrison/broccoli-asset-rev)