karma-generic-preprocessor

1.1.1 • Public • Published

karma-generic-preprocessor

Provides a way to define preprocessors inline in the karma configuration files. This can be very handy in some situations, for example:

  • URL rewriting
  • using exotic JS / CSS preprocessors without having to write dedicated plugin
  • whatever else you decide to do :)

Installation

npm install karma-generic-preprocessor --save

Note: Karma will automatically see and include plugins whose names start with karma-*. However, it is possible that, in your IDE or console configurations, you're running Karma as a global Node module. In that case, you'll have to install this plugin too globally, i.e

npm install karma-generic-preprocessor -g

Configuration and Usage

// karma.conf.js
module.exports = function(config) {
  config.set({
    preprocessors: {
      // it's probably best to keep this as generic as possible
      // since `karma-generic-preprocessor` has it's own matcher
      '**/*': ['generic'] 
    },
    genericPreprocessor: {
      rules: [{
        // this will always be matched on original path, even
        // if you change file.path in of the `process` functions
        match: "*.coffee",
        // almost  same as karam-coffee-preprocessor
        process: function (content, file, done, log) {
          file.path = file.originalPath.replace(/\.coffee$/g, '.js');
          try {
            done(coffee.compile(content));
          } catch (e) {
            log.error('%s\n  at %s', e.message, file.originalPath);
          }
        }
      }, {
        // if no match is specified all the files matched by
        // `preprocessors` config above will be processed
        process: function (content, file, done, log) {
          log.debug('Processing "%s".', file.originalPath);
          done(content);
        }
      }]
    }
  })
}

LICENSE

Available under MIT style license.

Dependents (7)

Package Sidebar

Install

npm i karma-generic-preprocessor

Weekly Downloads

3,916

Version

1.1.1

License

MIT

Unpacked Size

5.05 kB

Total Files

4

Last publish

Collaborators

  • grassator