Skip to content

Commit

Permalink
Merge pull request #25 from edspencer/cjs
Browse files Browse the repository at this point in the history
Fix CJS package build
  • Loading branch information
edspencer authored Dec 2, 2024
2 parents b77321a + 8daee98 commit a902649
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -18,7 +23,7 @@
"react"
],
"files": [
"/dist"
"/dist/**/*"
],
"repository": {
"type": "git",
Expand Down
45 changes: 20 additions & 25 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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/**",
},
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit a902649

Please sign in to comment.