How do I include a .gitignore file as part of my npm module?

I am building an npm module that will generate a specific project template for certain software projects. As such, when a developer installs my npm module and runs it, I would like the program to create files and folders in a certain way.

One such file I would like to include in the project template is a .gitignore file because the software project is going to assume it will be tracked via git. However, when I call "npm install" on my module, npm renames all my .gitignore files to .npmignore files. How can I ensure that my .gitignore files are not tampered with by npm when I distribute my module?

You can see multiple commits dealing with npm issue 1862:

  • this project adds a rename.json:

    lib/init-template/rename.json
    {
        ".npmignore": ".gitignore",
    }
    
  • this one renames the .gitignore:

    templates/default/.gitignore → templates/default/{%=gitignore%}
    
    index.js
    @@ -114,6 +114,10 @@ generator._pkgData = function (pkg) {
        + // npm will rename .gitignore to .npmignore:
        + // [ref](https://github.com/npm/npm/issues/1862)
        + pkg.gitignore = '.gitignore';