Skip to content

Instantly share code, notes, and snippets.

@moose56
Last active July 20, 2020 19:40

Revisions

  1. moose56 revised this gist Jul 20, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions svelte-fingerprinting
    Original file line number Diff line number Diff line change
    @@ -20,9 +20,9 @@ const del = require('del');
    console.log('addAsset', asset.toString());
    });

    await graph.loadAssets('*.html'); // load assests for all html files
    await graph.populate(); // populate the graph with the assests
    await hashFiles(graph); // hash the appropriate assests
    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
    })();
  2. moose56 created this gist Jul 20, 2020.
    28 changes: 28 additions & 0 deletions svelte-fingerprinting
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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 assests for all html files
    await graph.populate(); // populate the graph with the assests
    await hashFiles(graph); // hash the appropriate assests

    await graph.writeAssetsToDisc({isLoaded: true}, './dist'); // save all to the dist folder
    })();