Skip to content

Instantly share code, notes, and snippets.

@Munter
Created November 25, 2014 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Munter/b078ff12fd7393885514 to your computer and use it in GitHub Desktop.
Save Munter/b078ff12fd7393885514 to your computer and use it in GitHub Desktop.
Example script of how to do a production build of a website with external assets directly to disc
var AssetGraph = require('assetgraph-builder');
var graph = new AssetGraph({ root: 'https://raw.githubusercontent.com/saulshanabrook/hamilton-energy/gh-pages/'});
graph
.logEvents()
.loadAssets([
'index.html',
'README.md'
])
.populate({
followRelations: {
type: ['HtmlScript', 'HtmlStyle']
}
})
.queue(function moveVendorScriptsInternally(assetGraph) {
var newRoot = 'file://' + process.cwd() + '/app/';
assetGraph.findRelations({ hrefType: ['absolute', 'protocolRelative'] }).forEach(function (relation) {
if (relation.to.url) {
relation.hrefType = 'relative';
relation.to.url = newRoot + 'vendor/' + relation.to.fileName;
}
});
assetGraph.findAssets({ isInline: false, isLoaded: true }).forEach(function (asset) {
asset.url = asset.url.replace(assetGraph.root, newRoot);
});
assetGraph.root = newRoot;
})
.registerRequireJsConfig({preventPopulationOfJavaScriptAssetsUntilConfigHasBeenFound: true})
.buildProduction({
optimizeImages: true,
asyncScripts: true,
recursive: true
})
.writeAssetsToDisc({ isLoaded: true }, 'dist')
.writeStatsToStderr()
.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment