npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grunt-preprocess

v5.1.0

Published

Preprocess HTML and JavaScript directives based off environment configuration

Downloads

27,669

Readme

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:

  • \r\n - Windows
  • \n - Linux/OSX/Unix
  • \r - legacy Mac

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

  • 5.1.0
    • Grunt peer dependency tagged >= 0.4.0, dependency updates
    • added explicit dependency on lodash
    • added logging for preprocess errors (@marcominetti, #53)
  • 5.0.1 fixed processing of mutifile-style tasks for multiple different file extensions or different containing directories (#50)
  • 5.0.0 bumped preprocess dep to 3.0.2, implemented backward-compatible mapping of old to new options and pass-through for new options (#34, #39, #48)
  • 4.2.0 bumped preprocess dep to 2.3.1, bumped dev dependencies
  • 4.1.0 bumped preprocess dep to 2.1.0
  • 4.0.0 Switched order of context assignment, small change but necessitated major version
  • 3.0.1 Fixed issue arising from undefined options (#19)
  • 3.0.0 Updated dependencies, added merge from global options context to subtask context (#13)
  • 2.3.0 Updated preprocess, changes default handling to html
  • 2.2.0 Delegating to grunt's file.read/write for consistent usage within grunt (e.g. deep writes)
  • 2.1.0 updated preprocess dependency
  • 2.0.0 updated for grunt 0.4.0, moved context override to context option
  • 1.3.0 Moved logic to 'preprocess' npm module
  • 1.2.1 Added @include to include external files
  • 1.2.0 Added @include to include external files
  • 1.1.0 Added ability to process multiple destinations in a files block
  • 1.0.0 Changed syntax, added directives
  • 0.4.0 Added support for inline JS directives
  • 0.3.0 Added insert, extended context to all environment
  • 0.2.0 Added simple directive syntax
  • 0.1.0 Initial release

License

Written by Jarrod Overson

Licensed under the Apache 2.0 license.