Exclude single file from requirejs optimization

121 views
Skip to first unread message

Dave

unread,
Jan 20, 2015, 4:19:37 PM1/20/15
to mimo...@googlegroups.com
Hello,

I'm trying to build a project and I want to optimize all my require modules into a single file, except for one. The one exclusion (called globals.js) will contain configuration parameters, so I want it to be separate and easily editable.

What is the correct way to do this? I tried using the exclude array in the require configuration in as many variations as I could think of, but I could not get it to work.

Now I'm trying using a 'modules' config, but I get an exception (copied at end below). Here's the config I have now (with various exclude permutations I tried commented out)

exports.config = {

minMimosaVersion:'2.0.0',

modules: [
"copy",
"less",
"require",
"requirebuild-include",
"requirebuild-textplugin-include"
],

watch: {
sourceDir: "source",
compiledDir: "distribution",
javascriptDir: "javascripts/app"
},

vendor: {
javascripts: "javascripts/lib"
},

copy: {
extensions: ["js","css","png","jpg","jpeg","gif","html","eot","svg","ttf","woff","otf","yaml","kml","ico","htc","htm","json","txt","xml","xsd","map","md","mp4","pdf"],
exclude: [
/jquery-ui\\development-bundle/,
/require\\r.js/,
/knockout\\.*debug.*/,
/font-awesome/
]
},

requireBuildTextPluginInclude: {
folder: '.',
pluginPath: 'text',
extensions: ['html']
},

requireBuildInclude: {
folder:"javascripts",
patterns: ['app/**/*.js', 'lib/durandal/**/*.js'],
exclude:['/-built.js$/','/reload-client.js$/']
},

require: {
// exclude : [/globals/],
// exclude : [/globals\.js/],
// exclude : ['globals'],
// exclude : ['globals.js'],
// exclude : ['distribution/javascripts/app/globals.js']
// exclude : ['./distribution/javascripts/app/globals.js'],
// exclude : ['source/javascripts/app/globals.js'],
// exclude : ['./source/javascripts/app/globals.js'],

optimize: {
modules: [
{
name: 'main',
include : [],
excludeShallow : ['globals']
},
{ name: 'globals',
include: []
}
],
overrides: {
mainConfigFile: "source/javascripts/app/main.js",
name: '../lib/require/almond-custom',
inlineText: true,
stubModules: ['text'],
pragmas: {
build: true
}
}
}
}
};

Exception with modules config:

C:\Dev\CVT\node_modules\mimosa-requirebuild-include\index.js:100
return runConfig.include.push(fileAMD);
^
TypeError: Cannot call method 'push' of undefined
at C:\Dev\CVT\node_modules\mimosa-requirebuild-include\index.js:100:34
at Array.forEach (native)
at C:\Dev\CVT\node_modules\mimosa-requirebuild-include\index.js:88:20
at Array.forEach (native)
at C:\Dev\CVT\node_modules\mimosa-requirebuild-include\index.js:60:47
at Array.forEach (native)
at Array._appendFilesToInclude [as 0] (C:\Dev\CVT\node_modules\mimosa-requirebuild-include\index.js:55:22)

Thanks for any help you can offer.

dbashford

unread,
Jan 22, 2015, 10:54:24 PM1/22/15
to mimo...@googlegroups.com, dshef...@oculusinfo.com
The require.exclude config doesn't have anything to do with r.js.  You would use require.exclude if, for instance, mimosa-require was flagging the wrong file as a "root" file for your application and creating a bundle with it.  Or if there was one file that had a very odd configuration and was consistently failing path verification.

The below would keep jquery out of an optimized bundle. 

require: {
    optimize: {
      overrides: {
        exclude: ["vendor/jquery/jquery"]

Dave

unread,
Jan 23, 2015, 11:03:48 AM1/23/15
to mimo...@googlegroups.com, dshef...@oculusinfo.com
Thanks for that tip. I swear I tried putting the exclude there on an earlier iteration and it hadn't worked, but clearly I must have made a mistake. I seem to have it working now. Your explanation helped me solve another problem as well, so thanks for the 2-fer!

Dave
Reply all
Reply to author
Forward
0 new messages