As of my knowledge cutoff date in September 2021, there is no built-in feature in npm to ignore specific changelog files during the publish process. By default, npm uses the files specified in the "files" field of your package's package.json to determine which files to include when publishing.

However, if you want to exclude specific changelog files or any other files from being published to the npm registry, you can use a .npmignore file. The .npmignore file works similarly to .gitignore, where you can list files or directories that should be excluded from the npm package when publishing.

Here's how you can exclude specific changelog files using .npmignore:

  1. Create a .npmignore File: In your package's root directory, create a file named .npmignore if it doesn't already exist.

  2. Add Entries to .npmignore: In the .npmignore file, add the relative paths of the changelog files that you want to exclude from the published package. For example:

    # Exclude specific changelog files

    Make sure to include all the changelog files or directories that you want to exclude.

  3. Update package.json: Ensure that your package.json file lists the correct "files" field. The "files" field should include all the files that you want to include in the published package. Typically, you want to include all the necessary files and exclude the rest using .npmignore.

    For example, your "files" field in package.json might look like this:

    "files": [ "dist/", "src/", "", "package.json", "LICENSE" ],
  4. Publish the Package: After adding the .npmignore file and updating the "files" field, you can publish the package using the regular npm publish command:

    npm publish

During the publishing process, npm will use the .npmignore file to exclude the specified changelog files from the package. Only the files listed in the "files" field of package.json that are not ignored by .npmignore will be included in the published package.

Please note that the behavior of npm or npm-related tools might change over time, so it's a good idea to verify the current behavior of npm or consult the npm documentation for any updates or changes beyond my knowledge cutoff date.

Have questions or queries?
Get in Touch