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

Aliases defined under resolve.alias are duplicated #20

Closed
DanielHZhang opened this issue Sep 8, 2021 · 3 comments
Closed

Aliases defined under resolve.alias are duplicated #20

DanielHZhang opened this issue Sep 8, 2021 · 3 comments

Comments

@DanielHZhang
Copy link

vite-plugin-solid duplicates aliases listed under resolve.alias. Any downstream vite plugins that reference the user config in the configResolved hook have to deal with de-duplicating the user aliases.

Output result of config.resolve.alias in the configResolved hook after running vite-plugin-solid:

aliases: [
  { find: /^[\/]?@vite\/env/, replacement: [Function: replacement] },
  { find: /^[\/]?@vite\/client/, replacement: [Function: replacement] },      
  {
    find: 'src',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\src'
  },
  {
    find: 'shared',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\shared'
  },
  {
    find: 'src',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\src'
  },
  {
    find: 'shared',
    replacement: 'C:\\Users\\Daniel\\Documents\\Workspace\\test\\shared'
  },
  { find: /^solid-refresh$/, replacement: '/@solid-refresh' }
]

vite.config.ts:

import path from 'path';
import {defineConfig} from 'vite';
import solidPlugin from 'vite-plugin-solid';
import svgLoaderPlugin from './src/svg-loader';

export default defineConfig({
  resolve: {
    alias: [
      {
        find: 'src',
        replacement: path.join(process.cwd(), 'src'),
      },
      {
        find: 'shared',
        replacement: path.join(process.cwd(), 'shared'),
      },
    ],
  },
  plugins: [solidPlugin(), svgLoaderPlugin()],
  server: {
    port: 8080,
    strictPort: true,
  },
});

The issue might be from creating a new array on this line with mergeAndConcat:

alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],

@amoutonbrady
Copy link
Member

Hey! Thank you for reporting the issue. I'll look into it ASAP :)

@amoutonbrady
Copy link
Member

Sorry for the delay, I added an extra test on the ./playground/vite.config.js config file and manage to reproduce and seemingly fix the issue. It appears, vite automatically already merge stuff together properly so I just removed the mergeAndConcat call.

It's been released in 2.1.0

Let me know if that works for you.

@DanielHZhang
Copy link
Author

Yup can confirm that they're no longer being duplicated, thanks for the fix!

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

No branches or pull requests

2 participants