tweakpane
tweakpane copied to clipboard
Support import as ES module type
It would be great if Tweakpane could support ES module (type="module") import.
Is there any progress on this issue? 👀
It is very nice and quick to use an esmodule. No need to set up a bundler and you get all the type hints from the lsp
It's tough work in several reasons:
- The support for ES modules in TypeScript is still in beta (https://devblogs.microsoft.com/typescript/announcing-typescript-4-7-beta/)
- Keeping compatibility for various usage (browsers/bundlers, CommonJS/AMD/UMD, pure JS/TS, etc.)
For now you can use Skypack, the CDN that converts packages into ES modules.
Ref: https://github.com/cocopon/tweakpane/issues/207#issuecomment-803798190
~~This fixes skypack's typescript support:~~ Doesn't seem to help, but it's a clue:
You can add typing to a module via declare module. Create .d.ts file with this:
declare module "https://cdn.skypack.dev/chai" { import chai from "chai"; export = chai; }
From: https://github.com/microsoft/TypeScript/issues/46936#issuecomment-981482591
ESM Supports importing from esm or cjs so that isn't an issue. Especially when using typescript as there are extra compatibility features. The type issue I found is the lack of @tweakpane/core as a dependancy of tweakpane
You can easily support multiple distributions for this package, if you expect people to be bundling this then ESM support is also super important as that is the only way to treeshake. You should take a look at tsup to replace the current rollup build step you have
Published the beta release of the next major version v4 and it's ES module.
You can try it with npm install tweakpane@beta, or downloading it manually: https://github.com/cocopon/tweakpane/releases/tag/4.0.0-beta.1
Released in v4.0.0.