Release es6 and es5 sources with npm

I am developing two node packages registered with npm and using es6 syntax. Each package has only one es6 module exporting one class.

  • the package Ahas no dependencies
  • package Bdepends 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)

  • The source code is in es6/index.js
  • It translates to es5 / commonjs using Babel

Question

I want to give users of my packages A and B the choice to use es6 (by importing class B, which itself will import A es6 class, not es5 A) or es5 sources (requiring the es5 B function, which itself requires the es5 A function): What the best way to achieve it?

+5
source share
1

, ( github)

  • , es5 ( es5 A es5 B ).
  • , es6 ( es6 A es6B).

, , es6 es6. , , es5 . es5 .

es6 index.es6.js. es6 , .

+1

All Articles