Take a look at https://github.com/umdjs/umd - this is a wrapper for both AMD and CommonJS.
Preferred way of writing CommonJS plugins for jQuery
-
02-06-2022 - |
题
The latest jQuery v1 (as of now: v1.10.2) finally uses CommonJS. This allows to use it as a node module, e.g. with webmake.
What is the preferred way of writing plugins for jQuery in a CommonJS compatible way?
The following seems logical to me:
- If CommonJS is not available fall back to other techniques (AMD, global objects)
Require jQuery like:
var $ = require('jQuery');
Define new functions/objects (jQuery can be used with $)
Export those new functions/objects by assigning them to module.exports, e.g.:
module.exports.newFunc = newFunc;
Should I do it that way? Are there good alternatives?
解决方案
不隶属于 StackOverflow