[Vite] Support CommonJS and ESM for library
in package.json:
{
"main": "./dist/build.umd.cjs",
"module": "./dist/build.js",
"exports": {
".": {
"import": "./dist/build.js",
"require": "./dist/build.umd.cjs",
"types": "./dist/index.d.ts"
}
}
}
So when it is import
, we use commonjs, when it is require
, we use es module.
And we also define where to find the types files