Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Concatenate and minify a RequireJs based project with amd-optimize and gulp-concat

2996482May 31 2016 — edited Jun 1 2016

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

This post has been answered by Jim.Marion-Oracle on May 31 2016
Jump to Answer
Comments
Post Details
Added on May 31 2016
2 comments
802 views