yarn run script with parameters

我只是一个虾纸丫 提交于 2020-01-06 06:52:29

问题


How do I pass a parameter? When I run "yarn generate" it will make both a "-p" and a "test" directory. But it works well when I run "mkdir -p test" in bash. I tried to [-p] as well but it only creates that directory.

"scripts": {
    "generate": "mkdir -p test"
  }

回答1:


Although I could not reproduce the issue that you mentioned (my config: node v8.11.1 and yarn v1.2.1, latest MacOS), according to the yarn docs, you can pass the arguments to yarn script by appending them normally, like so:

yarn generate -p test

In this case your npm (yarn) scripts config (in the package.json, I assume) would look like

"scripts": {
    "generate": "mkdir"
}

If you're using Windows, you indeed won't have the mkdir -p flag (read this). In order to make what you want (check if the folder does not exist and if so, create one) you'd need to use some cmd commands. So your package.json will contain smth like

"scripts": { 
    "generate": "IF NOT EXIST test mkdir test" 
}


来源:https://stackoverflow.com/questions/50010211/yarn-run-script-with-parameters

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