Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt require fails to create multiple modules as expected

I have structure like:

  • app
    • scripts
      • libs
        • jquery.js
        • bootstrap.js
        • moment.js
      • app.js
      • vendor.js
      • common.js
      • app.config.js
      • main.js #require config

Note vendor.js is just a file that includes all files under libs. Ex

//vendor.js define(['jquery','bootstrap', 'moment'], function(){});

Just to list out the dependencies:

  • app.js depends on common.js and app.config.js
  • common.js depends on vendor.js
  • app.config.js depends on moment.js

What I'm trying to do is run the grunt requirejs command to create a vendor.js file with all files under libs/ and a app.js with the rest of the files not included in vendor.js.

Here is what my requirejs options looks like:

module.exports = function (grunt) {
    'use strict';
    var config = {
        dist: {
            options: {
                appDir: 'app/',
                baseUrl: './scripts',
                mainConfigFile: 'app/scripts/main.js',
                dir: 'dist/scripts/',
                modules: [
                    { name: 'vendor'},
                    { name: 'app', exclude: ['vendor'] }
                ]
            }
        }
    };
    grunt.config('requirejs', config);
};

What I get from running the above is the following build.txt

scripts/vendor.js
----------------
scripts/libs/jquery.js
scripts/libs/bootstrap.js
scripts/libs/moment.js
scripts/app.js
scripts/vendor.js
scripts/common.js
scripts/app.config.js

scripts/app.js
----------------

As you can see all the files are just appended to vendor.js and not app.js. I would expect vendor.js to include vendor.js and its dependencies. And app.js to include the rest since vendor is excluded.

I've tried numerous combination and still a nogo here.

like image 329
dchhetri Avatar asked Jan 27 '17 22:01

dchhetri


1 Answers

Found the issue! The problem was with my require config file thats feed to the grunt requirejs task. The require config file had deps: ['app'] code, which conflicted when trying to split up into modules because as soon as the require config was feed to the grunt requirejs task, it seen app as necessary dependency, which meant app and all its files were marked as dependent and thus included in the first module file listed.

like image 56
dchhetri Avatar answered Nov 03 '22 15:11

dchhetri