It can be easily set up with a module resolver:
1. Babel for Webpack
$ npm i babel-plugin-module-resolver --save-dev
Then create a .babelrc
file under root:
{
"plugins": [
[
"module-resolver",
{
"root": ["./"]
}
]
]
}
2. EsLint for VSCode
For VSCode to acknowledge the import and run go-to-definition correctly, add this in your jsconfig.json
, or create this file under project root if you don’t already have one:
{
"compilerOptions": {
"baseUrl": "."
}
}
Pingback: 使用webpack解决需求路径_javascript问答