Exclude test code in npm package?

后端 未结 2 1382
逝去的感伤
逝去的感伤 2021-02-01 01:48

The devDependencies section of npm\'s package.json documentation says to list your test dependencies there so that users of your package don\'t have to pull down extra dependenc

相关标签:
2条回答
  • 2021-02-01 02:36

    Another approach is to use a lib folder and store everything in there. Then you can configure your package.json to consider only that folder.

    In order to work you need also to move your main file inside lib and specify it in the package.json. See example below:

    {
      "name": "your-package",
      "main": "./lib/index.js",
      "files": [
        "/lib"
      ]
    }
    

    More info are available on this nice article

    0 讨论(0)
  • 2021-02-01 02:39

    Yes that's what most people do, here are some npmignore files for popular Node.js modules:

    https://github.com/socketio/socket.io/blob/ab46351a8446516fb4eea3b8333f7c0f18afaac5/.npmignore

    Other people whitelist what they want published in their package.json files setting:

    https://github.com/senchalabs/connect/blob/master/package.json
    https://github.com/strongloop/express/blob/master/package.json

    0 讨论(0)
提交回复
热议问题