Home > Mobile >  vite replace an import statement
vite replace an import statement

Time:02-08

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?

CodePudding user response:

you can use jsconfig.json file to achieve this.

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/utils/*": ["componentpath/*"],
    }
  }
}

CodePudding user response:

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))
          },
        ],
  •  Tags:  
  • Related