I am developing two node packages registered with npm, and using es6 syntax. Each package has only one es6 module exporting a single class.
- package
A
has no dependencies - package
B
depends onA
Class A
export default class A {...}
Class B
import A from 'A'
export default class B {...}
Each package has the following structure
modules/
index.js (es6 source)
index.js (commonjs source)
- Source code is in
es6/index.js
- It is transpiled to es5 / commonjs using Babel
Question
I want to give users of my A and B packages the choice to use es6 (by importing B class which itself would import A es6 class and not es5 A) or es5 sources (by requiring es5 function B which itself requires es5 function A): What is the best way to achieve it?