React and CRACO to import from root using alias

Posted on February 17, 2021

I'm used to use an alias to import starting from root instead with the back path in Vue.js.

In React there's no such thing out of the box.

Thanks to CRACO, it's possible to configure that with in craco.config.js:

const path = require(`path`);

module.exports = {
  webpack: {
    alias: {
      '@': path.resolve(__dirname, 'src/')
    }
  }
};

Found here.

Want to interact? Reach me out on Twitter
Spotted a typo? Send a patch