【问题标题】:requirejs optimizer creates code that does not workrequirejs 优化器创建不起作用的代码
【发布时间】:2012-06-26 19:36:05
【问题描述】:

我在我的项目中使用“定义”。当我不使用优化器时,我的 js 代码可以正常工作。当我运行优化器时,所有文件都包含在下面

require(["jquery", "modals", "registermodule", "bootstrap", "personsmodule", "datemodule",    "./jquery-ui-1.8.18.custom.min"], function($) {});


C:/Users/pethel/checkout/src/main/webapp/resources/scripts/main-built.js
----------------
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/jquery.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/modals.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/ajaxmodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/jquery-ui-1.8.18.custom.min.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/datemodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/validationmodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/guimodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/registration_util.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/registermodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/bootstrap.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/tablesort.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/personsmodule.js
C:/Users/pethel/checkout/src/main/webapp/resources/scripts/main.js

当我用丑陋的脚本加载我的页面时,我得到 datepicker 未定义。当文件包含在这里 jquery-ui-1.8.18.custom.min.js 时,怎么会发生这种情况?

【问题讨论】:

    标签: javascript jquery require requirejs


    【解决方案1】:

    问题是 jquery-ui-1.8.18.custom.min.js 不是 AMD 模块。

    方案一:jquery-ui 的代码封装到 AMD 模块中

    解决方案 2:删除代码中的依赖项并手动包含它。

    还有其他解决方案如何处理非 AMD 依赖项,但我不知道优化器在这种情况下如何工作。

    【讨论】:

    • 解决方案 1:不能手动完成?我需要tagneto.blogspot.no/2011/01/… 之类的东西 解决方案2:你是什么意思。另一个
    • 这个 apporach 在 chrome 中工作,但 IE 仍然抱怨 datepicker。
    猜你喜欢
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多