我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
当前回答
完整的纱线用户本地开发指南:
首先在主项目中添加依赖项:
cd main-project
yarn add file:../path/to/your-library
接下来,如果你想避免在每次改变它的源代码时重新构建这个依赖:
cd your-library
yarn link
这将注册一个到你的库的链接。接下来,使用刚刚在主项目中创建的链接。
cd main-project
yarn link your-library
现在,每次更改库中的代码时,您都不需要重新构建它,它将自动包含在主项目中。Yarn link的工作原理是在你的node_modules文件夹中创建符号链接,在这里阅读更多信息:https://classic.yarnpkg.com/lang/en/docs/cli/link/
其他回答
我想使用一组用TypeScript编写的本地依赖,这里的答案都不适合我。NPM安装会直接拒绝构建依赖项。
我不得不使用tsconfig。Json将包添加到我的项目中,而不将它们标记为依赖项。我的用例更加复杂,因为有些依赖项是相互依赖的,我希望所有依赖项都来自本地文件夹。
以下是我的解决方案:
// tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@tiptap/*": [
"tiptap/packages/*/src"
]
}
}
}
在上面的例子中,我有一个名为tiptap/的本地项目子文件夹,在tiptap/packages/*中有许多包。“路径”选项将重写所有@tiptap/foo导入到。/tiptap/packages/foo/src,包括我自己的文件和tiptap/中的文件。
这不是一个很好的解决方案,但这是唯一对我有效的方法。
用纱线可以这样做
纱线添加文件:../somelocallib
现在可以在包中指定本地Node模块安装路径。直接json。从文档中可以看出:
Local Paths As of version 2.0.0 you can provide a path to a local directory that contains a package. Local paths can be saved using npm install -S or npm install --save, using any of these forms: ../foo/bar ~/foo/bar ./foo/bar /foo/bar in which case they will be normalized to a relative path and added to your package.json. For example: { "name": "baz", "dependencies": { "bar": "file:../foo/bar" } } This feature is helpful for local offline development and creating tests that require npm installing where you don't want to hit an external server, but should not be used when publishing packages to the public registry.
实际上,从npm 2.0开始,现在已经支持本地路径了。
完整的本地开发有两个步骤:
提供包含包的本地目录的路径。
{ “名称”:“记者”, “依赖”:{ “酒吧”:“文件:. . / foo / bar” } }
符号链接包文件夹 CD ~/projects/node-redis #进入包目录 NPM link #创建全局链接 CD ~/projects/node-bloggy #进入其他包目录。 NPM link redis # link-install包