我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
我想这样做,所以npm install也会安装这个包。Json的../somelocallib或者更重要的是它的依赖项。
"dependencies": {
"express": "*",
"../somelocallib": "*"
}
当前回答
这是如何添加本地依赖项的:
npm安装文件:src/assets/js/FILE_NAME
把它添加到包中。json来自NPM:
保存文件:src/assets/js/FILE_NAME
直接添加到包。Json是这样的:
....
"angular2-autosize": "1.0.1",
"angular2-text-mask": "8.0.2",
"animate.css": "3.5.2",
"LIBRARY_NAME": "file:src/assets/js/FILE_NAME"
....
其他回答
实际上,从npm 2.0开始,现在已经支持本地路径了。
使用工作空间
使用该文件的缺点:../path/to/your-library是你必须安装NPM或使用NPM link,以使更改在导入你的包的包中生效。
如果你使用pnpm:一个更好的解决方案是使用workspace: protocol: workspace:../path/to/your-library。它会将目录符号链接到您的node_modules目录,而不是复制它,因此源上的任何更改都会立即生效。
例如:
...
"dependencies": {
...
"my-package": "workspace:../../dist"
},
注意:此解决方案打算在工作空间中使用,因此可能需要创建pnpm-workspace。Yaml(甚至是一个空文件)文件在您的项目的根。
现在可以在包中指定本地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.
这对我很有用。
将以下内容放入包中。json文件
"scripts": {
"preinstall": "npm install ../my-own-module/"
}
有一个很棒的yalc可以帮助管理本地包。它帮助我使用后来部署的本地库。只需用.yalc目录打包项目(带或不带/node_modules)。所以只要这样做:
npm install -g yalc
in directory lib/$ yalc publish
在项目:
project/$ yalc add lib
project/$ npm install
就是这样。
当你想更新东西:
lib/$ yalc push //this will updated all projects that use your "lib"
project/$ npm install
使用Docker打包和部署
tar -czvf <compresedFile> <directories and files...>
tar -czvf app.tar .yalc/ build/ src/ package.json package-lock.json
注意:记得添加.yalc目录。
inDocker:
FROM node:lts-alpine3.9
ADD app.tar /app
WORKDIR /app
RUN npm install
CMD [ "node", "src/index.js" ]