Require output to a single file, excluding jQuery, without preserving the dependency?

I am using the requirejs optimizer to minimize my modules into a single file for production. However, I want to exclude jQuery from the file so that it can be downloaded separately from the real application logic, how can I achieve this? I tried to configure this with the exclude and excludeShallow parameters, but when I start the page, I get the following error:

Untrained ReferenceError: jQuery undefined app.min.js: 14 (anonymous function) app.min.js: 14

My grunt configuration for requirejs looks like this:

requirejs: {
        minify: {
            options: {
                baseUrl: 'js',
                mainConfigFile: 'js/main.js',
                name: 'main',
                out: 'js/app.min.js',
                excludeShallow: [
                    'jquery'
                ]
            }
        }
    }

Many thanks!

+5
source share
3 answers

Here's how: http://requirejs.org/docs/optimization.html#empty

:

({
    baseUrl: ".",
    name: "main",
    out: "main-built.js",
    paths: {
        jquery: "empty:"
    }
})
+2

jQuery app.min.js , excludeShallow. * nix.

( app.min.js? .)

+1

I assume that you are using some libraries that depend on jQuery. Do you use the washer option to indicate a dependency?

I mean, yours js/main.jsshould contain the configuration as shown below:

shim: {
  'some-library': ['jquery']
}
0
source

All Articles