Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig.json support? #70

Closed
plashenkov opened this issue Aug 10, 2020 · 8 comments
Closed

tsconfig.json support? #70

plashenkov opened this issue Aug 10, 2020 · 8 comments

Comments

@plashenkov
Copy link

plashenkov commented Aug 10, 2020

Hi there!

Thanks for the helpful plugin!
I'm trying to integrate esbuild into rollup using your plugin and it seems that it doesn't support tsconfig.json completely?
At least it doesn't respect compilerOptions.baseUrl and compilerOptions.paths.
These are path aliases which allow to write

import '@alias/module'

instead of

import `../../../../../../../../some-folder/module`

(well, I think you know, but just for clarity :) )
And as far as I know esbuild itself supports these options (evanw/esbuild#60 and evanw/esbuild#38 (comment)).

Or maybe I missed something?

@ycnmhd
Copy link

ycnmhd commented Dec 10, 2020

found a workaround using @rollup/plugin-alias

import path from "path";
import resolve from "rollup-plugin-node-resolve";
import esbuild from "rollup-plugin-esbuild";
import alias from "@rollup/plugin-alias";

const projectRootDir = path.resolve(__dirname);

export default {
  /**/
  plugins: [
    alias({
      customResolver: resolve({ extensions: [".tsx", ".ts"] }),
      entries: Object.entries({
        "::helpers/*": ["./src/helpers/*"],
        "::hooks/*": ["./src/hooks/*"]
        /**/
      }).map(([alias, value]) => ({
        find: new RegExp(`${alias.replace("/*", "")}`),
        replacement: path.resolve(
          projectRootDir,
          `${value[0].replace("/*", "")}`
        )
      }))
    }),
    esbuild({
      /**/
    })
  ]
};

@egoist
Copy link
Owner

egoist commented Dec 11, 2020

The solution is to use @rollup/plugin-alias as @ycnmhd said, there's also alias-hq (by @davestewart) to reduce boilerplate code.

@davestewart
Copy link

Thanks for the mention @egoist

@peats-bond
Copy link

The solution is to use @rollup/plugin-alias as @ycnmhd said

The workaround using @rollup/plugin-alias adds ~5 seconds of build time to my project. @egoist do you have plans to better support tsconfig.json? It looks like the esbuild library supports more fields than you support right now:

@egoist
Copy link
Owner

egoist commented Jun 25, 2021

@peats-bond path alias is not part of esbuild's transform api

@JensDll
Copy link

JensDll commented Sep 6, 2022

I couldn't get the newer @rollup/plugin-node-resolve to work as the customResolver argument. However, in my trivial case of wanting to bundle TypeScript files, a simple resolveId function that looks through a list of extensions was enough to resolve and bundle the aliased modules:

import alias, { type ResolverFunction } from '@rollup/plugin-alias'

function resolveExtensions(extensions: string[]): ResolverFunction {
  return async function (source) {
    for (const extension of extensions) {
      try {
        const moduleInfo = await this.load({ id: source + extension })
        return moduleInfo.id
      } catch {}
    }

    return null
  }
}

alias({
  customResolver: resolveExtensions(['.ts']),
  entries: [/* ... */]
})

@sxzz
Copy link
Collaborator

sxzz commented Sep 20, 2023

See #70 (comment), and let's track evanw/esbuild#394. As this project is a wrapper of esbuild.

@sxzz sxzz closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2023
@castarco
Copy link
Contributor

castarco commented Aug 4, 2024

Notice that besides tsconfig.json's paths, we also have package.json's imports field.

Some people are using the later because it's more generic (at least when we know that source code will always be transformed), but rollup-plugin-esbuild seems to have the same (or similar) problems with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants