Created
July 23, 2019 15:22
-
-
Save Munter/1f2deefc0e35633305d9d1651a928f5a 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'); | |
async function everythingIsRelative(graphInstance) { | |
const relations = graphInstance.findRelations({hrefType: {$not: 'inline'}}); | |
for (const relation of relations) { | |
relation.hrefType = 'relative'; | |
} | |
} | |
async function main() { | |
const graph = new AssetGraph({ | |
root: 'docs/_site', | |
canoniralRoot: 'https://mochajs.org/' | |
}); | |
// Logging for easier debugging | |
await graph.logEvents(); | |
// Add initial entry points | |
await graph.loadAssets('index.html'); | |
// Expand the graph to the entirety of your site | |
await graph.populate({ | |
followRelations: { | |
crossorigin: false | |
} | |
}); | |
// Make al URL's root relative | |
await everythingIsRelative(graph); | |
// Write the whole thing to the `dist`-folder | |
await graph.writeAssetsToDisc({isLoaded: true}, 'dist-demo'); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment