-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
how to set alias #2398
Comments
You can add it to the Webpack config by placing your aliases in the |
GitHub issues are for bug reports & feature requests only. Such aliases are already set. vue-cli/packages/@vue/cli-service/lib/config/base.js Lines 49 to 50 in ff57b8f
You can use configureWebpack or chainWebpack in |
Your solution doesn't appear to work: vue.config.js
Error:
vue.config.js
Error:
@sodatea that solution doesn't work, my files are separated into a client/ and api/ folder, and I have to launch the cli with a custom entrypoint in the commandline, like so:
|
Context option also doesn't work vue.config.js
|
Seems the solution is something along the lines of: vue.config.js
as per |
This works
|
If you use vue create cli just use '@/...' by default this resolve the path ./src, so in my case i need resolve the file store.js in src then i add this line: import store from '@/store.js'; |
I have done that success with
|
While investigating this issue I have solved it like below and want to share others. Here are my vue.config.js file to support alias.
And use it in Vue component with alias version (alias loading only worked with "~" but not with "@" sign):
|
dude,It solved my problem.but can you tell me where did you find the solution? |
It is great to hear I have helped somebody. I have searched about this issue and tried multiple variants but any of helped me to specify directory based aliasing. So I want to give up after a lot of researching. But I did one last try and it worked! |
@abdulladev1995 you rock man! It solved the crappy ../../../ so glad:))) PS if you are using pycharm or webstorm don't forget to mark the assets directory as source |
Why is this issue closed? Vetur still can't properly infer custom paths. |
I resolved my issue by adding in a {
"allowJs": true,
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["src/**/*", "tests/**/*"],
"exclude": ["node_modules"]
} |
Seems to not work with monorepos, but this may be more applicable and open: vuejs/vetur#762 |
Ha! That's funny. Never ever got a response in those forums. |
Alias would remove unnecessary repetitions and less relative paths make changes easier when moving around files. This commit cleans also up some relative paths ('../../../') by using the alias and orders imports. It updates both path alias in tsconfig and module alias in Vue CLI's bundler (vuejs/vue-cli#2398).
This is the best way I've found to handle aliases, this doesn't just work with Vue it works with webpacks in general. I get that this isn't the place this is meant to go, but since this thread exists, may as well have a solid answer. This is essentially an automated way of creating the jsconfig.json file that @sean-hill mentions. The files you create go in your root folder next to where your vue.config or webpacks.config file is. The file that is generated will show up there as well. Requires: prettier First you'll want to configure your Vue or Webpacks config file like below. vue.config.js
Next you'll create a template file that is used when the aliases are generated. jsconfig.template.js
Then you'll create the actual alias generator. Note that const aliases is where you'll want to put the names and paths to the folders you want aliased. I left Mine in for reference, you can leave unused aliases and it won't hurt, or remove them. aliases.config.js
Finally a file like the below will be generated at run time, when you run jsconfig.json
Once those are done you can use aliases all throughout your application. Example:
I put the import twice to show that you can import without putting the extension. Some people don't know this. Hope this is helpful |
Alias would remove unnecessary repetitions and less relative paths make changes easier when moving around files. This commit cleans also up some relative paths ('../../../') by using the alias and orders imports. It updates both path alias in tsconfig and module alias in Vue CLI's bundler (vuejs/vue-cli#2398).
What problem does this feature solve?
what should i do when i need to set a alias like '@' same as 'src' ?
What does the proposed API look like?
i need cli-2.0 resolve setting
The text was updated successfully, but these errors were encountered: