1.0.1 • Published 8 years ago

ember-cli-transforms v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

ember-cli-transforms

An ember-cli addon that lets you apply arbitrary transformations to specific files at the end of a build.

Build Status

Installation

ember install ember-cli-transforms

Usage

In your app's ember-cli-build.js, define transforms options on your app instance as such:

const app = new EmberApp(defaults, {
  transforms: {
    targets: [
      {
        pattern: 'index.html',
        rename: (originalPath) => originalPath.replace(/\.html$/, '.jsp'),
        transform: (content, originalPath) => content.replace(/laughter/g, 'tears')
      },
      {
        pattern: '**/*.css',
        transform: (content, originalPath) => content.replace(/.\/fonts\//g, 'http://somecdn/fonts/')
      }
    ]
  }
});

Options

transforms.targets: object[]

An array of target objects and their transforms. Defaults to [].

A target is a simple object that looks like this:

const target = {
  
  /**
   * @required
   * @type string
   */
  pattern: '**/*.js',

  /**
   * @optional
   * @param {string} relativePath - The current path of the file being processed
   * @return {string} New path for the file being processed
   */
  rename: function(relativePath) {},

  /**
   * @optional
   * @param {string} content      - the current contents of the file being processed
   * @param {string} relativePath - the current path of the file being processed
   * @return {string} New contents for the file being processed
   */
  transform: function(content, relativePath) {}
  
}

Technically there's nothing stopping you from defining a target without a rename or transform methodsthat'd just be kind of pointless.

transforms.extensions: string[]

An array of file extensions that will be processed. Defaults to ['css', 'html', 'js'].

1.0.1

8 years ago

1.0.0

9 years ago