Home

Awesome

grunt-preprocess

NPM

Linux Build Status dependencies dev-dependencies

Grunt task around preprocess npm module

What does it look like?

<head>
  <title>Your App</title>

  <!-- @if NODE_ENV='production' -->
  <script src="some/production/lib/like/analytics.js"></script>
  <!-- @endif -->

</head>
<body>
  <!-- @ifdef DEBUG -->
  <h1>Debugging mode - <!-- @echo RELEASE_TAG --> </h1>
  <!-- @endif -->
  <p>
  <!-- @include welcome_message.txt -->
  </p>
</body>
var configValue = '/* @echo FOO */' || 'default value';

// @ifdef DEBUG
someDebuggingCall()
// @endif

See preprocess documentation for more information

Getting Started

Install this grunt plugin next to your project's Gruntfile with: npm install --save-dev grunt-preprocess

Then add this line to your project's Gruntfile:

grunt.loadNpmTasks('grunt-preprocess');

Options

context

Type: Object Default: {NODE_ENV: 'development'}

The additional context on top of ENV that should be passed to templates. If NODE_ENV is not set, the task sets it to development by default.

inline

Type: Boolean Default: undefined

Required to enable overwriting of source files

srcDir

Type: String Default: <path to source file to be processed>

The directory where to look for files included via @include variants and @extend.

srcEol

Type: String Default: EOL of source file or os.EOL if source file contains multiple different or no EOLs.

The end of line (EOL) character to use for the preprocessed result. May be one of:

type

Type: String Default: file extension of the file to be processed

The syntax type of source file to preprocess. See preprocess() description for a list of all supported file types.

Example Usage

preprocess : {
  options: {
    context : {
      DEBUG: true
    }
  },
  html : {
    src : 'test/test.html',
    dest : 'test/test.processed.html'
  },
  js : {
    src : 'test/test.js',
    dest : 'test/test.processed.js'
  },
  multifile : {
    files : {
      'test/test.processed.html' : 'test/test.html',
      'test/test.processed.js'   : 'test/test.js'
    }
  },
  inline : {
    src : [ 'processed/**/*.js' ],
    options: {
      inline : true,
      context : {
        DEBUG: false
      }
    }
  },
  all_from_dir: {
    src: '**/*.tmpl',
    ext: '.html',
    cwd: 'src',
    dest: 'build',
    expand: true
  }
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

License

Written by Jarrod Overson

Licensed under the Apache 2.0 license.