So this isn't a question on how to do it, but more of a clarification on how it works. I'm using Vue and I'm creating a file that's usable by on both the client side and the server side (logic should be consistent and changes should be easily made).

So what the file uses is the module.exports object. I can understand this working for the server side (as its using node) but it surprisingly works on client side too.

From what I've learned (and used) is that javascript files usually use export instead. But this doesn't work with Node.

So my overall question is, is it expected behaviour that module.exports works with general Javascript files or is it only working because webpack is doing something about it.

  • If the client side file is gettign bundled with WebPack, then it is WebPack that is handling the module and including it in your bundle. You can look at your client-side JS in your browsers devtools to see what it all looks like. – neilsimp1 Dec 29 '17 at 13:53
  • Keep in mind the permssion may be different if you run the JavaScript within a web browser vs somthing like electron. – Robert Baron Dec 29 '17 at 19:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.