javascript - How to remove (function(){'use strict'; } and ()); when concatenating with grunt-contrib-concat -


i can concatenate files in proper order , can add (function(){'use strict'; top , }()); bottom of output file don't know how remove (function(){'use strict'; , }()); individual files before concatenating.

i read through docs , tried using custom process example , know need make changes line src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1'); unfortunately don't understand line or how change it.

lastly, don't know if matters make change. when concat , minify code, leave is, , don't add banner , footer works fine. there benefit replacing individual use-stricts one?

from gruntfile

concat: {     options: {         banner: "(function(){'use strict';\n",         footer: '}());',         process: function(src, filepath) {             return '// source: ' + filepath + '\n' +                 src.replace(/(^|\n)[ \t]*('use strict'|"use strict");?\s*/g, '$1');         }     },     nonmin: {         src: ['src/angular-gmap-gplace.js', 'src/modules/*.js'],         dest: 'dist/angular-gmap-gplace.js'     },     min: {         src: ['src/**/*.js'],         dest: '.tmp/concat.js'     } } 

is there benefit replacing individual use-stricts one?

no. there drawbacks.

using iife in each file means each file has it's own scope and, unless deliberately create global, can't interfere other files.

if merge them single iife no longer true, , share scopes each other. risk accidentally overwriting variable used 1 file identically named variable in different file.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -