The library mode documentation for Vite has an example of a package.json that uses require for UMD modules and import for ESM and this is the example:
{
"name": "my-lib",
"type": "module",
"files": ["dist"],
"main": "./dist/my-lib.umd.cjs",
"module": "./dist/my-lib.js",
"exports": {
".": {
"import": "./dist/my-lib.js",
"require": "./dist/my-lib.umd.cjs"
}
}
}
Are the import and require keywords in this case used as "conditional keywords" that toggle the module file resolution?
So if a developer is using ESM syntax and they do something like:
import { Foo } from { my-lib }
then the import will resolved from "./dist/my-lib.js" and if they do:
const myLib = require('my-lib')
then the import will be resolved from ./dist/my-lib.umd.cjs?
Also if we are making use of the exports property like this do we still need main and module?
It seems like these are overlapping?