How to npm publish specific folder but as package root

后端 未结 10 1275
后悔当初
后悔当初 2020-12-13 01:10

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,

10条回答
  •  情话喂你
    2020-12-13 01:56

    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.

提交回复
热议问题