Broccoli plugin to add prepend asset references with a scheme + domain or root path.
Turns
<script src="assets/appname.js">
background: url('/images/foo.png');
Into
<script src="https://subdomain.cloudfront.net/assets/appname.js">
background: url('https://subdomain.cloudfront.net/images/foo.png');
npm install broccoli-asset-prepend --save-dev
var AssetPrepend = require('broccoli-asset-prepend');
var assetNode = new AssetPrepend(node, {
assetExtensions: ['js', 'css', 'png', 'jpg', 'gif'],
replaceExtensions: ['html', 'js', 'css'],
ignore: ['testem.js'],
prepend: 'https://subdomain.cloudfront.net/'
});
prepend
- Default:''
- A string to prepend to all of the assets. Commonly a CDN url likehttps://subdomain.cloudfront.net/
assetExtensions
- Default:['js', 'css', 'png', 'jpg', 'gif', 'map']
- The file types to prepend.replaceExtensions
- Default:['html', 'css', 'js']
- The file types to replace source code with new checksum file names.ignore
- Default:[]
- An array of paths to skip rewriting.enableCaching
- Default: true - If true, will set this options on broccoli-asset-rewriteassetFileFilter
- Default: a function always returning true - Asset files matchingassetExtensions
will be passed through this filter giving you the opportunity to exclude some assets. broccoli-asset-rewrite is slower with a larger assetMap, so this can be useful to optimize build times.annotation
- Default: null. A human-readable description for this plugin instance.
The default settings are available if needed in your application or addon via:
var broccoliAssetPrependDefaults = require( 'broccoli-asset-prepend/lib/default-options' );
var app = new EmberApp({
assetPrepend: {
prepend: 'https://sudomain.cloudfront.net/'
}
});
This addon runs in the postProcessTree hook.
See Options section above for explanations and defaults
enabled
- Default: true - will skip entirely if falseprepend
- Default: null - RequiredassetExtensions
replaceExtensions
ignore
enableCaching
assetFileFilter
Thanks to broccoli-asset-rev for inspiration and to Precision Nutrition for sponsoring the work on this plugin.