[英]select2 + requirejs: Cannot bundle i18n files
I've been trying to save some ajax calls on my production environment. 我一直在尝试在我的生产环境中保存一些ajax调用。 For that, I have bundled and minified some of my scripts but I'm struggling with select2 and it's translation files.
为此,我已经捆绑并缩小了我的一些脚本,但我正在努力使用select2和它的翻译文件。
I've included jQuery + bootstrap + (lots of deps) + select2 + select2 i18n files on a built.js and set the shim values (tho i don't think it's needed). 我在built.js中包含了jQuery + bootstrap +(很多deps)+ select2 + select2 i18n文件并设置了垫片值(因为我认为不需要它)。
Both jquery and select2 are pasted before the i18n files. jquery和select2都粘贴在i18n文件之前。
Added the following config (on production environment): 添加了以下配置(在生产环境中):
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'
]
}
});
However, when I try to load my application with all minified resources I get an error on the console: 但是,当我尝试使用所有缩小的资源加载我的应用程序时,我在控制台上收到错误:
Uncaught TypeError: Cannot read property 'define' of undefined
未捕获的TypeError:无法读取未定义的属性'define'
On this line: 在这一行:
(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()
After few seconds when waitSecondsTimeout expires: 在waitSecondsTimeout到期后几秒钟:
Uncaught Error: Load timeout for modules: select2/i18n/pt-BR,select2/i18n/es,select2/i18n/en
未捕获错误:模块加载超时:select2 / i18n / pt-BR,select2 / i18n / es,select2 / i18n / en
Application works well without the built files. 没有内置文件,应用程序运行良好。
I had a similar problem not sure what caused it, deferred loading, or browser using multiple threads to load up javascript, but I solved it by wrapping the i18n file function with this 我有一个类似的问题,不知道是什么导致它,延迟加载,或浏览器使用多个线程加载JavaScript,但我解决了它通过包装i18n文件函数与此
(function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd){
^
Note the added accolade. 请注意添加的荣誉。
Then at the end of the file, before the last accolade I added 然后在文件的最后,在我添加的最后一个荣誉之前
}
else {
window.setTimeout(arguments.callee,10);
}})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.