[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

posted @ 2024-05-02 14:24  Zhentiw  阅读(32)  评论(0编辑  收藏  举报