使用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()

相关推荐
zhuà!5 小时前
腾讯地图TMap标记反显,新增标记
前端·javascript·vue.js
未知原色5 小时前
web worker使用总结(包含多个worker)
前端·javascript·react.js·架构·node.js
幽络源小助理5 小时前
SpringBoot+Vue摄影师分享社区源码 – Java项目免费下载 | 幽络源
java·vue.js·spring boot
+VX:Fegn08956 小时前
计算机毕业设计|基于springboot + vue健身房管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
inferno6 小时前
JavaScript 基础
开发语言·前端·javascript
开发者小天6 小时前
React中useMemo的使用
前端·javascript·react.js
1024肥宅6 小时前
JS复杂去重一定要先排序吗?深度解析与性能对比
前端·javascript·面试
苹果醋36 小时前
iview— Select— Option选中后有空格
运维·vue.js·spring boot·nginx·课程设计
趣知岛7 小时前
JavaScript性能优化实战大纲
开发语言·javascript·性能优化
im_AMBER7 小时前
weather-app开发手记 04 AntDesign组件库使用解析 | 项目设计困惑
开发语言·前端·javascript·笔记·学习·react.js