Skip to content

Error when trying to resolve alias '/@/' #759

@LoveofRedMoon

Description

@LoveofRedMoon

Expected Behavior

file /output/bundle.js needs required('src/index');

Actual Behavior

file /output/bundle.js shows require('../../../@/index');

Additional Information

In alias plugin, the following code will return false when pass paramters ('/@/', '/@/vue/Button.vue')

function matches(pattern: string | RegExp, importee: string) {
  if (pattern instanceof RegExp) {
    return pattern.test(importee);
  }
  if (importee.length < pattern.length) {
    return false;
  }
  if (importee === pattern) {
    return true;
  }
  const importeeStartsWithKey = importee.indexOf(pattern) === 0;
  const importeeHasSlashAfterKey = importee.substring(pattern.length)[0] === '/';
  return importeeStartsWithKey && importeeHasSlashAfterKey;
}

I guess it is necessary to remove the trailing slash with pattern

for example:

function getEntries({ entries }: RollupAliasOptions): readonly Alias[] {
  if (!entries) {
    return [];
  }

  if (Array.isArray(entries)) {
    return entries;
  }

  return Object.entries(entries).map(([key, value]) => {
    // return { find: key, replacement: value };
    return { find: key.replace?.(/\/+$/, '') , replacement: value };
  });
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions