I am working on a project based on KnockoutJs, RequireJs. I am developing the build system using Gulp. I want to concatenate the JS files by page. Following is my current directory structure:
- jsfiles
- libs
- Folders for various libraries
- ...
- modules
- models
- Model1.js
- Model2.js
- ...etc
- utils
- cacheManager.js
- helper.js
- dashboard.js
- header.js
- footer.js
- requireConfig.js
I have 3 different HTML template files dashboard.html, header.html, footer.html which are dependent on dashboard.js, header.js and footer.js respectively. The dashboard.js, header.js and footer.js files are dependent on the files in the /libs folder and certain files in the /modules folder.
I want to create JS bundles for each .html file. So basically I want to perform concatenation only for .js files directly under the /modules directory. I have the following Gulp task I have :
gulp.task('scripts', function() {
return gulp.src('modules/dashboard.js', {base: 'jsfiles/'})
.pipe(amdOptimize('modules/dashboard', {configFile: 'requireConfig.js', name: 'modules/dashboard', baseUrl: 'jsfiles/'}))
.pipe(concat('dashboard.js'))
.pipe(gulp.dest('dist'));
});
This is doing the required stuff for dashboard.js and creating a dashboard.js directory in the end which contains all the concatenated dependencies. I want the script to also generate the concatenated files for header.js, footer.js. I tried using 'modules/*.js' as an expression for gulp.src but amdOptimize needs me to specify the module name and so does concat expect me to specify the file name for the concatenated file. How can I make this code generic so that I can create concatenated files for other 2 JS files as well ?
Thanks