Arjun T Raj Arjun T Raj - 10 months ago 98
Javascript Question

Phonegap + require Js

How can we use Phonegap with require js ? I am try to add to phonegap using the require() method. My code is given below and all .js files are in the correct location. Please help me, it is able to load phonegap via AMD , or Use Normal script method like

<script type="text/javascript" src="cordova.js"></script>

this is my require config and methods


baseUrl: 'js/lib',

paths: {
controller: '../controller/controller',
model: '../model/model',
view: '../view/view',

/* map: {
'*': {
'tempName': 'actualName'

shim: {
'backbone': {
deps: ['underscore', 'jquery','cordova'],
exports: 'Backbone'
'underscore': {
exports: '_'

require(['jquery', 'backbone', 'router', ], function ($, Backbone, Router) {

document.addEventListener('deviceready', function () {
alert('hi'); // working
navigator.notification.alert('hi'); // not working

}, false);



Requirejs and Phonegap tends to not work too well together.

The best way I have found is to just include the cordova script before your require modules.

<script type="text/javascript" src="cordova-2.7.0.js"></script>
<script data-main="js/main" src="require.js"></script> 

Check the answer for this question. He gives good insight into some of the problems faced.