I'm trying to optimize my javascript project with r.js optimizer from requirejs. I use both amd and non-amd modules in my project. There will be two environments, one with requirejs environment and the other with no requirejs environment.The files at the non-requirejs environment should not have on require or define calls. While combining amd-modules into bundles using r.js it is fine to have a define call with bundle name at the end of the file. But for the non-requirejs environment after the files have been optimized, they are also getting a define insertion at the end of the file with the module name.

Let's take I have four files A and B which are AMD-modules and C and D are non-AMD modules.

my build.js is like this

({
    appDir: "../",
    baseUrl: "./",
    dir : "../../../output",
    paths: {
        A : '../somepath/to/A',
        B : '../somepath/to/B'
    },
    modules : [
        {
            name : 'bundle1',
            create : true,
            include : ['A', 'B']
        },
        {
            name : 'bundle2',
            create : true,
            include : ['C', 'D']
        }
    ],
    // removeCombined : true,
    cjsTranslate: false,
    optimizeCss : "none",
    skipModuleInsertion: true,
    optimize: "uglify",
    fileExclusionRegExp: /^(((r|app.build)\.js)|(v0))$/,
    keepBuildDir: false,
    bundlesConfigOutFile: "bundles.js",
    onModuleBundleComplete : function(data) {
        console.log(data)
    }

})

This is the bundles amd-file looks like.

define('A', function(){
 //some stuff of A
});
define('B', function(){
 //some stuff of B
});
define('bundle1',function(){});

The bundled non-amd file looks like

//some stuff of C
});
//some stuff of D
define('bundle2',function(){});

How to resolve this situation. I have gone through the optimization docs and example.build.js. still couldn't figure out the way. Am I missing something ? Is there a way to exclude that define call at the end of the non-amd-modules. If yes, How ?

1

There are 1 answers

0
Aziz Khambati On

I see you have used skipModuleInsertion option which based on the documentation should have helped you. I am not sure why it didn't.

Another option you can use is after the build is complete before writing to file, you can remove that particular define call using onBuildWrite