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

resolve.alias doesn't work is this plugin #60

Closed
viclafouch opened this issue Mar 17, 2022 · 11 comments
Closed

resolve.alias doesn't work is this plugin #60

viclafouch opened this issue Mar 17, 2022 · 11 comments

Comments

@viclafouch
Copy link

Hello !

It looks like aliases are not correctly transformed in d.ts files.. All the JavaScript code is ok. It's just my d.ts files.

image

Here my vite config :

import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
import react from '@vitejs/plugin-react'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import dts from 'vite-plugin-dts'

const path = require('path')

// https://vitejs.dev/config/
export default defineConfig({
  test: {
    environment: 'jsdom',
    globals: true
  },
  build: {
    sourcemap: true,
    target: 'esnext',
    minify: false,
    lib: {
      entry: path.resolve(__dirname, 'src/index.tsx'),
      name: 'Mui-phone-number',
      fileName: format => `mui-phone-number.${format}.js`
    },
    rollupOptions: {
      output: {
        sourcemapExcludeSources: true,
        globals: {
          react: 'React',
          '@mui/material/InputAdornment': 'InputAdornment',
          '@mui/material/TextField': 'TextField',
          '@mui/material/IconButton': 'IconButton',
          '@mui/material/styles': 'styles',
          'react/jsx-runtime': 'jsxRuntime',
          '@mui/material/Menu': 'Menu',
          '@mui/material/MenuItem': 'MenuItem',
          '@mui/material/Typography': 'Typography',
          '@mui/material/ListItemIcon': 'ListItemIcon',
          '@mui/material/ListItemText': 'ListItemText'
        }
      }
    }
  },
  plugins: [
    peerDepsExternal(),
    react(),
    tsconfigPaths(),
    dts({
      insertTypesEntry: true
    })
  ]
})

Is anyone has the same issue ?

@qmhc
Copy link
Owner

qmhc commented Mar 18, 2022

I initially think this may be some unrobust when using with the vite-tsconfig-paths.

Normally it is as expected when using resolve.alias in the vite config file.

This is one of the main tasks for next version, I still need more time for futher testing, thanks for your patience.

@qmhc
Copy link
Owner

qmhc commented Mar 21, 2022

I had read the source codes of vite-tsconfig-paths in last weekend.

It's using some external resolvers to resolve the paths which defined in tsconfig.ts that makes others plugins cannot perceive through vite's hooks.

That is a bad news, it means that this plugins cannot make some cooperations with other plugins.

@viclafouch
Copy link
Author

viclafouch commented Mar 21, 2022

Oo good catch, so I guess, the better thing to do for now is to rewrite the aliases into the resolve.alias option ?

Edit: I just found an another package, but I can't tell if the source is ok or no :/
https://www.npmjs.com/package/vite-aliases

@qmhc
Copy link
Owner

qmhc commented Mar 21, 2022

I did a simple test and it is work well with vite-aliases, you can follow up if there are problems.

Also you can use the resolve.alias directly, is well.

@viclafouch
Copy link
Author

Thank you very much @qmhc ! You can close the issue ;)

@gyzerok
Copy link

gyzerok commented Oct 7, 2022

@viclafouch would you mind sharing your config? It seems like emitted typescript declarations do not work with vite-aliases.

@virketrang
Copy link

I'm facing this exact issue. I have defined my aliases in vite.config.ts, but it is not working with vite-plugin-dts. Would someone share there solution?

@mathews-cometchat
Copy link

I have the same issue as well.

@DaftPaul
Copy link

same issue here I think we should re open it

@zhouxinxing
Copy link

Is there no one to maintain it ?

@qmhc
Copy link
Owner

qmhc commented Jan 30, 2024

@DaftPaul @zhouxinxing Now please use pathsToAliases option of the plugin and you don't need to add any extra plugin.

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

7 participants