preprocess-mallowigi2.1.1 • Public • Published
What does it look like?
Your App<!-- @if NODE_ENV='production' --><!-- @endif --><!-- @ifdef DEBUG -->Debugging mode - <!-- @echo RELEASE_TAG --><!-- @endif --><!-- @include welcome_message.txt -->
var configValue = '/* @echo FOO */' || 'default value';// @ifdef DEBUG// @endif
The most basic usage is for files that only have two states, non-processed and processed.
In this case, your
@exclude directives are removed after preprocessing
<!-- @exclude -->You're on dev!<!-- @endexclude -->
@endifThis will include the enclosed block if your test passes
@endifThis will include the enclosed block if VAR is defined (typeof !== 'undefined')
@endifThis will include the enclosed block if VAR is not defined (typeof === 'undefined')
@includeThis will include the source from an external file. If the included source ends with a newline then the following line will be space indented to the level the @include was found.
@endexcludeThis will remove the enclosed block upon processing
@echo VARThis will include the environment variable VAR into your source
@exec FUNCTION([param1, param2...])This will execute the environment FUNCTION with is parameters and echo the result into your source. The parameter could be a string or a reference to another environment variable.
Extended html Syntax
This is useful for more fine grained control of your files over multiple environment configurations. You have access to simple tests of any variable within the context (or ENV, if not supplied)
<!-- @if NODE_ENV!='production' -->You're on dev!<!-- @endif --><!-- @if NODE_ENV='production' --><!-- @endif -->
NODE_ENV set to
COMMIT_HASH this will be built to look like
With NODE_ENV not set or set to dev and nothing in COMMIT_HASH, the built file will be
You're on dev!
You can also have conditional blocks that are hidden by default by using the
!> end tag instead of
--> after your condition:
<!-- @if true !><p>Process was run!</p><!-- @endif -->
Extended syntax below, but will work without specifying a test
;//@exclude//@endexclude'/* @echo USERNAME */';
Built with a NODE_ENV of production :
Like HTML, you can have conditional blocks that are hidden by default by ending the directive with a
** instead of
Note: It doesn't work with simple style comments.
(CSS preprocessing supports single line comment style directives)
#!/bin/bash# @include util.sh
Configuration and Usage
Install via npm
$ npm install --save preprocess
Use the exposed
preprocess method or the convenience file functions. The context, by default, is the
current ENV config the process (
var pp = ;var text = 'Hi, I am <!-- @echo USERNAME -->';pp;// -> Hi, I am jsoversonpp;// -> Hi, I am Bob// specify the format to use for the directives as the third parameterpp;// -> Hi, I am Bob// Simple wrapper around fs.readFile and fs.writeFilepp;// Simple wrapper around fs.readFileSync and fs.writeFileSyncpp;
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 jshint
- 2.1.0 Added automatic support for numerous formats, merged @exec, hidden by default html tags, added simple directives
- 2.0.0 Added ability to echo strings, added conditional comments, removed lodash, merged 17, 13, 15, 16
- 1.2.0 Added processing for hash-style comments (via @marsch). Added more file aliases.
- 1.1.0 Added deep inclusion, fixed sequential ifs
- 1.0.1 Fixed multiple inline echo statements
- 1.0.0 Pulled from grunt-preprocess to stand alone
Copyright Jarrod Overson
Written by Jarrod Overson
Licensed under the Apache 2.0 license.