Kalamarico
Kalamarico

Reputation: 5666

different ways to parse and build with Grunt

In my project, i use an external library that it has some private functions on its local scope, it seems like this:

(function(window, undefined) {

var isArray = function() {...}
var forEach = function() {...}
var int = function() {...}
{(this))

The external lib gives me some funcionality, but additionally i will use these functions i mentioned in my project, so, I need to put externalLib private functions on window scope. To avoid that, i'm going to build myLib.js with my code and the externalLib code. So, i need to put some code from externalLib.js (basically i only need to remove first and last line from the code). What do you think about the best form to accomplish this task in GruntJS? I hope I explained well

Upvotes: 0

Views: 529

Answers (1)

Sergey Rybalkin
Sergey Rybalkin

Reputation: 3026

You can preprocess files during grunt.js build using grunt-preprocess module. This requires some additional directives in your code:

// @ifdef DEBUG
(function(window, undefined) {
// @endif

    var isArray = function() {...}
    var forEach = function() {...}
    var int = function() {...}

// @ifdef DEBUG
{(this))
// @endif

Where DEBUG can be any environment variable added either via command line switch or configuration file.

Also you can use @exclude directive that will simply remove code from grunt.js processed files. More on this here - https://github.com/onehealth/preprocess#directive-syntax

Upvotes: 3

Related Questions