tweakpane icon indicating copy to clipboard operation
tweakpane copied to clipboard

Support import as ES module type

Open bolinocroustibat opened this issue 4 years ago • 4 comments

It would be great if Tweakpane could support ES module (type="module") import.

bolinocroustibat avatar Mar 22 '21 14:03 bolinocroustibat

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

asiryk avatar Apr 27 '22 14:04 asiryk

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

cocopon avatar May 01 '22 14:05 cocopon

~~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

braebo avatar Aug 01 '22 05:08 braebo

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

ghostdevv avatar Aug 01 '22 12:08 ghostdevv

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

cocopon avatar Jun 22 '23 14:06 cocopon

Released in v4.0.0.

cocopon avatar Aug 06 '23 15:08 cocopon