It seems every time a module is required, it is evaluated anew. e.g. using local variables to deal with singletons or maintain a 'global' id dont work.
// In some-module.js
let number = 0
module.exports = {
increment: function () {
return number++
}
}
// In another-module.js
const SomeModule = require('some-module')
console.log(SomeModule.increment())
// In a-third-module.js
const SomeModule = require('some-module')
console.log(SomeModule.increment())
// In application.js
// Prints 0 twice
require('another-module')
require('a-third-module')
This is a problem requiring jquery plugins that require jquery.
// In some-plugin.js
const jQuery = require('jquery')
jQuery.fn.somePlugin = function () {
console.log('do stuff')
}
// In application.js
const $ = require('jquery')
require('some-plugin')
// somePlugin deosnt exist cause our jquery and somePlugin's are different
$('.aselector').somePlugin()
Is this by design? Will it be fixed to match the node, webpack et al behavior?
It seems every time a module is required, it is evaluated anew. e.g. using local variables to deal with singletons or maintain a 'global' id dont work.
This is a problem requiring jquery plugins that require jquery.
Is this by design? Will it be fixed to match the node, webpack et al behavior?