查看项目中是否存在vue.config.js文件,不存在就在根目录下面创建该文件
1、第一种
configureWebpack: {
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
components: '@/components'
}
}
},
2、第二种
configureWebpack: (config) => {
config.resolve.alias = {
'@': path.resolve(__dirname, 'src'),
components: '@/components'
}
}
2、第三种
configureWebpack: (config) => {
config.resolve.alias = {
'@': path.resolve(__dirname, 'src'),
components: '@/components'
}
}
完整代码
const path = require('path')
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
// 配置别名
configureWebpack: (config) => {
config.resolve.alias = {
'@': path.resolve(__dirname, 'src'),
components: '@/components'
}
}
})