Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.52k stars 983 forks source link

Fix browser entry point #914

Closed benmccann closed 3 years ago

benmccann commented 3 years ago

UMD builds should be listed in browser. main is traditionally meant for the server-side entry point (i.e. CJS)

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#main https://docs.npmjs.com/cli/v7/configuring-npm/package-json#browser

The library currently won't load in Vite / SvelteKit because of this

tambien commented 3 years ago

can we include both "main" and "browser"? i wonder if webpack/parcel or some other packager is using the "main" entry point

benmccann commented 3 years ago

I think we could probably make main point to the esm build. Having main point to the UMD build which is only meant to be used in the browser is what's causing the problem.

Bundlers can definitely take ESM as input, so should have no issue using an ESM main - though I expect that they're not using main given the presence of module

benmccann commented 3 years ago

@tambien did you have any thoughts about this?

tambien commented 3 years ago

Do you know what the entry point that unpkg uses? There's a lot of people using this link: https://unpkg.com/tone, and i worry that if it all of a sudden pointed to the esm module instead of build/Tone.js, it might mess up some live sites.

benmccann commented 3 years ago

Thanks for taking a look. I've updated it so that it will continue to work for unpkg.

From https://unpkg.com:

If you omit the file path (i.e. use a “bare” URL), unpkg will serve the file specified by the unpkg field in package.json, or fall back to main.

benmccann commented 3 years ago

Thanks for the merge! I have this same change pending in tambien/Piano (https://github.com/tambien/Piano/pull/37) if you'd be able to take a look and merge it there as well. Thanks!!