From 8daee98c84572e996787c4eb0c81c4e060bb4e9e Mon Sep 17 00:00:00 2001 From: Ed Spencer Date: Mon, 2 Dec 2024 08:22:12 -0500 Subject: [PATCH] Fix CJS package build --- package.json | 13 +++++++++---- rollup.config.mjs | 45 ++++++++++++++++++++------------------------- tsconfig.json | 7 ++++--- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 72ce5e6..9ce1704 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,14 @@ "name": "inform-ai", "version": "0.5.1", "description": "A collection of hooks and utilities to easily add contextual AI to React applications", - "main": "dist/index.js", - "directories": { - "example": "example" + "main": "./dist/index.cjs.js", + "module": "./dist/index.js", + "types": "./dist/types/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.cjs.js" + } }, "scripts": { "test": "npx jest", @@ -18,7 +23,7 @@ "react" ], "files": [ - "/dist" + "/dist/**/*" ], "repository": { "type": "git", diff --git a/rollup.config.mjs b/rollup.config.mjs index 4318787..378ec16 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,5 +1,4 @@ import typescript from "rollup-plugin-typescript2"; -import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; import peerDepsExternal from "rollup-plugin-peer-deps-external"; import postcss from "rollup-plugin-postcss"; @@ -16,30 +15,26 @@ export default [ ], }, { - input: "./src/index.ts", - output: [ - { - file: "./dist/index.esm.js", - format: "esm", - }, - { - file: "./dist/index.cjs.js", - format: "cjs", - }, - ], - external: ["react", "react-dom"], - plugins: [ - postcss({ - extract: true, - minimize: true, - }), - peerDepsExternal(), // Automatically externalize peer dependencies - resolve(), // Resolve modules from node_modules - commonjs(), // Convert CommonJS modules to ES6 - typescript({ - tsconfig: "./tsconfig.json", - }), - ], + input: "src/index.ts", + output: { + file: "dist/index.js", + format: "esm", + sourcemap: true, + }, + plugins: [peerDepsExternal(), typescript({ useTsconfigDeclarationDir: true }), commonjs()], + watch: { + include: "src/**", + }, + }, + // CommonJS Build + { + input: "src/index.ts", + output: { + file: "dist/index.cjs.js", + format: "cjs", + sourcemap: true, + }, + plugins: [peerDepsExternal(), typescript({ useTsconfigDeclarationDir: true }), commonjs()], watch: { include: "src/**", }, diff --git a/tsconfig.json b/tsconfig.json index 3826f8f..471ff82 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,13 @@ "strict": true, "esModuleInterop": true, "skipLibCheck": true, - "outDir": "./dist", - "rootDir": "./src", + "outDir": "dist", + "rootDir": "src", "declaration": true, "declarationDir": "./dist/types", "moduleResolution": "node", - "jsx": "react-jsx" // Use the new JSX transform + "jsx": "react-jsx", + "sourceMap": true }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"]