Esbuild: [Feature] alias option for path Resolve

Created on 26 Feb 2020  Â·  4Comments  Â·  Source: evanw/esbuild

Greetings,

First of all, thanks for the wonderful work.

By the time of writing, looking at the other issues, I realize that most of the requests are based on the habits & biases that the intensive use of webpack of the past years has introduced to us – and consequently, on the existing code base we have written. And my request lie in the same category.

I tried to use esbuild on my current project that is using webpack, hop(p)ing to benefit from really faster build time, which makes the extensive use of aliases in my imports (such as '@' for path.resolve(__dirname, 'src')) which is not supported by esbuild yet.

My request is to introduce an option to define aliases.

However I would strongly understand a rejection, as esbuild would not be a Webpack written in Go 😄

Best,
François

Most helpful comment

@evanw I would like to mention that some people use jsconfig.json instead of tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
            "view/*": ["view/*"],
            "common/*": ["common/*"]
        }
    }
}

All 4 comments

Thanks for logging this. It's something I do want to support, although it'll likely be in more of a data-driven way than using JavaScript code to set up the aliases, since this project isn't written in JavaScript.

Potential ways I'm considering doing this are either the alias field in package.json like Parcel does and/or the paths field in tsconfig.json for TypeScript code (see #60).

@evanw I would like to mention that some people use jsconfig.json instead of tsconfig.json

{
    "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
            "view/*": ["view/*"],
            "common/*": ["common/*"]
        }
    }
}

Someone just opened a PR for jsconfig.json support: #132 (just posting here to link these two issues together).

I think this issue can be considered fixed now that #60 has been implemented. You can now use paths in tsconfig.json or jsconfig.json to specify path aliases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mixtur picture mixtur  Â·  4Comments

frandiox picture frandiox  Â·  3Comments

sarsamurmu picture sarsamurmu  Â·  3Comments

fannheyward picture fannheyward  Â·  4Comments

OneOfOne picture OneOfOne  Â·  3Comments