Created
May 31, 2022 04:03
-
-
Save M-Gonzalo/214b826d3b0465f0f9c582895bc96517 to your computer and use it in GitHub Desktop.
How to configure absolute imports on a react app created using Vite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ####################################################################### | |
// En jsconfig.json: | |
{ | |
"compilerOptions": { | |
"baseUrl": "./src", | |
"paths": { | |
"@/*": ["*"] | |
} | |
} | |
} | |
// ####################################################################### | |
// ####################################################################### | |
// En consola: | |
npm i @vitejs/plugin-react-refresh | |
// ####################################################################### | |
// ####################################################################### | |
// En vite.config.js: | |
import { defineConfig } from 'vite' | |
import react from '@vitejs/plugin-react' | |
const path = require('path') | |
import reactRefresh from '@vitejs/plugin-react-refresh' | |
// https://vitejs.dev/config/ | |
export default defineConfig({ | |
resolve: { | |
alias: [{ find: '@', replacement: path.resolve(__dirname, '/src') }], | |
}, | |
plugins: [ | |
react(), | |
reactRefresh() | |
] | |
}) | |
// ####################################################################### | |
// ####################################################################### | |
// Para hacer los imports de los componentes desde cualquier carpeta: | |
import TestComponent from '@/components/test_folder/TestComponent.jsx' | |
// ####################################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment