2017-06-18 71 views
0

我有頂級的package.json在哪裏設置cacheDirectories按https://devcenter.heroku.com/articles/nodejs-support#custom-cachingHeroku的node_modules不緩存

"scripts": { 
    "start": "npm --prefix frontend start && npm --prefix mockserver start", 
}, 
"dependencies": { 
}, 
"devDependencies": { 
}, 
"cacheDirectories": ["frontend/node_modules", "mockserver/node_modules"], 
... 

在頂層所以沒有依賴性,但我有前端/的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的構建輸出:

-----> 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

我得到的答案在這裏:https://github.com/heroku/heroku-buildpack-nodejs/issues/435

總之,我應該使用Heroku的-postbuild而不是啓動腳本安裝自定義的依賴。並使用啓動只作爲應用程序啓動命令。

頂級的package.json

"scripts": { 
    "heroku-postbuild": "npm --prefix frontend run installAndCompile && npm --prefix mockserver run installAndCompile", 
    "start": "npm --prefix mockserver start" 
    }, 

子項目的的package.json

"scripts": { 
    "installAndCompile": "npm install && npm run compile" 
    },