I'm currently working on a javascript project. I usually use typescript and ts has the path mapping feature. Is there something similar in javascript ?
TS path mapping:
"compilerOptions": {
"baseUrl": "src",
...
"paths": {
"@app/*": ["app/*"],
"@config/*": ["app/_config/*"],
"@environment/*": ["environments/*"],
"@shared/*": ["app/_shared/*"],
"@helpers/*": ["helpers/*"]
},
...
CodePudding user response:
In Webpack this feature is available via resolve.alias
. The configuration is similar, for example via 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
},
},
};