Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Path mapping in Javascript?

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/*"]
        },
        ...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
    },
  },
};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading