From 9f3a1d04f1e36bf7abf58a84daab3d2c2d0932bc Mon Sep 17 00:00:00 2001 From: kodai3 Date: Sun, 10 Mar 2024 12:51:05 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20build=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kodai3 --- package.json | 4 +--- tsup.config.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) 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';"); +}