使用npm i自己开发的组件库 依赖重复

我在vue项目中你npm install 自己开发的组件库
image.png
发现貌似因为 组件库中使用到了element 并且package.json中的element版本 跟vue主项目中使用的element版本不一致 导致会在组件库下的node_modules中又出现一个element

我想组件库中的 element 依赖默认使用 vue主项目的element
如果vue主项目没有element再在组件库的node_modules下添加element依赖

这是我组件库的package.json

{
  "name": "dia-depot",
  "version": "1.0.0",
  "description": "> TODO: description",
  "scripts": {
    "dev:docs": "lerna run dev --scope @dia/docs --stream",
    "build:component": "npm run build:component-core && npm run build:component-theme",
    "build:component-core": "rimraf lib/component && esno build/components.js",
    "build:component-theme": "gulp build --gulpfile gulpfile.js",
    "link": "lerna link",
    "bootstrap": "lerna bootstrap"
  },
  "main": "lib/component/index.js",
  "directories": {
    "lib": "lib"
  },
  "files": [
    "lib"
  ],
  "dependencies": {
    "core-js": "^3.6.5",
    "element-ui": "^2.15.6",
    "normalize.css": "^8.0.1",
    "vue": "^2.6.11",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0"
  },
  "devDependencies": {
    "@rollup/plugin-node-resolve": "^13.0.6",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "esbuild": "^0.13.10",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "^8.0.0",
    "gulp-cssmin": "^0.2.0",
    "gulp-sass": "^5.0.0",
    "highlight.js": "^9.3.0",
    "lerna": "^4.0.0",
    "markdown-it": "^8.4.1",
    "markdown-it-anchor": "^5.0.2",
    "markdown-it-chain": "^1.3.0",
    "markdown-it-container": "^2.0.0",
    "node-sass": "^4.12.0",
    "rollup": "^2.58.3",
    "rollup-plugin-commonjs": "^10.1.0",
    "rollup-plugin-esbuild": "^4.6.0",
    "rollup-plugin-filesize": "^9.1.1",
    "rollup-plugin-vue": "^5.0.0",
    "sass": "^1.43.3",
    "sass-loader": "^8.0.2",
    "transliteration": "^1.1.11",
    "vue-template-compiler": "^2.6.11"
  }
}
阅读 1.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题