7

Does esbuild provide a feature like the resolve.alias option in webpack?

const path = require('path');
    
module.exports = {
  //...
  resolve: {
    alias: {
      Utilities: path.resolve(__dirname, 'src/utilities/'),
      Templates: path.resolve(__dirname, 'src/templates/'),
    },
  },
};

Now, instead of using relative paths when importing like so:

import Utility from '../../utilities/utility';

you can use the alias:

import Utility from 'Utilities/utility';
doberkofler
  • 9,511
  • 18
  • 74
  • 126

2 Answers2

5

esbuild does currently not offer a dedicated way to resolve aliases but does support paths in tsconfig.json. https://github.com/evanw/esbuild/issues/2191

doberkofler
  • 9,511
  • 18
  • 74
  • 126
3

esbuild have no similar option in build options but it provides hancy way to control paths resolving via plugins. You can either write simple own plugin or use existing one such as esbuild-plugin-alias