vue3 vue-cli typescript 配置源码路径别名
1 tsconfig.json
path属性中新增自定义别名的路径
文件中默认配置了src路径的别名@
"paths": {
"my-service/*": [
"src/service/my/*"
],
"@/*": [
"src/*"
]
},
- vue.config.js
增加webpack路径别名配置
function resolvePath(...dir) {
return path.join(__dirname, ...dir)
}
module.exports = defineConfig({
chainWebpack: config => {
config.resolve.alias
.set("my-service", resolvePath("src/service/my"))
}
})