Remove development specific entries from package.json when running npm pack (or pnpm pack)

199 views Asked by At

I have a package.json with this kind of content:

{
  "name": "smoketest",
  "version": "0.0.1",
  "main": "dist/index.js",
  "files": [
    "dist"
  ],
  "scripts": {
    "run": "node dist/index.js",
    "build": "rm -rf dist && NODE_ENV=production rollup -c",
    "dev": "rm -rf dist && rollup -c -w"
  },
  "dependencies": {
    "jest-cli": "^27.2.5"
  },
  "devDependencies": {
    "@babel/plugin-proposal-class-properties": "^7.14.5",
    "@babel/plugin-proposal-decorators": "^7.15.8",
    "@babel/plugin-proposal-private-methods": "^7.14.5",
    "@babel/preset-env": "^7.15.8",
    "@babel/preset-typescript": "^7.15.0",
    "@rollup/plugin-babel": "^5.3.0",
    "@rollup/plugin-commonjs": "^21.0.0",
    "@rollup/plugin-json": "^4.1.0",
    "@rollup/plugin-node-resolve": "^13.0.5",
    "@rollup/plugin-run": "^2.1.0",
    "@types/minimist": "^1.2.2",
    "babel-plugin-transform-typescript-metadata": "^0.3.2",
    "babel-plugin-tsconfig-paths": "^1.0.2",
    "cross-fetch": "^3.1.4",
    "minimist": "^1.2.5",
    "rollup": "^2.58.0",
    "rollup-plugin-multi-input": "^1.3.1"
  }
}

I am using npm pack to create an archive. That works quite nicely. However, I'd like to remove development specific stuff:

{
  "name": "smoketest",
  "version": "0.0.1",
  "main": "dist/index.js",
  "files": [
    "dist"
  ],
  "scripts": {
    "run": "node dist/index.js",
  },
  "dependencies": {
    "jest-cli": "^27.2.5"
  }
}

Is it somehow possible to either specify a different package.json or specify some keys to be dropped?

Any solution for npm or pnpm would work for me.

0

There are 0 answers