Last active
July 20, 2020 19:40
-
-
Save moose56/e4fd2db26d1f08a79d099a0728cfba80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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