Created
November 25, 2014 23:40
-
-
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
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
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