2013-02-22 24 views
4

我有一個使用文本插件優化的RequireJS設置。我似乎遇到了被添加到我的模塊中的'.js'文件名。我正在看這在Firefox 17.RequireJS文本插件添加'.js'到文件名,但在同一個域上

我閱讀了這個項目,但我很確定我所有的文件都在同一個域。 Why is requirejs trying to append a '.js' to .jst template files that are loaded with the !text plugin?

我的文件在位於

  • dev-img4.x.com/m/j/mains/main-article.js
  • dev-img4.x.com/m/焦耳/視圖/ logged_out.js
  • dev-img4.x.com/m/j/views/templates/logged_out.html

文本插件試圖尋找dev-img4.x.com/ m/j/views/templates/logged_out.html.js,這對我沒有意義,因爲它l ooks像我所有的依賴都在同一個域上。我不確定文本插件如何認爲存在跨域問題。

主article.js

require.config({ 
     baseUrl: 'dev.x.com/m/j', 
     paths: { 
      'jquery': 'dev.x.com/m/j/lib/jquery', 
      'backbone': 'dev.x.com/m/j/lib/backbone', 
      'underscore': 'dev.x.com/m/j/lib/underscore', 
      'text': 'dev.x.com/m/j/lib/text' 
     }, 
     shim: { 
      'underscore': { 
       exports: '_' 
      }, 
      'backbone': { 
       deps: ['jquery', 'underscore'], 
       exports: 'Backbone' 
      } 
     }, 
     urlArgs: 'buildlife=1', 
     waitSeconds: 15 
    }); 

    require(['jquery', 'modules/site', 'underscore', 'backbone', 'views/logged_out'], function($, site, _, Backbone, loggedOutView) { 
      //This function will be called when all the dependencies 
      //listed above are loaded. Note that this function could 
      //be called before the page is loaded. 
      //This callback is optional. 

      var loggedOutBar = new loggedOutView(); 

      /* Initialize code */ 
      $(document).ready(function() { 
       /* sitewide code */ 
       site.init(); 

       $('.rslogo').after(loggedOutBar.render()); 
      }); 
     } 
    ); 

logged_out.js

define(['module', 'jquery', 'underscore', 'backbone', 'text!views/templates/logged_out.html'], function(module, $, _, Backbone, loggedOutTemplate) { 
     /* Create a view of the logged out bar */ 

     var loggedOutView = Backbone.View.extend({ 
      className: 'loginbar', 
      initialize: function() { 

      }, 
      template: _.template(loggedOutTemplate), 
      render: function() { 

       this.$el.html(this.template); 

       return this; /* Allow method chaining after render */ 
      } 
     }); 

     return loggedOutView; 
    }); 

logged_out.html

<a href="#" class="signin">Sign In</a> | <a href="#" class="signup">Sign Up</a> 

回答

4

使用相對URL,你需要的是

baseUrl: '/j/' 

然後在每一個js文件在你的配置,你只需要從恢復的baseUrl

jquery: lib/jquery 

這將防止任何跨域的問題,你可能有,如果你使用需要在dev.x

的子域

另外,如果您訪問www.dev.x(dev.x的子域),這可能會導致附加'.js'的問題。用戶'liorix'在以前的帖子中發現了這個問題:https://stackoverflow.com/a/10618426/404097

使你的baseUrl相對將解決你的問題,如果這是問題。

+0

沒有www.dev.x.com域名,所以我會嘗試相對路徑。謝謝。 – Stephen 2013-02-25 01:50:53

+0

我無法使用相對路徑。我有一個奇怪的服務器設置,我無法控制/ j目錄不直接脫離域名。 :( – Stephen 2013-02-25 03:05:18

相關問題