Created
September 2, 2022 15:39
-
-
Save jrc03c/149f49af44cf102f31c266ab1b1cbb22 to your computer and use it in GitHub Desktop.
Create a module resolution alias in (e.g.) 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
// Note that this uses the __dirname definition from here: | |
// https://gist.github.com/jrc03c/6fbccd5af3a4d1b61f12e1e620e1c01b | |
import { defineConfig } from "vite" | |
import path from "path" | |
const __dirname = path.resolve( | |
import.meta.url.replace("file://", "").split("/").slice(0, -1).join("/") | |
) | |
export default defineConfig({ | |
resolve: { | |
alias: { | |
"@": __dirname, | |
}, | |
}, | |
}) | |
// Now it's possible to import relative to the project root, like: | |
// import whatever from "@/path/to/whatever" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment