Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dxw/grunt-fingerprint
Add hashes to assets
https://github.com/dxw/grunt-fingerprint
govpress
Last synced: 10 days ago
JSON representation
Add hashes to assets
- Host: GitHub
- URL: https://github.com/dxw/grunt-fingerprint
- Owner: dxw
- License: mit
- Created: 2019-02-08T13:58:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-10T21:31:03.000Z (about 2 years ago)
- Last Synced: 2023-04-10T16:27:53.602Z (over 1 year ago)
- Topics: govpress
- Language: JavaScript
- Homepage:
- Size: 180 KB
- Stars: 0
- Watchers: 15
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-MIT
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# grunt-fingerprint
Add hashes to assets.
## Installation
First, make sure old fingerprinted files get deleted, otherwise your files will end up with multiple hashes. [grunt-contrib-clean](https://github.com/gruntjs/grunt-contrib-clean) will do this for you.
Then, add the package:
```
yarn add --dev git+https://github.com/dxw/grunt-fingerprint.git
```Add the following to your `Gruntfile.js`:
```js
grunt.loadNpmTasks('@dxw-digital/grunt-fingerprint')
``````js
grunt.initConfig({
fingerprint: {
production: {
options: {
json: 'build/fingerprint.json',
},
src: [
'build/*.min.css',
],
},
},
});
```Now, `grunt fingerprint` will move `build/main.min.css` to `build/main-da39a3ee5e6b4b0d3255bfef95601890afd80709.min.css` and leave a JSON file in `build/fingerprint.json` with a mapping between the old file and the new.
```
% jq . < build/fingerprint.json
{
"rewrittenFiles": {
"build/main.min.css": "build/main-da39a3ee5e6b4b0d3255bfef95601890afd80709.min.css"
}
}
```Note: I recommend not accessing the JSON file via in-browser JS because it will be cached.