requireJS优化器创建不起作用的代码

requirejs optimizer creates code that does not work

本文关键字:代码 不起作用 创建 优化 requireJS      更新时间:2023-09-26

我在我的项目中使用"定义"。当我不使用优化器时,我的 js 代码会哗啦啦。当我运行优化器时,所有文件都包含在下面 se

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

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

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

解决方案 1:将 jquery-ui 的代码包装到 AMD 模块

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

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