我一直在尝试在我的生产环境中保存一些 ajax 调用。为此,我捆绑并缩小了我的一些脚本,但我正在努力处理 select2 及其翻译文件。
我在 built.js 上包含了 jQuery + bootstrap +(很多 deps)+ select2 + select2 i18n 文件并设置了 shim 值(虽然我认为不需要)。
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()
几秒后 waitSecondsTimeout 到期:
Uncaught Error: Load timeout for modules: select2/i18n/pt-BR,select2/i18n/es,select2/i18n/en
应用程序在没有构建文件的情况下运行良好。
最佳答案
我有一个类似的问题,不知道是什么原因导致的,延迟加载,或者浏览器使用多线程加载 javascript,但我通过用这个包装 i18n 文件函数解决了这个问题
(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd){
^
注意增加的荣誉。
然后在文件末尾,在我添加的最后一个赞誉之前
}
else {
window.setTimeout(arguments.callee,10);
}})();
关于javascript - select2 + requirejs : Cannot bundle i18n files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39649078/