Skip to content

Commit

Permalink
fix: correctly add file extensions for relative imports (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel authored Aug 29, 2024
1 parent 747151d commit d05f035
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/config/src/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import dts from 'vite-plugin-dts'
function ensureImportFileExtension({ content, extension }) {
// replace e.g. `import { foo } from './foo'` with `import { foo } from './foo.js'`
content = content.replace(
/(im|ex)port\s[\w{}/*\s,]+from\s['"]\.\/[^.'"]+(?=['"];?)/gm,
/(im|ex)port\s[\w{}/*\s,]+from\s['"]\.\.?\/[^.'"]+(?=['"];?)/gm,
`$&.${extension}`,
)

// replace e.g. `import('./foo')` with `import('./foo.js')`
content = content.replace(
/import\(['"]\.\/[^.'"]+(?=['"];?)/gm,
/import\(['"]\.\.?\/[^.'"]+(?=['"];?)/gm,
`$&.${extension}`,
)
return content
Expand Down

0 comments on commit d05f035

Please sign in to comment.