File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,17 +50,37 @@ The plugin will only attempt to hash files with `[hash]` in the name.
5050</html >
5151```
5252
53+ ### Node.js
54+
55+ The recommended usage is to hash static assets in your post-build process using Node.js.
56+
57+ Let's say that you use Rollup to bundle and minify your CSS and JavaScript. The template ` index.html ` is copied to the ` build ` folder.
58+
59+ A post-build script could look like:
60+
5361``` js
62+ // postbuild.js
5463const fs = require (" fs" );
5564const posthtml = require (" posthtml" );
5665const { hash } = require (" posthtml-hash" );
5766
58- const html = fs .readFileSync (" ./index.html" );
67+ const html = fs .readFileSync (" ./build/ index.html" );
5968
6069posthtml ()
61- .use (hash ())
70+ .use (hash ({ path : " build " } ))
6271 .process (html)
63- .then ((result ) => fs .writeFileSync (" ./index.html" , result .html ));
72+ .then ((result ) => fs .writeFileSync (" ./build/index.html" , result .html ));
73+ ```
74+
75+ For convenience, you can add the post-build script to your package.json. The ` postbuild ` script is automatically invoked following the ` build ` script.
76+
77+ ``` json
78+ {
79+ "scripts" : {
80+ "build" : " rollup -c" ,
81+ "postbuild" : " node postbuild.js"
82+ }
83+ }
6484```
6585
6686### Options
You can’t perform that action at this time.
0 commit comments