How to get module working in both Node and browser without transpiler?

Viewed 38

Now that Chrome supports import/export I thought we could share some code between Node.js and browser without the need for Babel, but because export can't be wrapped in a conditional, I'm not sure how we can do this.

e.g. is there some way to write something like this

if (typeof module !== "undefined" && module.hasOwnProperty("exports")) {
    module.exports = BigInt;
} else {
    export default BigInt;
}

and trick both the Chrome and Node into parsing it?

0 Answers
Related