From c980e1b9f71453231e739e7235706ffa72b1f501 Mon Sep 17 00:00:00 2001 From: kodai3 Date: Sat, 16 Mar 2024 02:18:37 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"chore:=20=F0=9F=A4=96=20upd?= =?UTF-8?q?ate=20build=20config""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2aff0a34b5223b919c5dd041822c9a943205194b. 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 7a7f03fe..3d844ec0 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,7 @@ "name": "@ubie/ubie-ui", "version": "0.0.3", "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';"); +}