I have structure like:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With