Importing ES6 modules from multi-compiled UMD/CJS/ES6

496 views Asked by At

Using ES6 boilerplate generator, I have built a moduleA that exports CommonJS (via Babel), UMD (via Rollup, unminified & minified version), and ES2015 via Babel. In other words, my module's package.json has

  "main": "cjs/index.js",
  "browser": "dist/moduleA.js",
  "module": "es/index.js",
  "jsxnext:main": "es/index.js",

Now I am building a moduleB that uses similar setup. What would be the best way to reference moduleA from moduleB? What would be the difference between require("moduleA") vs import { X } from "moduleA". Basically I do not understand how different export options (main/browser/module) can be used from another module. Thanks!

0

There are 0 answers