Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果您的代码检测到它是由 调用的require,您可能希望它相应地分支,在每种情况下做或不做某些事情。我该怎么做呢?
require
当然,只需检查module.parentis not nullor undefined。如果它是用一个对象设置的,那么你的模块是用require.
module.parent
null
undefined