我想编写一个通用的JavaScript模块,可以被node.js和RequireJS加载,所以我会写这样的东西:
(function() {
if (typeof exports !== 'undefined') {
// node.js
module.exports = ...;
} else if (typeof define === 'function' && define.amd) {
// AMD
define([...], function(...) {
return ...;
});
}
})();
在这种情况下,RequireJS 优化器仍然有效吗?
最佳答案
上次,当我尝试使其工作时 - requirejs 没有看到依赖文件。
所以我使用了“include”配置参数。
关于javascript - 如果define()不是顶级函数调用,RequireJS优化器仍然有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17913303/