broccoli-asset-prepend

0.1.2 • Public • Published

broccoli-asset-prepend

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');

Installation

npm install broccoli-asset-prepend --save-dev

Usage

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/'
});

Options

  • prepend - Default: '' - A string to prepend to all of the assets. Commonly a CDN url like https://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-rewrite
  • assetFileFilter - Default: a function always returning true - Asset files matching assetExtensions 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.

Default settings

The default settings are available if needed in your application or addon via: var broccoliAssetPrependDefaults = require( 'broccoli-asset-prepend/lib/default-options' );

Ember CLI addon usage

var app = new EmberApp({
  assetPrepend: {
    prepend: 'https://sudomain.cloudfront.net/'
  }
});

Ember CLI addon options

This addon runs in the postProcessTree hook.

See Options section above for explanations and defaults

  • enabled - Default: true - will skip entirely if false
  • prepend - Default: null - Required
  • assetExtensions
  • replaceExtensions
  • ignore
  • enableCaching
  • assetFileFilter

Credits

Thanks to broccoli-asset-rev for inspiration and to Precision Nutrition for sponsoring the work on this plugin.

Package Sidebar

Install

npm i broccoli-asset-prepend

Weekly Downloads

21

Version

0.1.2

License

MIT

Unpacked Size

8.21 kB

Total Files

7

Last publish

Collaborators

  • lukemelia