9

How to streamline npm release when I want to include only specific path(s)?

I have ./src and ./dist files in my repository. I want to effectively publish only the contents of ./dist + ./package.json.

Using .npmignore to ignore ./src will simply ignore the ./src folder. I want to include only the contents of ./dist, i.e. now user would need to do require('my-package/dist/something'). I want to make it require('my-package/something'). ./something is contained in ./dist.

Gajus
  • 69,002
  • 70
  • 275
  • 438
  • 2
    I am having this exact issue. With the main: "dist/" I can make the entry point work seamlessly, but if anyone wants to include something lower , they need the /dist/ in the path and I don't want that. – httpete Aug 10 '17 at 12:06

2 Answers2

11

The way I have done it at the moment is, I have created a bash script:

npm run build
cp package.json ./dist
# or, if you need to have package.json "main" entry different,
# e.g. for being able to use `npm link`, you need to replace "main" value:
# sed 's#"main": "./dist/index.js"#"main": "./index.js"#' package.json > ./dist/package.json
cd ./dist
npm publish
Gajus
  • 69,002
  • 70
  • 275
  • 438
0

For cross-platform compatibilty use shx:

npm run build
shx cp package.json ./dist
shx cd ./dist
npm publish
leonheess
  • 16,068
  • 14
  • 77
  • 112