question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `@/` -> src folder alias to keep consistant with vue-cli

See original GitHub issue

Is your feature request related to a problem? Please describe.

As the comment describes, when using directory mappings, the key must start and end with a slash

https://github.com/vitejs/vite/blob/e0acfdf395391df61db219fc928ba047b3aabe91/src/node/config.ts#L93-L113

Describe the solution you’d like

Since @/ -> src folder is a convention in vue-cli, it would be great to also add it to vite. It should be technically feasible because @/xx is not a valid npm package name.

Describe alternatives you’ve considered

Therer is another option: /@/, which matches the current rule.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
adapapcommented, Nov 6, 2020

My workaround is as follows:

vite.config.ts

const pathAliasMap = {
  '@/': '/src/',
}

export default {
  resolvers: [
    {
      alias(path: string) {
        for (const [slug, res] of Object.entries(pathAliasMap)) {
          if (path.startsWith(slug)) {
            return path.replace(slug, res)
          }
        }
      },
    },
  ],
}
0reactions
dagadbmcommented, Feb 9, 2021

how to make this work when using sass ? specially the ~ imports

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue cli 3 project alias src to @ or ~/ not working - Stack Overflow
It's built in to the CLI, can you try import Component from '@/components/folder/Component.vue' ? – Alexander Staroselsky. Mar 23, 2019 at 3:35.
Read more >
Renaming src Folder of a Vue CLI 3 Project
Source files in a Vue CLI 3 project are contained in the folder src. This article discusses whether or not you should change...
Read more >
Configuration Reference | Vue CLI
The directory where the production build files will be generated in when running vue-cli-service build . Note the target directory contents ...
Read more >
How to Migrate from Vue CLI to Vite - Vue School Blog
Learn how to migrate from Vue CLI to Vite in 9 simple steps for a faster and more streamlined developer experience.
Read more >
Dependency resolution - Parcel
In JavaScript, Typescript, and other JS-based languages, dependency specifiers may resolve to a directory rather than a file. If the directory contains a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found