You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-10Lines changed: 40 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
[![NPM][npm]][npm-url]
4
4
5
-
`posthtml-hash` is a [PostHTML](https://github.com/posthtml/posthtml) plugin for hashing static assets to enable caching.
5
+
`posthtml-hash` is a [PostHTML](https://github.com/posthtml/posthtml) plugin for hashing file names to enable caching.
6
6
7
7
```diff
8
8
<html>
@@ -29,7 +29,7 @@ npm i -D posthtml-hash
29
29
30
30
### Input
31
31
32
-
The plugin will only attempt to hash files with `[hash]` in the name.
32
+
By default, the plugin will attempt to hash file names that contain `[hash]`. As a qualifier, only nodes with a `href` or `src` attribute are considered.
33
33
34
34
```html
35
35
<html>
@@ -81,29 +81,59 @@ For convenience, you can add the post-build script to your package.json. The `po
81
81
}
82
82
```
83
83
84
+
### Custom Hash Length
85
+
86
+
Customize the hash length by specifying an integer after the `hash:{NUMBER}`. The default hash length is `20`.
87
+
88
+
**Note**: This only works for a pattern that uses square brackets and a colon separator. Use the `hashLength` option for other use cases.
89
+
90
+
```html
91
+
<scriptsrc="src.[hash].js"></script>
92
+
<!-- src.b0dcc67ffc1fd562f212.js -->
93
+
94
+
<scriptsrc="src.[hash:8].js"></script>
95
+
<!-- src.b0dcc67f.js -->
96
+
```
97
+
84
98
### Options
85
99
86
-
This plugin assumes that the file to process is in the same directory as the posthtml script. If not, specify the relative path to the html file in `options.path`:
100
+
This plugin assumes that the file to process is in the same directory as the PostHTML script. If not, specify the relative path to the html file in `options.path`:
87
101
88
102
```js
89
103
hash({
90
104
/**
91
105
* Relative path to processed HTML file
92
106
*/
93
107
path:"public", // default: ""
108
+
109
+
/**
110
+
* File name pattern (regular expression) to match
111
+
*/
112
+
pattern:newRegExp(/\custom-file-pattern/), // default: new RegExp(/\[hash.*]/g)
113
+
114
+
/**
115
+
* Custom hash length
116
+
*/
117
+
hashLength:8, // default: 20
94
118
});
95
119
```
96
120
97
-
### Custom Hash Length
121
+
##Recipes
98
122
99
-
Customize the hash length by specifying an integer after the `hash:{NUMBER}`. The default hash length is `20`.
0 commit comments