如何包含我的 node_modules 或为私有(private) npm 模块指定 npm 登录/授权 token ?
似乎 GAE 不再允许包含 node_modules 文件夹(参见 this issue )并且似乎没有允许 npm 登录或设置 token 的 Hook 。
最佳答案
如果您在要部署的应用程序本地包含一个 .npmrc 文件,它将被复制到应用程序源中并在 npm 安装期间使用。您可以让构建步骤创建此文件或从您的主目录复制它。参见 this npm article .
.npmrc 文件应如下所示:
//registry.npmjs.org/:_authToken=<token here>
我使用的 Dockerfile 如下所示:
# Use the base App Engine Docker image, based on debian jessie.
FROM gcr.io/google_appengine/base
# Install updates and dependencies
RUN apt-get update -y && apt-get install --no-install-recommends -y -q curl python build-essential git ca-certificates libkrb5-dev && \
apt-get clean && rm /var/lib/apt/lists/*_*
# Install the latest release of nodejs
RUN mkdir /nodejs && curl https://nodejs.org/dist/v6.2.1/node-v6.2.1-linux-x64.tar.gz | tar xvzf - -C /nodejs --strip-components=1
ENV PATH $PATH:/nodejs/bin
COPY . /app/
WORKDIR /app
# NODE_ENV to production so npm only installs needed dependencies
ENV NODE_ENV production
RUN npm install --unsafe-perm || \
((if [ -f npm-debug.log ]; then \
cat npm-debug.log; \
fi) && false)
# start
CMD ["npm", "start"]
关于node.js - Google App Engine 上的私有(private) Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37780523/