Ale*_*dre 6 javascript jquery requirejs select2
我一直在尝试在生产环境中保存一些ajax调用。为此,我捆绑并缩小了一些脚本,但是我在为select2及其翻译文件苦苦挣扎。
我在build.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'
        ]
    }
});
但是,当我尝试使用所有缩小的资源加载应用程序时,在控制台上出现错误:
未捕获的TypeError:无法读取未定义的属性'define'
在这行上:
(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过期:
未捕获的错误:模块的加载超时: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);
}})();