'Does esbuild provide a feature like the resolve.alias option in webpack?
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';
Solution 1:[1]
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | doberkofler |
Solution 2 | Mikhail Sereniti |