Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created February 1, 2013 03:43
Show Gist options
  • Save mkuklis/4689023 to your computer and use it in GitHub Desktop.
Save mkuklis/4689023 to your computer and use it in GitHub Desktop.
requirejs + cordova
require.config({
dir: "../../release/js/",
optimize: "uglify",
paths: {
jquery: 'vendor/jquery/jquery-1.9.0',
underscore: 'vendor/underscore',
backbone: 'vendor/backbone/backbone',
text: 'vendor/require/plugins/text',
cordova: 'vendor/android/cordova-2.3.0'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
cordova: {
exports: 'cordova'
},
app: {
deps: ['jquery', 'underscore', 'backbone', 'cordova']
}
}
});
require(['app'], function (App) {
document.addEventListener('deviceready', function () {
App.initialize();
}, false);
});
@mkuklis
Copy link
Author

mkuklis commented Feb 1, 2013

oh didn't realize these hooks exist. This doesn't look too bad. Does it work for you?

@scttnlsn
Copy link

scttnlsn commented Feb 1, 2013

Yeah, me either but they're working well. Seems like a decent compromise.

On a side note...really wish there were notifications for Gists.

@mkuklis
Copy link
Author

mkuklis commented Feb 2, 2013

Ha I was just thinking the same (regarding gists :)). I will give it a try with the hooks as well. I'm glad you found them.

@ufologist
Copy link

Tracing dependencies for: main
Error: ENOENT, no such file or directory './app/vendor/cordova/channel.js'
In module tree:
main
cordova

the above problem solution

require.config({
    shim: {
        'cordova-android': {
            exports: 'cordova'
        }
    },
    paths: {
        // don't map cordova.js with path 'cordova',
        // because it conflicts with internal module named 'cordova' in cordova.js.
        // if you map path 'cordova' with cordova-2.6.js, when it exec require('cordova/channel'),
        // will load script from cordova-2.6/channel.js,
        // because 'cordova' = 'cordova-2.6' with the path setting.
        // http://stackoverflow.com/questions/15440529/cordova-2-4-0-or-2-5-0-or-2-6-0-and-requirejs
        'cordova-android': '../lib/cordova-2.6.0'
    }
});

@zmoxga
Copy link

zmoxga commented Jun 20, 2014

do you know how to do with phonegap 3.5(not cordova 3.5 ) and rquireJs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment