typescriptrollupjspreact

Why Preact should be in prod dependency in Grid.js?


I've been reviewing some discussions, such as this one, which suggest that React should typically be placed as a prod dependency. However, I'm uncertain if the same consideration applies to Preact.

According to the official Grid.js website, they specifically mention that preact is the only external dependency they use, highlighting the importance of this choice.

In my understanding, if I want to maintain the context relationship of Preact in my package, and if I intend to export various hooks like useEffect, useCallback, useState, and useRef through index.ts, should I still consider Preact as an external dependency? Or is it viable for me to classify Preact solely as a dev dependency, especially given that I utilize Rollup for bundling both UMD and ESM formats, and Preact is included in the generated JS files?

I'm looking for clarity on whether I can, or should, categorize Preact in a certain way for an efficient and reliable setup. Any insights or advice would be greatly appreciated!


Solution

  • To start off with, I'm a Preact maintainer who's worked a lot on build tooling, including the tool that gridjs uses to build (microbundle).

    Dependency management is fairly complex and there's no one right way to do it. Different situations call for different configs and so you have to pick which situations you want to support and work from there.

    Some comments on your links, however:


    If you want to make a package, there's a couple items to think of:

    But, importantly, you can choose some (seemingly) conflicting options. Package exports allow you to define submodules that can be, for example, very different builds of your library. Maybe my-lib/widget is an all-in-one bundle meant for people wanting to embed your lib onto their site, where my-lib is a normal library, meant more for usage via NPM.


    Hopefully this is useful as generic advice. StackOverflow might not be the best place for a lengthy back-and-forth on your specifics & providing examples, so feel free to ping me in the Preact slack if you wanted, else, I can try to respond here as best as I can via comments.