我使用AWS云格式作为后端,其项目文件结构如下:
| template.yaml
| lambda-functions
| ---- function-1
|----function.js
|----package.json
| ---- function-2
|----function.js
|----package.json在AWS中,我执行aws cloudformation package,然后是aws cloudformation deploy。
如果我想让它工作,我需要同时对function-1和function-2子文件夹执行node_modules,并将node_modules子文件夹提交给git。
如何从buildspec直接在所有子文件夹上运行npm安装,这样我就不必提交node_modules子文件夹了。
发布于 2018-10-19 14:35:45
你可以用勒纳。
如果包之间存在依赖关系,Lerna也将帮助您。
基本上,您只需在根目录中添加一个lerna.json并使用lerna安装您的依赖项。
lerna.json:
{
"lerna": "2.11.0",
"packages": [
"lambda-functions/*"
],
"version": "0.0.0"
}我假设您使用的是AWS CodeBuild,下面是一些如何配置安装阶段的示例:
buildspec.yml和lerna:
version: 0.2
phases:
install:
commands:
- echo Entered the install phase...
- npm install --global lerna
- lerna bootstrap --concurrency=1 -- --production
...lerna bootstrap将为每个包创建node_modules。
如果不想使用lerna,可以为每个包添加一个命令。类似于:
buildspec.yml带纱:
version: 0.2
phases:
install:
commands:
- echo Entered the install phase...
- npm install --global yarn
- yarn --cwd lambda-functions/function-1 --production install
- yarn --cwd lambda-functions/function-2 --production install
- yarn --cwd lambda-functions/function-3 --production install
...或者:
buildspec.yml与npm:
version: 0.2
phases:
install:
commands:
- echo Entered the install phase...
- cd lambda-functions/function-1 && npm install --production
- cd lambda-functions/function-2 && npm install --production
- cd lambda-functions/function-3 && npm install --production
...https://stackoverflow.com/questions/52888164
复制相似问题