diff --git a/package.json b/package.json index e7a48b76..399de60e 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,7 @@ "name": "@ubie/ubie-ui", "version": "0.0.2", "description": "React components for creating Ubie applications.", - "main": "dist/index.js", - "module": "dist/index.mjs", - "typings": "dist/index.d.ts", + "types": "dist/index.d.ts", "files": [ "README.md", "dist" diff --git a/tsup.config.ts b/tsup.config.ts index d3b9be0c..d77aa977 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -5,5 +5,23 @@ export default defineConfig({ dts: true, format: ['cjs', 'esm'], entry: ['src', '!src/**/*.spec.*', '!src/**/*.d.ts'], + external: ['react'], bundle: false, + plugins: [ + { + name: 'fix-esm', + renderChunk(_, chunk) { + if (this.format === 'esm') { + // https://github.com/egoist/tsup/issues/953 + const code = addMjsExtension(chunk.code); + return { code }; + } + }, + }, + ], }); + +function addMjsExtension(content) { + // This regex looks for relative import paths that don't have a file extension + return content.replace(/from\s+['"](\.\/|\.\.\/)(?![^'"\s]+?\.\w+['"])([^'"\s]+?)['"];/g, "from '$1$2.mjs';"); +}