New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Alias/resolver mappings with '*' supported? #300
Comments
See type definition of Resolver You can do something like: const scopeRegex = /^\/@scope\/(\w+)\//
const myResolver = {
requestToFile(req) {
const match = req.match(scopeRegex)
if (match) {
const pkg = match[1]
return path.resolve(__dirname, 'packages', pkg, 'src', req.replace(scopeRegex, ''))
}
},
fileToRequest(file) {
// reverse logic
}
}
module.exports = {
resolvers: [myResolver]
} We may add wildcard support eventually but as of now this is what you have to do. Might be easier to just duplicate a few aliases. Also note: path aliases must start with |
@yyx990803 Thank you that really helped me! |
I've published |
This conflicts with |
Try this. // vite.config.ts
alias: {
'/@/': path.resolve(__dirname, 'src'),
},
resolvers: [
{
alias(id: string) {
return id.replace(/^@\//, '/@/') // add slash to particular id, then vite won't resolve it as a module
},
},
], // tsconfig.json
"paths": {
"@/*": [
"./src/*"
],
}, This trick can allow you to use relative path as alias. |
@RoB8080 thanks |
Work on 2.0, see https://vitejs.dev/config/#alias |
Is there a way to use alias configuration similar to the
paths
oftsconfig.json
or do I need to add it for each alias?This possible?
Current approach:
And how would I do that with the
resolvers
?Thanks!
The text was updated successfully, but these errors were encountered: