Search code examples
javascriptgrunt-contrib-requirejsrequirejs-optimizeralmond

RequireJS Optimizer: Exclude specific libs


My build process combines every application script and vendor lib into one single .min.js-file. Now, let's say one of this vendor libs is jQuery. My application will run in an environment where jQuery is already used. So I don't need to include jQuery in my build. However, in my application prototype (development environment) I still need it, so it can only be removed in the build process.

So when building my .min.js-file I would need to exclude jQuery, but the application should still work and dependencies should still be resolved correctly.

My grunt-contrib-requirejs build looks like:

/**
 * JavaScript/RequireJS compilation/compression
 * with almond
 */
requirejs: {
    prod: {
        options: {
            /**
             * Use Uglify2 with
             * compressed output
             * and generate a .map-file
             */
            optimize: 'uglify2',
            // needs to be false if preserveLicense is true
            generateSourceMaps: false,
            preserveLicenseComments: true,
            uglify2: {
                output: {
                    beautify: false
                }
            },
            /**
             * Generate the output
             * as a single file to the build folder
             */
            name: '../../<%= project.almond %>',
            baseUrl: '<%= project.scripts %>',
            mainConfigFile: '<%= project.scripts %>/main.js',
            include: 'main.js',
            out: '<%= project.dist.web %>/js/app.min.js'
        }
    }
}

Is there a predefined way to solve it? Or any workaround idea?


Solution

  • This can be done using the empty option in the Optimizer. See the docs for more information.