使用npm运行js脚本覆盖vue依赖包

// scripts/replace-components.js

// eslint-disable-next-line @typescript-eslint/no-var-requires

const fs = require('fs-extra')

const path = require('path')

const replacements = {

// 源文件(你的组件): 目标文件(node_modules中的组件)

'./src/components/CustomTable.vue': './node_modules/some-package/src/Table.vue',

'./src/components/CustomForm.vue': './node_modules/some-package/src/Form.vue'

}

function replaceComponents() {

Object.entries(replacements).forEach(([src, dest]) => {

const srcPath = path.resolve(__dirname, '...', src)

const destPath = path.resolve(__dirname, '...', dest)

复制代码
if (fs.existsSync(srcPath)) {
  // 确保目标目录存在
  fs.ensureDirSync(path.dirname(destPath))
  // 复制文件
  fs.copySync(srcPath, destPath)
  console.log(`✅ 已替换: ${dest}`)
} else {
  console.log(`❌ 源文件不存在: ${src}`)
}

})

}

replaceComponents()

相关推荐
忆琳1 分钟前
Vue3 优雅解决单引号注入问题:自定义指令 + 全局插件双方案
vue.js·element
忆琳7 分钟前
Vue3 全局自动大写转换:一个配置,全站生效
javascript·element
张元清19 分钟前
不用 Server Components 也能做 React 流式 SSR —— 实战指南
前端·javascript·面试
Ruihong1 小时前
放弃 Vue3 传统 <script>!我的 VuReact 编译器做了一次清醒取舍
前端·vue.js
蜡台1 小时前
IDEA LiveTemplates Vue ElementUI
前端·vue.js·elementui·idea·livetemplates
苏瞳儿1 小时前
前端/后端-配置跨域
前端·javascript·node.js·vue
神の愛1 小时前
Vite的proxy和Nginx的location 请求转发区别
vue.js
竹林8181 小时前
从轮询到订阅:我在 React 项目中实现实时监听 ERC-20 转账事件的完整踩坑记录
前端·javascript
视觉CG1 小时前
【tailwindcss】网页标题样式
javascript·ecmascript·tailwindcss
之歆1 小时前
Vue Router 深度解析 — 从浏览器导航模型到 SPA 路由工程
前端·javascript·vue.js