I am developing two node packages registered with npm, and using es6 syntax. Each package has only one es6 module exporting a single class.
A
has no dependenciesB
depends on A
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)
es6/index.js
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?
What I would do is to have two separate releases (two separate github projects)
Reason for this is that, presently, best is to avoid to confuse people who have not yet made the transition to es6 with es6 files. In the future, within a year or two, the es5 version would become unnecessary. You want to be able to discontinue support for the es5 version without dramatically changing the file organisation.
In the es6 release, consider naming your files index.es6.js. This will help prevent accidental reference to es6 code in an environment that has no support for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With