Skip to content

Commit

Permalink
Merge pull request #29 from kodai3/fix-build-process
Browse files Browse the repository at this point in the history
Fix build process
  • Loading branch information
takanorip authored Mar 18, 2024
2 parents 9915951 + fbd7a97 commit 15891ae
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.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"
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]+?\/)['"]([^'"\s]+?)['"];/g, "from '$1$2.mjs';");
}

0 comments on commit 15891ae

Please sign in to comment.