Skip to content

Commit

Permalink
Merge pull request #24 from kodai3/chore-build-config
Browse files Browse the repository at this point in the history
chore: 🤖 update build config
  • Loading branch information
takanorip committed Mar 13, 2024
2 parents 6c203c4 + 9f3a1d0 commit 0e2cb73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';");
}

0 comments on commit 0e2cb73

Please sign in to comment.