1、node_modules 库文件只需在package.json 中指定 main 入口文件,暴漏下即可引用
{
"name": "kkk",
"version": "0.3.2",
"description": "移动端适配解决方案",
"main": "methods.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"适配"
],
"author": "",
"license": "ISC"
}
2、npm i 可以从仓库加载项目,只需在package.json 配置dependencies
重命名包名 vote---1111, 克隆地址 git+http://gitee.xxxxxx.com/dxxw/vote.git,
其中 <protocol> 可以是 git,git+ssh,git+http,git+https,或者 git+file。而 #<commit-ish> 可以选择 commit 的点,#semver:<semver> 是选择 tag 并且支持语义化版本,如此以来我们不用发布到 npm 也能使用包了!
在使用时取决于心项目package.json的配置名称,而不是包内package.json的name,例如本示例
import add from 'vote---1111' 而不是 import add from 'vote'
"dependencies": {
"autoprefixer": "^10.4.14",
"lib-flexible": "^0.3.2",
"postcss-pxtorem": "^6.0.0",
"postcss-write-svg": "^3.0.1",
"sass": "^1.59.2",
"vote---1111": "git+http://gitee.xxxxxx.com/dxxw/vote.git"
}
"dependencies": {
// semver(by tag)
"random.ts": "git+https://github.com/isLishude/random.ts.git#semver:^2.0.0",
// branch
"random.ts": "git+ssh://git@github.com/isLishude/random.ts.git#dev",
// master
"random.ts": "git+ssh://git@github.com/isLishude/random.ts.git",
// commit-ish
"random.ts": "git+ssh://git@github.com/isLishude/random.ts.git#9d22109491"
}