Javascript中的路径映射?



我目前正在做一个javascript项目。我通常使用typescript,它有路径映射特性。在javascript中有类似的东西吗?

路径映射:

"compilerOptions": {
"baseUrl": "src",
...
"paths": {
"@app/*": ["app/*"],
"@config/*": ["app/_config/*"],
"@environment/*": ["environments/*"],
"@shared/*": ["app/_shared/*"],
"@helpers/*": ["helpers/*"]
},
...

在Webpack中,此功能可通过resolve.alias获得。配置是类似的,例如通过webpack.config.js:

const path = require('path');
module.exports = {
resolve: {
alias: {
"@app": path.resolve(__dirname, 'app/'),
"@config": path.resolve(__dirname, 'app/config/'),
"@environment": path.resolve(__dirname, 'environments/'),
// Etc
},
},
};