Skip to content

Instantly share code, notes, and snippets.

@moose56
Last active July 20, 2020 19:40
Show Gist options
  • Save moose56/e4fd2db26d1f08a79d099a0728cfba80 to your computer and use it in GitHub Desktop.
Save moose56/e4fd2db26d1f08a79d099a0728cfba80 to your computer and use it in GitHub Desktop.
const AssetGraph = require('assetgraph'); // library to build dependency tree
const hashFiles = require('assetgraph-hashfiles'); // library to add hash
const del = require('del');
// top level await calls need to be inside
// an async function call
(async () => {
// remove old version of dist folder so
// we start from a clean slate and no old
// versions are left around
const deletedPaths = await del(['./dist']);
deletedPaths.forEach(p => console.log(`deleted path: ${p}`));
// create new graph of the public folder
const graph = new AssetGraph({root: './public'});
// output events for logging
graph.on('addAsset', function (asset) {
console.log('addAsset', asset.toString());
});
await graph.loadAssets('*.html'); // load assets for all html files
await graph.populate(); // populate the graph with the assets
await hashFiles(graph); // hash the appropriate assets
await graph.writeAssetsToDisc({isLoaded: true}, './dist'); // save all to the dist folder
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment