diff --git a/package.json b/package.json index d2f63788b5..490617509c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ ".": { "types": "./dist/esm/index.d.ts", "import": "./dist/esm/index.js", - "require": "./dist/cjs/index.js" + "require": "./dist/cjs/index.cjs" } }, "type": "module", @@ -24,8 +24,8 @@ "scripts": { "prepare": "husky install", "build": "rimraf ./dist; run-s build:**", - "build:cjs": "tsc --module commonjs --outDir dist/cjs", "build:esm": "tsc && node build-scripts/fix-imports.js", + "build:cjs": "rollup --config rollup.cjs.config.js -- dist/esm/index.js", "build:umd": "rollup --config rollup.config.js -- dist/esm/index.js", "build:umd:min": "terser --ecma 6 --compress --mangle -o dist/umd/index.min.js -- dist/umd/index.js && gzip -9 -c dist/umd/index.min.js > dist/umd/index.min.js.gz", "size": "npm run build:esm && size-limit", diff --git a/rollup.cjs.config.js b/rollup.cjs.config.js new file mode 100644 index 0000000000..cb6ad03637 --- /dev/null +++ b/rollup.cjs.config.js @@ -0,0 +1,20 @@ +import { nodeResolve } from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import nodePolyfills from "rollup-plugin-polyfill-node"; + +export default { + output: { + file: "dist/cjs/index.cjs", + format: "cjs", + }, + plugins: [ + commonjs(), + json(), + nodePolyfills(), + nodeResolve({ + browser: true, + preferBuiltins: false, + }), + ], +};