Using auth tokens in .npmrc

前端 未结 2 545
忘掉有多难
忘掉有多难 2020-12-29 09:10

I have a project where we use font awesome 5 library. I followed the instructions that are written here and added an .npmrc file with my auth token.

Is

2条回答
  •  醉梦人生
    2020-12-29 09:37

    It is definitely NOT a safe behavior to put the token in any git checked file, including .npmrc.

    Below are the steps your team can take to safely leverage your npm token.

    There are two different environments to consider:

    1. each developer's local dev machine
    2. the app's deployment platform

    local dev

    Following the Global Set Up instructions you linked to in your question, is not the solution.

    Create the .npmrc file similar to the "Per project" instructions, but substitute your real token with a variable name, prefixed by $. ie:

    @fontawesome:registry=https://npm.fontawesome.com/
    //npm.fontawesome.com/:_authToken=$TOKEN
    

    npm will detect an environment variables file named .env. So, in a .gitignored .env file, add your secret key value pair, ie:

    TOKEN=ABC123
    

    You can also prefix the variable name with "NPM_CONFIG_", according to the npm-config docs, ie:

    NPM_CONFIG_TOKEN=ABC123
    

    Now, when the dev runs npm i, font-awesome dependencies will load from the private repo.

    NOTE: Don't follow the current npm-config docs about the environment variables syntax! See this stack overflow answer, ie:

提交回复
热议问题