spinners
spinners

Reputation: 2679

Problems using grunt-preprocess

I am trying to use grunt-preprocess module but having difficulty getting ifdefs to work.

Here is my gruntfile

module.exports = function(grunt) {
// Configuratuion goes here

grunt.initConfig({

  preprocess : {

    options: {
      context : {
        DEBUG: false
      }
    },

    html : {
      src : 'dev/index.html',
      dest : 'dev/index.processed.html'
    }

  }
});

grunt.loadNpmTasks('grunt-preprocess');
grunt.registerTask('default', ['preprocess']);
}

and this is my html

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<div id="wrap">

<!-- @ifdef DEBUG -->
  <h1>Test Page</h1>
<!-- @endif -->

<!-- @exclude -->
<header>You're on dev!</header>
<!-- @endexclude -->

<p>Test Pragraph</p>

<div id="output"></div>

</div>

</body>
</html>

But when I run grunt the code between the DEBUG ifdef is not removed (although the ifdef comments themselves are removed)

I have a feeling that I am missing some critical step that is not mentioned in the documentation.

Thanks

Upvotes: 0

Views: 1226

Answers (1)

hereandnow78
hereandnow78

Reputation: 14434

see the documentation:

@ifdef VAR / @endif This will include the enclosed block if VAR is defined (typeof !== 'undefined')

your DEBUG-Var is defined (its value is a boolean), so your block will be included. remove it completly, and it should work:

options: {
  context : {}
}

Upvotes: 1

Related Questions