I have installed the project with vue cli 3
but as the project grows, the import on the components are getting ugly, I end up importing a component like
import Component from '../../../../components/folder/Component.vue'
I just want to alias the src folder and do
import Component from '@components/folder/Component.vue'
I did read that I have to modify the vue.config.js
, I have done it but the error is the same
Module not found: Error: Can't resolve '@components/Permissions/PermissionsTable'
This is my vue.config.js
const path = require("path");
const vueSrc = "./src";
module.exports = {
runtimeCompiler: true,
css: {
modules: true
},
configureWebpack: {
resolve: {
alias: {
"@": path.join(__dirname, vueSrc)
}
}
}
};
Am I missing something? What else should I do?
Very simple. To launch a VueJs project, you must type "npm run serve".
The simplest way to get started with Vue is to grab the development version script for it and add it to the head tag of your HTML file. Then you can start Vue code inside the HTML file inside of script tags. And have the Vue code connect up with an existing element on your HTML page.
For Vue CLI you need to create a file in the root folder of project - jsconfig.json
{
"include": ["./src/**/*"],
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@/*": ["./*"]
}
},
"exclude": ["node_modules"]
}
and that's all, helped me with PhpStorm
I was missing extensions: ['.js', '.vue', '.json'],
and in the import I have to use '@/components/...'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With