na2hiro / namespaced-fieldset

A tiny React utils which gives uncontrolled `<input>` elements a power of namespaces, and allows constructing complex objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make sure the module works universally

na2hiro opened this issue · comments

I think I set up the build with microbundle so the npm module is universal, namely as ESM, CJS and UMD. However, it still needs some config in Remix usage: #4. This suggests our module is recognized only as ESM module.

Is there some better setup for the package so it works universally?

@na2hiro

https://github.com/remix-run/remix/blob/b4fd6eeb98a29f4cd1170ecf67f610ebee45da3b/packages/remix-dev/compiler/plugins/serverBareModulesPlugin.ts#L153

Looks like Remix looks for a require prop on exports. I think if you use that, you'll get rid of this problem.

Microbundle has this example in its README:

{
  "name": "foo",                      // your package name
  "type": "module",
  "source": "src/foo.js",             // your source code
  "exports": {
    "require": "./dist/foo.cjs",      // used for require() in Node 12+
    "default": "./dist/foo.modern.js" // where to generate the modern bundle (see below)
  },
  "main": "./dist/foo.cjs",           // where to generate the CommonJS bundle
  "module": "./dist/foo.module.js",   // where to generate the ESM bundle
  "unpkg": "./dist/foo.umd.js",       // where to generate the UMD bundle (also aliased as "umd:main")
  "scripts": {
    "build": "microbundle",           // compiles "source" to "main"/"module"/"unpkg"
    "dev": "microbundle watch"        // re-build when source files change
  }
}