2016-09-22 89 views
4

我一直试图在我的生产环境中保存一些ajax调用。为此,我捆绑并缩小了一些脚本,但我正在努力使用select2,它是翻译文件。select2 + requirejs:无法捆绑i18n文件

我已经在built.js中包含了jQuery + bootstrap +(很多deps)+ select2 + select2 i18n文件,并设置了填充值(我不认为这是需要的)。

jquery和select2都粘贴在i18n文件之前。

增加了以下配置(生产环境):

requirejs.config({ 
    bundles: { 
     'built': [ 
      'jquery', 
      'bootstrap', 
      'highcharts', 
      'bootbox', 
      'datatables', 
      'datatables-bootstrap', 
      'i18n', 
      'moment', 
      'knockout', 
      'knockout-mapping', 
      'pnotify', 
      'pnotify.nonblock', 
      'pnotify.desktop', 
      'pnotify.buttons', 
      'select2/select2', 
      'select2/i18n/pt-BR', 
      'select2/i18n/es', 
      'select2/i18n/en' 
     ] 
    } 
}); 

然而,当我尝试了所有精缩资源我得到的控制台上的错误装入我的应用程序:

Uncaught TypeError: Cannot read property 'define' of undefined

在此线上:

(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd)var e=jQuery.fn.select2.amd;return e.define("select2/i18n/pt-BR",[],function() 

几秒钟后等待SecondsTimeout expires:

Uncaught Error: Load timeout for modules: select2/i18n/pt-BR,select2/i18n/es,select2/i18n/en

应用程序运行良好,没有构建的文件。

回答

0

我有一个类似的问题,不知道是什么原因引起的,延迟加载,或者使用多线程加载JavaScript的浏览器,但我用这个

(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd){ 
                     ^

注意添加包裹的i18n文件功能解决了这个问题荣誉。

在文件的结尾

然后,最后的荣誉之前,我加入

} 
else { 
    window.setTimeout(arguments.callee,10); 
}})();