javascript - Run Yarn tasks from a parent directory - Stack Overflow

I have a project that contains several sub projects, one of which is a JavaScript project. I want to us

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

Share Improve this question edited Jul 23, 2019 at 16:29 tk421 5,9776 gold badges26 silver badges36 bronze badges asked Jul 23, 2019 at 13:49 Robbie MilejczakRobbie Milejczak 5,7903 gold badges35 silver badges68 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744303283a4567604.html

相关推荐

  • javascript - Run Yarn tasks from a parent directory - Stack Overflow

    I have a project that contains several sub projects, one of which is a JavaScript project. I want to us

    7天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信