Replies: 1 comment 5 replies
-
|
Actually it's not the best method I think. We're using the structure like this |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to integrate
tsdowninto Floating UI floating-ui/floating-ui#3324 and need to make sure it supports legacy bundlers like webpack 4.As far as I can tell, the best method to simultaneously support CJS and ESM is to do this: https://satya164.page/posts/publishing-dual-module-esm-libraries#wrapping-up
{ "main": "./cjs/index.js", "module": "./esm/index.js", "exports": { ".": { "import": { "types": "./esm/index.d.ts", "default": "./esm/index.js" }, "require": { "types": "./cjs/index.d.ts", "default": "./cjs/index.js" } } } }i.e. only use
.jsextensions and specify new folders and apackage.jsonwithcommonjsandmoduletypes.Issues with
.cjsand.mjson legacy bundlers:.cjsin"main"breaks legacy bundlers when it's specified in a transitive dependency: floating-ui/floating-ui#1529.mjsin"module"breaks legacy bundlers: atomiks/floating-ui#2 and motiondivision/motion#1307The config is pretty small to achieve this, but it requires a
prepack.mjsscript to create thepackage.jsons and extra code to work.I wonder if this should be the default if you specify
format: ['cjs', 'esm']?That is — instead of the above, the smallest default config would instead output the
esmandcjsfolders with the relevantpackage.jsons:Another thing is supporting sub-paths on legacy bundlers that don't support an
exportsmap. The simplest way to support it is, again, a new folder with apackage.jsonthat points to the relevantdistfile withmain+module:my-package/utils/package.json{ "main": "../dist/cjs/utils.js", "module": "../dist/esm/utils.js", "types": "../dist/cjs/utils.d.ts" }Beta Was this translation helpful? Give feedback.
All reactions