rochars / wavefile

Create, read and write wav files according to the specs. :star: :notes: :heart:
MIT License
226 stars 48 forks source link

Use separate exports for ES and CommonJS modules #30

Open rejc2 opened 1 year ago

rejc2 commented 1 year ago

Following the approach recommended in the Node.js documentation:

https://nodejs.org/api/packages.html#approach-1-use-an-es-module-wrapper

Reason for change

Currently if you import the 'wavefile' package from an ES module in Node, Node will use the CommonJS module in dist/wavefile.js and treat the object exported there as the default export. This means that in order to get the WaveFile class, you will need to do:

import waveFileModule from 'wavefile';
const { WaveFile } = waveFileModule;

rather than the expected pattern of:

import { WaveFile } from 'wavefile';

The change in this PR re-exports WaveFile in a ESM wrapper module.