angularjs - Concat javascript files under a single file -


file structure.

/app    /components       /core          /extensions            - array.js             - string.js         /services            - logger.js          /lib             - core.js  

core.js

(function() {      'use strict';      angular.module('app.core',[]);   }()); 

what need overwrite core.js on each build copying other js files in folder on it, while keeping first original content of module deceleration.

this wanted result core.js :

(function() {      'use strict';      angular.module('app.core',[]);   }()); // content of array.js (function() {    'use strict';      var core = angular.module('app.core');     core.config( .....)   }());        // content of string.js  ...  // content of logger.js 

iv'e tried 2 grunt tasks believed men't purpose did not find way configure them needs.

1) grunt-concat had 2 issues first appends contents start of file , not end of file wanted. , not override existing content.

2) grunt-copy override overrides entire file.

what iv'e attempted use process function grunt copy.

  copy: {       src: ['app/components/core/{,*/}*.js'],       dest: 'app/components/core/lib/core.js',       options:{           process : function(content, srcpath){               return content; // manipulation on content here.            }       }            } 

this problematic since have keep text comprises angular module definition in gruntfile , append first content comes process function, seems messy.

 process : function(content, srcpath){               if(isfirst) {                   isfirst = false;                   // here append angular module deceleration.                }               return content;           } 

is there elegant way achieve iv'e described ?

grunt-contrib-concat need, following:

  1. rename current core.js _banner.js (or like) - it's practice not overwrite banner file anyway
  2. setup concat agregate _banner.js other files, , save core.js:

    concat: {   core: {     files: [{       src: [         'app/components/core/_banner.js',         'app/components/core/extensions/*.js',         'app/components/core/services/*.js'       ],       dest: 'app/components/core/lib/core.js'     }]   }, }, 

should give want


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -