blobs icon indicating copy to clipboard operation
blobs copied to clipboard

Adding ES Modules to the final build

Open dkzlv opened this issue 4 years ago • 7 comments

Currently, if you have a ES bundler (Vite, Snowpack) you cannot use this library, as it uses an outdated module system (UMD). I added the support for ES modules. It just builds 4 additional files for both versions of the lib. Most bundlers (Vite including) will use index.module.js by default, but it's a convention to also add a module key in the package.json.

dkzlv avatar Apr 25 '21 12:04 dkzlv

If new versions are planned, I would actually advise in favor of abandoning rollup config at all and using something like dual-publish with CJS as a more common option for module system.

It would also drastically simplify the build process for you.

dkzlv avatar Apr 25 '21 12:04 dkzlv

Hey, so sorry I missed this. Will take a look ASAP

g-harel avatar May 19 '21 00:05 g-harel

Do you think publishing the TypeScript source could also solve this for you? I'm mostly outputting bundled JS to make it easier to use with a <script> import.

The build command fails because of uglify when I patch that rollup config change, I'll need to iterate on it.

g-harel avatar May 19 '21 02:05 g-harel

@g-harel

I'm mostly outputting bundled JS to make it easier to use with a

Most of the libs ship bundled code, that is ok. Not only it allows to use stuff, like unpkg and other CDNs right in the script tag, it also speeds up the build, as I don't need to rebuild your library from the source.

Do you think publishing the TypeScript source could also solve this for you?

I believe it's not a common thing to ship raw .ts files. I didn't find a single example of this in my node_modules, tbh. I think it would work, but it's unnecessary work for the compiler and bundler.

As of #4, I don't see any errors, when I try to import the same file. TS doesn't throw any errors and compiles the code successfully. I guess there might be some incompatible configuration settings in tsconfig.json.

dkzlv avatar May 19 '21 12:05 dkzlv

I just published 2.2.1-beta.0 with this change, let me know how that works for you! If it works out I'll merge and do a real release

g-harel avatar May 27 '21 01:05 g-harel

@g-harel I tried your beta release, but it doesn't work. I suspect it's mostly because you haven't added "module" key in package.json. All these modern bundlers are so fragile :)

dkzlv avatar Jun 13 '21 12:06 dkzlv

That's embarrassing, my bad and thanks for checking. I published a patched version as 2.2.1-beta.1

g-harel avatar Jun 15 '21 04:06 g-harel