Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

mapping '@' import path to the source folder #330

Open
akauppi opened this issue Feb 16, 2020 · 3 comments
Open

mapping '@' import path to the source folder #330

akauppi opened this issue Feb 16, 2020 · 3 comments
Milestone

Comments

@akauppi
Copy link

akauppi commented Feb 16, 2020

What problem does this feature solve?

Vue samples seem to use 'import "@/components/..."' paths, which is automatically set up for Vue CLI projects.

This notion does not work for rollup-plugin-vue users, adding to the threshold or frustration of using Rollup instead of the default build pipeline.

I do not know, whether handling alias paths within rollup-plugin-vue makes sense. The work-around is to use '@rollup/plugin-alias' and set up such an alias on your own.

One solution could be not to do technically anything within rollup-plugin-vue but to instruct people how such an alias is to be done.

// rollup.config.js
import alias from '@rollup/plugin-alias';

...
  // For '@/...' to work like it does for Vue CLI -configured projects.
  alias({
    entries: {
      ['@']: path.resolve(__dirname, 'src')
    }

What does the proposed API look like?

No API. Importing from @/ would map to the src folder.

@znck znck added this to the Zero Issues milestone Oct 22, 2020
@liana-p
Copy link

liana-p commented Jan 30, 2021

Hitting this issue too. I am making a library which includes vue components, and use import aliases.

Once compiled the alias paths are still there instead of being replaced, so when using my library, the code inside it tries to import with the original alias path

@precious-void
Copy link

@akauppi I'm using it like that:

import path from "path";
...
import alias from "@rollup/plugin-alias";
...
  // For '@/...' to work like it does for Vue CLI -configured projects.
  alias({
    entries: {
      ['@']: path.resolve(__dirname, 'src')
    })
...

@akauppi
Copy link
Author

akauppi commented May 25, 2021

@shtelzerartem Something must have been dropped in the original editing. Modified it to match yours. Thanks!

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

No branches or pull requests

4 participants