1

I'm currently trying to create separate modules within the requirejs optimiser config which currently looks like: Module based setup (fails to skip facebook path):

({
        baseUrl: '../static/js',
        mainConfigFile: '../static/js/main.js',
        dir: '../static/js/deploy',
        paths:{
            requireLib: 'vendor/require/require.min',
            _core: 'minify_modules/_core',
            search: 'minify_modules/_search'
        },

        modules:[
            {
                name: 'main',
                include: ['requireLib', '_core']
            },
            {
                name: 'search',
                include:['search']
            }
        ]
    })

Within one of my requirejs modules I require the facebook SDK. When I run the optimiser the optimiser fails to skip the directory and reports:

Error: JavaException: java.io.FileNotFoundException: /connect.facebook.net/en_US/all.js (No such file or directory)

Originally I used the non module method and had a single output file. When I ran that setup it would skip external resources like Facebook SDK so I'm obviously a little confused why the below setup will skip the directory and module based setup above will not.

Non-module based setup (skips facebook path)

    ({
    baseUrl: '../static/js',
    mainConfigFile: '../static/js/main.js',
    name: 'main',
    out: '../static/js/yb-scripts.min.js',
    paths: {
        requireLib: 'vendor/require/require.min',
        _core: 'minify_modules/_core'
    },
    include: ['requireLib', '_core']
})

The Facebook SDK is referenced in main.js config file:

facebookSDK: '//connect.facebook.net/en_US/all',

I've been trying to follow the optimiser notes here: LINK

Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
Malcr001
  • 8,179
  • 9
  • 44
  • 57

1 Answers1

2

You can specify in your paths property to skip minimizing a certain module because it is served from an external resource:

paths: {
  requireLib: 'vendor/require/require.min',
  _core: 'minify_modules/_core',
  facebookSDK: 'empty:'
},

See the RequireJS docs for empty: for more details.

On a side note, I didn't realize the optimization process for a single file would actually skip external resources by default. I usually still specify empty: for all the JS libraries since I use CDNs with fallback, such as jquery: ["http://code.jquery.com/jquery-1.10.1.min", "../bower_components/jquery/jquery.min"].

Herman Tran
  • 1,581
  • 2
  • 12
  • 19
  • Thanks this got me a little further. Do you know what this means: Tracing dependencies for: main Error: nope In module tree: _core controllers/search/searchCtrl – Malcr001 Nov 03 '13 at 17:21
  • Did you check the file path of that controller module? It does seem weird that it wouldn't be tracing given that your single file config and module config are the same. Or is it the omitted `search` path that you had in the single file config? – Herman Tran Nov 03 '13 at 17:36
  • The file path is correct. This error only shows up when using the multiple module method. The _core module contains paths to other modules which include this search controller. I'm going to mark your answer as correct as you technically have solved my problem. I just have this strange Error: nope problem now. – Malcr001 Nov 03 '13 at 18:54