【问题标题】:select2 + requirejs: Cannot bundle i18n filesselect2 + requirejs:无法捆绑 i18n 文件
【发布时间】:2017-01-31 14:58:26
【问题描述】:

我一直在尝试在我的生产环境中保存一些 ajax 调用。为此,我捆绑并缩小了我的一些脚本,但我在 select2 和它的翻译文件上苦苦挣扎。

我在 build.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'
        ]
    }
});

但是,当我尝试使用所有缩小的资源加载我的应用程序时,我在控制台上收到错误:

未捕获的类型错误:无法读取未定义的属性“定义”

在这一行:

(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 jquery requirejs select2


    【解决方案1】:

    我遇到了类似的问题,不知道是什么原因造成的,延迟加载,或者浏览器使用多个线程加载 javascript,但我通过用这个包装 i18n 文件函数解决了这个问题

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

    注意添加的荣誉。

    然后在文件末尾,在我添加的最后一个荣誉之前

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

    【讨论】:

    • 伙计,你是大师。我在 django-jet 的 bundle.min.js 中遇到了同样的错误。一旦修复 node_modules/select2/.../en.js,.. 在“gulp build”之前,一切正常。谢谢!
    猜你喜欢
    • 2021-01-07
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2019-01-02
    • 1970-01-01
    • 2017-11-19
    • 2023-03-03
    相关资源
    最近更新 更多