Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vite replace an import statement

I have a vue file

// myComponent.vue
import { something } from 'some-module'
...

I want to replace this import statement into

import { something } from '@/utils/myModule'

in case when running the vitest command. Do we have some plugin which I can use to get the above result?

like image 294
coure2011 Avatar asked Aug 08 '26 08:08

coure2011


1 Answers

Ok its working

// vite.config.js
    alias: [
          {
            find: /some-module/,
            replacement: fileURLToPath(new URL('./src/utils/someModuleFake.ts', import.meta.url)),
          },
          {
            find: '@',
            replacement: fileURLToPath(new URL('./src', import.meta.url))
          },
        ],
like image 91
coure2011 Avatar answered Aug 10 '26 10:08

coure2011



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!