Grunt Strip Code

1.0.12 · maintenance · verified Tue Apr 21

grunt-strip-code is a Grunt plugin designed to remove specific sections of code from files during the build process, typically used to strip development or test-only code from production builds. It operates by identifying code blocks marked with configurable start and end comments (e.g., `/* test-code */` and `/* end-test-code */`) or by matching custom regular expressions. The current stable version is 1.0.12, published in June 2019. While the Grunt ecosystem is generally in maintenance mode compared to newer build tools, this plugin offers specific functionalities like parity and intersection checks for defined code blocks, helping to prevent accidental removal or retention of code. Its primary differentiation is its integration within the Grunt task runner for conditional code compilation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure and run `grunt-strip-code` to remove comment-delimited code blocks from JavaScript files, showcasing a common use case for excluding testing utilities like Istanbul ignores from production builds.

/* Gruntfile.js */
module.exports = function(grunt) {
  grunt.initConfig({
    strip_code: {
      options: {
        blocks: [
          {
            start_block: "/* istanbul ignore next */",
            end_block: "/* end-istanbul ignore next */"
          }
        ],
        parityCheck: true
      },
      main: {
        src: 'src/**/*.js'
      }
    }
  });

  grunt.loadNpmTasks('grunt-strip-code');

  grunt.registerTask('default', ['strip_code']);
};


/* src/app.js */
function publicFunction() {
  console.log('This function should always be present.');
}

/* istanbul ignore next */
function privateDevFunction() {
  console.log('This function is for development/testing only.');
}
/* end-istanbul ignore next */

publicFunction();

/* Another block for testing */
/* istanbul ignore next */
console.log('Another dev-only line.');
/* end-istanbul ignore next */

view raw JSON →