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

(fix): don't treat @/ ~/ alias as external module #540

Closed
wants to merge 1 commit into from
Closed

(fix): don't treat @/ ~/ alias as external module #540

wants to merge 1 commit into from

Conversation

rockmandash
Copy link

@rockmandash rockmandash commented Mar 5, 2020

Current Behavior

Treating none relative import as external.

Desired Behavior

I know TSDX absolute import is under discussion right now.

But can we start supporting @/ and ~/ as an alias of srcDir?

It's widely used in Nuxt community, see documentation

Suggested Solution

Don't treat import path that startsWith @/ and ~/ as external.

So people can write their own absolute import plugin like this:

function rollupPluginAbsoluteImport() {
  return {
    name: "rollup-plugin-absolute-import",
    resolveId(source: string) {
      if (source.startsWith("@/") || source.startsWith("~/")) {
        return path.resolve(paths.appSrc, "." + source.slice(1, source.length));
      }
      return null;
    }
  };
}

Who does this impact? Who is this for?

All users who can't wait to use absolute import path

Describe alternatives you've considered

There is no way to use the absolute import path for TSDX right now I think.

I tried a lot of rollup plugins...

Additional context

Maybe release more often?

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 6, 2020

A few things:

  1. This is a feature, not a bugfix
  2. There is a way to do aliases with babel-plugin-module-resolver, see this HOWTO: HOWTOs #379 (comment)
  3. I think I could get behind a default using @, though this might need support in Parcel and Storybook examples for consistency. ~ I think is very confusing since that refers to homedir in unix.
  4. RE: frequency of releases: More frequent releases please! #512 . I think you already up-voted it

@rockmandash rockmandash closed this Mar 6, 2020
@agilgur5 agilgur5 added the topic: TS Paths Aliases Related to using aliases with TypeScript paths label Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: TS Paths Aliases Related to using aliases with TypeScript paths
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants