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 mand. Do we have some plugin which I can use to get the above result?
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 mand. Do we have some plugin which I can use to get the above result?
Share Improve this question edited Feb 8, 2022 at 11:56 coure2011 asked Feb 8, 2022 at 11:38 coure2011coure2011 42.5k87 gold badges225 silver badges361 bronze badges3 Answers
Reset to default 5Ok 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))
},
],
you can use jsconfig.json file to achieve this.
{
"pilerOptions": {
"baseUrl": ".",
"paths": {
"@/utils/*": ["ponentpath/*"],
}
}
}
vite-plugin-filter-replace can solve this problem. Add follow config in vite.config.ts
import filterReplace from 'vite-plugin-filter-replace';
export default {
plugins: [filterReplace([{
filter: /\.vue$/,
replace: {
from: /some-module/g,
to: '@/utils/myModule'
},
}], {
enforce: 'pre',
apply: 'build'
}
)],
};