makestatic-fingerprint
Version:
Fingerprints output files
148 lines (102 loc) • 4.18 kB
Markdown
# Fingerprint
> Fingerprint output files and update references
---
- [Install](#install)
- [API](#api)
- [Fingerprint](#fingerprint)
- [See Also](#see-also)
- [Fingerprint](#fingerprint-1)
- [Options](#options)
- [Throws](#throws)
- [.sources](#sources)
- [Throws](#throws-1)
- [License](#license)
---
## Install
```
yarn add makestatic-fingerprint
```
## API
### Fingerprint
Fingerprints output files for cache busting. Rewrites the references to
the resources and renames the corresponding compilation assets.
Enable this plugin for the `emit` phase.
Fingerprinting uses a checksum of the file content to generate a unique
name for the file, references to the resource are renamed and the
corresponding output file is renamed.
Because this plugin is enabled during the `emit` phase you can be certain
that the generated checksums match the actual checksums of the referenced
files as the files have been optimized and sealed.
#### See Also
* [Graph Resources](https://makestatic.ws/docs/api/graph-resources/ "Graph Resources")
#### Fingerprint
```javascript
new Fingerprint(context, options)
```
Create a Fingerprint plugin.
The `rules` option is an array of regular expression resource patterns.
When no `id` function is specified the default implementation will
generate a checksum of the resource file content. When no `name` function
is given it generates a name prepending a period and the generated `id`
before the file extension.
The signature for an `id` function is:
```javascript
id(file, content)
```
It should return a unique identifier for the file.
The signature for a `name` function is:
```javascript
name(file, id)
```
It should return the new name of the file based on the supplied `id`.
You may change the checksum algorithm using the `algorithm` option but
it is recommended you use the default.
* `context` Object the processing context.
* `options` Object the plugin options.
##### Options
* `rules` Array list of resource matching rules.
* `algorithm` String=sha512 checksum algorithm.
* `id` Function generate fingerprint id.
* `name` Function generate new resource file name.
##### Throws
* `Error` if no resource graph is available.
#### .sources
```javascript
Fingerprint.prototype.sources(file, context)
```
Inspects the rules assigned to this plugin and finds matching resources.
For each matched resource call the `id` function to generate a unique
identifier for the resource followed by the `name` function to generate a
new name for the resource.
Once the resource name has been allocated references to the resource are
renamed and compilation asset output paths are renamed.
* `file` Object the current file.
* `context` Object the processing context.
##### Throws
* `Error` if a resource could not be found in the graph.
## License
MIT
---
Created by [mkdoc](https://github.com/mkdoc/mkdoc) on March 12, 2017
[docs]: https://makestatic.ws/docs/ "Documentation"
[standalone manual]: https://github.com/makestatic/website/blob/master/MANUAL.md "Standalone Manual"
[yarn]: https://yarnpkg.com "Yarn"
[webpack]: https://webpack.js.org "Webpack"
[babel]: https://babeljs.io "Babel"
[postcss]: http://postcss.org "Postcss"
[sugarss]: https://github.com/postcss/sugarss "Sugarss"
[reshape]: https://github.com/reshape/reshape "Reshape Source Code"
[reshapeml]: https://reshape.ml "Reshape"
[clean-css]: https://github.com/jakubpawlowicz/clean-css "Clean CSS"
[html-minifier]: https://github.com/kangax/html-minifier "Html Minifier"
[uglify-js]: https://github.com/mishoo/UglifyJS2 "Uglify JS"
[imagemin]: https://github.com/imagemin/imagemin "Imagemin"
[mkdoc]: https://github.com/mkdoc/mkdoc "Mkdoc"
[browsersync]: https://www.browsersync.io "Browsersync"
[yeoman]: http://yeoman.io "Yeoman"
[spike]: https://www.spike.cf "Spike"
[validator]: https://github.com/validator/validator "HTML Validator"
[github pages]: https://pages.github.com "Github Pages"
[amazon s3]: https://aws.amazon.com/s3/ "Amazon S3"
[google sitemaps]: https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 "Google Sitemaps"
[sitemaps]: https://www.sitemaps.org/ "Sitemaps"