I have a project that include a gulp task for building and packaging the sources and release in a directory called dist. My goal is publish it as a npm package,
If your project has git you can use small hack. Add next scripts to package.json
"prepublishOnly": "npm run build && cp -r ./lib/* . && rm -rf ./lib",
"postpublish": "git clean -fd",
now when you run publish command npm involve prepublishOnly. It builds files and saves them to lib folder (a build script depend on your project). The next command copies files to root folder and removes lib. After publish postpublish script returns the project to a previous state.