Is there any performance advantage or disadvantage (when using require) to importing the entire module, versus importing only selected functions?
As I understand it when using require to import modules (as opposed to using import ) compilers such as Babel do not perform any pruning of the final code as it does when using import. As such, considering then that both methods end up providing pointers to functions. I'm wondering if there is any reason to prefer one over the other. Or if this is just a matter of personal preference and readability.
const { methodOne, methodTwo } = require('../myLibrary')
const x1 = methodOne()
const x2 = methodTwo()
VS
const Lib = require('../myLibrary')
const x1 = Lib.methodOne()
const x2 = Lib.methodTwo()
I'm not looking for opinions on one style versus the other, I think both have value in certain situations. I'm just trying to figure out if there even is a technical reason to prefer one over the other.
Also for now let's just assume I'm not using Node 14 soimportis not available.