Phillip Whisenhunt
Phillip Whisenhunt

Reputation: 1305

r.js optimization is not preserving paths

I'm using r.js optimization with CDN assets set to :empty in the paths configuration. However, when I hit the optimized file, require is not fetching the CDN assets. Specifically it is not reaching out for jQuery. I'm also using the grunt requirejs task.

Here is my require.js config:

require.config({
  paths: {
    jquery               :'//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min'
  }
});

And here is the grunt.js config:

    requirejs: {
        compile: {
            options: {
                baseUrl: "public/resources/javascripts/",
                mainConfigFile: "public/resources/javascripts/main.js",
                out: "public/resources/javascripts/main-build.js",
                paths: {
                    'jquery': 'empty:'
                },
                name: "main",
                generateSourceMaps: true,
                optimize: "uglify2",
                preserveLicenseComments: false
            }
        }
    }

And I'm hitting the built asset as:

<script data-main="/resources/javascripts/main-build.js" src="/resources/javascripts/libs/require.js"></script>

Upvotes: 0

Views: 137

Answers (1)

Simon Boudrias
Simon Boudrias

Reputation: 44609

You must add the resources loaded from a CDN inside the exclude array too. Otherwise, the module is included, simply empty.

exclude: [ "jquery" ]

On a side note, loading jQuery from a CDN will be slower than bundling it into your builded file. You shouldn't use a CDN in this case.

Upvotes: 1

Related Questions