Build commonjs require function.
The require function provided by this library is not compatible with jN's builtin require. cjs-require introduce a module scope just like Node.js. So:
- Variables defined through
varare defined in module scope instead of global. - Each module has its own
requirefunction instead of sharing a globalrequire. - Based on (2), it is possible to do relative-require (
require(./foo)). - All cjs-require functions share the same module cache, but not with jN's builtin require.
jN/includes/my-script.js
// inject cjsRequireFactory to global
require("includes/cjs-require.js");
(function() {
// get the require function
var require = cjsRequireFactory(Editor.nppDir + "/plugins/jN/includes/my-script.js");
// now just require any cjs module
var test = require("./cjs-modules/test");
test();
})();jN/includes/cjs-modules/test.js
module.exports = function() {
alert("Test function is called");
};This library define one function in the global scope.
Get the commonjs require function for filename.
-
0.1.1 (Apr 23, 2018)
- Add: support absolute path.
- Add: support folder.
- Add: support JSON.
-
0.1.0 (Apr 23, 2018)
- Initial release.