Skip to content

Commit

Permalink
chore: use vite-tsconfig-paths for resolving aliases (mammadataei#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
mammadataei committed Mar 17, 2023
1 parent 8194b41 commit 22c8d93
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"start-server-and-test": "^1.14.0",
"tailwindcss": "^3.1.8",
"typescript": "^4.8.4",
"vite": "^4.0.1"
"vite": "^4.0.1",
"vite-tsconfig-paths": "^4.0.7"
}
}
16 changes: 2 additions & 14 deletions example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { resolve } from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { compilerOptions } from './tsconfig.json'

function resolveAliasesFromTypescriptConfig() {
return Object.entries(compilerOptions.paths).reduce((acc, [key, [value]]) => {
const aliasKey = key.substring(0, key.length - 2)
const path = value.substring(0, value.length - 2)
return { ...acc, [aliasKey]: resolve(__dirname, path) }
}, {})
}
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
resolve: {
alias: resolveAliasesFromTypescriptConfig(),
},
plugins: [react()],
plugins: [react(), tsconfigPaths()],
})
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 22c8d93

Please sign in to comment.