Prepublish not working as expected

╄→гoц情女王★ 提交于 2020-01-15 12:59:11

问题


I am testing on npm scripts to build my project dependency.

My idea comes from https://github.com/ParsePlatform/parse-server which impressed me by code in repository doesn't mean code in node_modules after npm install.

Below is my testmodule structure

src/index.js
package.json

and this is my package.json content

{
  "name": "testmodule",
  "version": "1.0.0",
  "description": "",
  "main": "lib/index.js",
  "scripts": {
    "build": "babel src/ -d lib/",
    "prepublish": "npm run build"
  },
  "devDependencies": {
    "babel-cli": "^6.18.0",
    "babel-core": "^6.18.2"
  }
}

and this is structure I expect after run npm install testmodule

node_modules/testmodule/lib/index.js
node_modules/testmodule/package.json

which is src folder should not be here.

But after I run npm install, it is exactly the same as when I push to my git repository.

Please take note that I am using GitLab in my own server.

So my questions are:

  1. Is there anything that i'm missing to make prepublish run?

  2. Which part of parse-server code makes the src folder and other files not there after install?


回答1:


How are you running npm install?

According to the documentation on npm scripts, the prepublish script is run "BEFORE the package is published. (Also run on local npm install without any arguments.)". It seems clear that the prepublish script is only run on npm publish or npm install <local directory>.

If you are trying to install directly from your local gitlab server via a URL, this will not work - the script will not be run. The solution would be to install locally unless you're willing to open source your package & push it to the npm repository or pay for a private npm repository. This is what I have done during development of packages before they're ready to be made public.



来源:https://stackoverflow.com/questions/40880642/prepublish-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!