2014-03-19 27 views
2

我使用grunt-browserify進行處理需要服務器端,然後向客戶端提供唯一的JS。Grunt Browserify - 執行兩個庫加載之間的腳本

像曝光here,我想用一個墊片加載我的庫,並將它們放在一個「vendor.js」中,然後加載我的應用程序的JS,執行需求並將結果放入「app.js」中,然後使用concat將它們放到客戶端的「main.js」文件中。

問題是,我使用jQuery的,jQuery的移動和骨幹。爲了使jqm和主幹一起使用,我必須在加載jqm庫之前禁用jqm路由器。使用簡單的腳本標記,我習慣於按照jQuery的順序加載,然後使用JavaScript禁用jQM路由器,然後jQM,然後骨幹

現在我不知道如何告訴browserify以相同的順序加載腳本。這裏是我的gruntfile(browserify部分):

browserify: { 
    vendor: { 
    src: ['client/lib/**.js'], 
    dest: 'client/build/vendor.js', 
    options: { 
     shim: { 
     jquery: { 
      path: 'client/lib/jquery-1.11.0.js', 
      exports: '$' 
     }, 
     'jquery.mobile.config': { 
      path: 'client/lib/jquery.mobile-config.js', 
      exports: null, 
      depends: { 
      jquery: '$' 
      } 
     }, 
     'jquery.mobile': { 
      path: 'client/lib/jquery.mobile-1.4.2.js', 
      exports: 'jqm', 
      depends: { 
      jquery: '$', 
      'jquery.mobile.config' : 'jquery.mobile.config' 
      } 
     }, 
     underscore: { 
      path: 'client/lib/underscore.js', 
      exports: '_' 
     }, 
     backbone: { 
      path: 'client/lib/backbone.js', 
      exports: 'Backbone', 
      depends: { 
      underscore: 'underscore' 
      } 
     } 
     } 
    } 
    }, 
    app: { 
    files: { 
     'client/app/**.js': ['client/build/app.js'] 
    } 
    } 
}, 

這裏是jquery.mobile.config腳本:

$(document).bind("mobileinit", function() { 
$.mobile.ajaxEnabled = false; 
$.mobile.linkBindingEnabled = false; 
$.mobile.hashListeningEnabled = false; 
$.mobile.pushStateEnabled = false; 

    // Remove page from DOM when it's being replaced 
    $('div[data-role="page"]').on('pagehide', function (event, ui) { 
     $(event.currentTarget).remove(); 
    }); 
}); 

總之,我試着這樣做:Backbone + JQuery Mobile + RequireJS但咕嚕-browserify代替的requirejs

回答

0

我發現了一個hacky的解決方案,其中包括jQuery的移動之前瀏覽它jjm conf腳本串聯組成。

concat: { 
    test: { 
    options: { 
     separator: ';' 
    }, 
    src : ['client/lib/jqm/jquery.mobile-config.js', 'client/lib/jqm/jquery.mobile-1.4.2.js'], 
    dest: 'client/lib/jquery.mobile-1.4.2.configured.js' 
    } 

... 

browserify: { 
    lib: { 
    src: ['client/lib/*.js'], 
    dest: 'client/build/temp/lib.js', 
    options: { 
     shim: { 
     jquery: { 
      path: 'client/lib/jquery-1.11.0.js', 
      exports: '$' 
     }, 
     'jquery.mobile': { 
      path: 'client/lib/jquery.mobile-1.4.2.configured.js', 
      exports: '$', 
      depends: { 
      jquery: '$' 
      } 
     }, 
     underscore: { 
      path: 'client/lib/underscore.js', 
      exports: '_' 
     }, 
     backbone: { 
      path: 'client/lib/backbone.js', 
      exports: 'Backbone', 
      depends: { 
      jquery: '$', 
      underscore: '_' 
      } 

這個工作,避免直接修改任何庫,但感覺很hacky。如果有人想出更好的東西,那就太好了