vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.85k stars 6k forks source link

Alias prefixed with `#` doesn't work with `import.meta.glob` #17614

Closed enkot closed 1 month ago

enkot commented 1 month ago

Describe the bug

I try to use import.meta.glob with an alias prefixed with # but it doesn't work:

export default defineConfig({
  resolve: {
    alias: [
      {
        find: '#icons',
        replacement: fileURLToPath(new URL('./assets/icons', import.meta.url)),
      }
    ],
  },
});
const glob = import.meta.glob('#icons/*.svg', { eager: true }); // doesn't work

Prefixed with @ or without prefixes - works fine:

const glob = import.meta.glob('@icons/*.svg', { eager: true }); // works
const glob = import.meta.glob('icons/*.svg', { eager: true }); // works

Reproduction

https://stackblitz.com/edit/vitejs-vite-sx14yb?file=main.js

Steps to reproduce

  1. Run the project.
  2. Open the console.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.3.2 => 5.3.3

Used Package Manager

npm

Logs

glob #icons {}
glob @icons {/assets/icons/vite.svg: Module}

Validations

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.