我已根据https://devcenter.heroku.com/articles/nodejs-support#custom-caching
设置了cacheDirectories的package.json。"scripts": {
"start": "npm --prefix frontend start && npm --prefix mockserver start",
},
"dependencies": {
},
"devDependencies": {
},
"cacheDirectories": ["frontend/node_modules", "mockserver/node_modules"],
...
所以没有toplevel的依赖,但是我有frontend / package.json和mockserver / package.json,它们有很多依赖项,它们安装在各自的node_modules中。这就是各个package.jsons的样子(例如mockserver):
"scripts": {
"start": "npm install && npm run build && node dist/server.js",
},
dependencies...
devdependencies...
这样可以正常工作并进行部署,但它不会缓存定义为缓存的两个node_modules。
以下是heroku build的输出:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
NODE_VERBOSE=false
NODE_ENV=demo
NODE_MODULES_CACHE=true
npm scripts will see NODE_ENV=production (not 'demo')
https://docs.npmjs.com/misc/config#production
-----> Installing binaries
engines.node (package.json): 7.10.0
engines.npm (package.json): unspecified (use default)
Downloading and installing node 7.10.0...
Using default npm version: 4.2.0
-----> Restoring cache
Loading 2 from cacheDirectories (package.json):
- frontend/node_modules (not cached - skipping)
- mockserver/node_modules (not cached - skipping)
-----> Building dependencies
Installing node modules (package.json)
-----> Caching build
Clearing previous node cache
Saving 2 cacheDirectories (package.json):
- frontend/node_modules (nothing to cache)
- mockserver/node_modules (nothing to cache)
-----> Build succeeded!
请注意,两个node_modules已安装在上一个版本中,但它表示(未缓存 - 跳过)。
提前致谢!
答案 0 :(得分:0)
我在这里得到了答案:https://github.com/heroku/heroku-buildpack-nodejs/issues/435
总之,我应该使用heroku-postbuild而不是start脚本来安装自定义依赖项。并且仅使用start作为应用程序启动命令。
顶级package.json
"scripts": {
"installAndCompile": "npm install && npm run compile"
},
子项目的package.json
{{1}}