Use rollup instead of tsc to generate cjs files

This commit is contained in:
Franck Royer 2022-06-16 16:36:48 +10:00
parent ebbb0a2713
commit e3b6292a6e
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
2 changed files with 22 additions and 2 deletions

View File

@ -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",

20
rollup.cjs.config.js Normal file
View File

@ -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,
}),
],
};