为了保证多个项目复用代码,我喜欢把路径别名设置为@
,下面介绍vscode中的配置方法。
1、安装插件Path Intellisense
2、配置
"path-intellisense.mappings": {"@": "${workspaceRoot}/src"
}
3、在项目package.json所在同级目录下创建文件jsconfig.json
:
{"compilerOptions": {"target": "ES6","module": "commonjs","allowSyntheticDefaultImports": true,"baseUrl": "./","paths": {"@/*": ["src/*"]}},"exclude": ["node_modules"]
}
备注:我在nuxt项目中会这样配置
{"compilerOptions": {"target": "ES6","module": "commonjs","allowSyntheticDefaultImports": true,"baseUrl": "./","paths": {"@/*": ["*"]}},"exclude": ["node_modules"]
}