Frage

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

War es hilfreich?

Lösung

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"].

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top