rollup-plugin-vue icon indicating copy to clipboard operation
rollup-plugin-vue copied to clipboard

mapping '@' import path to the source folder

Open akauppi opened this issue 5 years ago • 3 comments

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.

akauppi avatar Feb 16 '20 10:02 akauppi

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

liana-p avatar Jan 30 '21 20:01 liana-p

@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')
    })
...

precious-void avatar May 25 '21 07:05 precious-void

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

akauppi avatar May 25 '21 10:05 akauppi