2013-02-22 101 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

相关问题