admin管理员组文章数量:1355748
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'
}
)],
};
本文标签: javascriptvite replace an import statementStack Overflow
版权声明:本文标题:javascript - vite replace an import statement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743978271a2570966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论