admin管理员组文章数量:1401819
I have a project that contains several sub projects, one of which is a JavaScript project. I want to use the JavaScript project as a task runner for the entire project via gulp
but I'm running into some trouble.
My project structure is essentially:
root
|_
js-client
|_
package.json
|_
node_modules
|_
go-server
I've determined that .yarnrc
can be used to specify a different node_modules
location, so I moved package.json
to the root
directory and created this .yarnrc
file:
--modules-folder client/node_modules
Now when I run yarn install
from the root directory, the modules do get installed exactly as I expect in the specified location but when I run yarn build
I get this error:
[09:46:17] Local modules not found in ~/Documents/Projects/root
[09:46:17] Try running: npm install
I'm guessing this means --modules-folder
is only used as a flag for install
and not for run
. Is what I'm trying to do possible, or do I just have to create a separate yarn project to run tasks? I'd rather not rely on global to acplish this
I have a project that contains several sub projects, one of which is a JavaScript project. I want to use the JavaScript project as a task runner for the entire project via gulp
but I'm running into some trouble.
My project structure is essentially:
root
|_
js-client
|_
package.json
|_
node_modules
|_
go-server
I've determined that .yarnrc
can be used to specify a different node_modules
location, so I moved package.json
to the root
directory and created this .yarnrc
file:
--modules-folder client/node_modules
Now when I run yarn install
from the root directory, the modules do get installed exactly as I expect in the specified location but when I run yarn build
I get this error:
[09:46:17] Local modules not found in ~/Documents/Projects/root
[09:46:17] Try running: npm install
I'm guessing this means --modules-folder
is only used as a flag for install
and not for run
. Is what I'm trying to do possible, or do I just have to create a separate yarn project to run tasks? I'd rather not rely on global to acplish this
2 Answers
Reset to default 5The answer is to run yarn with --cwd
This changes yarn's working directory to whatever you specify
So for the example above, to run yarn build
from the root directory, you would type:
yarn --cwd js-client build
Do you have a build script in your package.json?
If not, I would add it to your package.json to overwrite the default behavior and start the script with something like: cd client && yarn build
.
Edit:
root
--package.json (with the build script)
--client
本文标签: javascriptRun Yarn tasks from a parent directoryStack Overflow
版权声明:本文标题:javascript - Run Yarn tasks from a parent directory - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744303283a2599685.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论