如何在 G运行t 上 运行 多次申请

How to run multiple application on Grunt

我有两个应用程序说 applicationAapplicationB 如果我 运行 在终端上执行命令

grunt serve

我的 applicationA 会正常工作。

当我需要 运行 applicationB 时,首先我需要停止 applicationA 然后我可以 运行 applicationB。如果我尝试 运行 两者,那么它会像这样抱怨

Fatal error: Port 9000 is already in use by another process.

注意:它 运行 所在的端口 9000,一个应用程序在 angularJS 中,另一个包含静态页面

所以我的问题是,我可以在 Grunt 上并行 运行 多个应用程序吗?如果是,请指导我该怎么做?

So my question is that can I run multiple applications on Grunt in parallel? if yes then please guide me how can i do that

是的,您可以通过 g运行t(从单独的终端 windows)运行 多个应用程序,但要确保每个应用程序使用不同的端口号

您可以按如下方式注册g运行t任务:

grunt.registerTask('serve', function (target) {
    if (target === 'applicationA') {
        return grunt.task.run([ 
            'express:appA',
        ]);
    }
    return grunt.task.run([
           'express:appB',
         ]);
  });

运行 applicationA 为 grunt serve:applicationA applicationB 为 grunt serve:applicationB

希望一切顺利!

您可以通过更新 Gruntfile:

在另一个端口将 g运行t 配置为 运行
grunt.initConfig({
  server: {
    port: grunt.option('port') || 8000
  }
});

或从命令行:

$ grunt serve --port=8000

阅读他提到的@NLN 回答后

make sure each of them use different port number

所以我开始阅读我的 Gruntfile.js 文件。在这个文件中有一个 connect 对象定义如下 applicationA

grunt.initConfig({
   connect: {
      options: {
        port: 9000, 
        hostname: 'localhost',
        livereload: 35729 
      }
   }    
});

所以在其他 applicationB 中我更改了此配置 portlivereload 像这样

grunt.initConfig({
   connect: {
      options: {
        port: 9001, // change to some different port
        hostname: 'localhost',
        livereload: 35730 // this also need to change to some different port
      }
   }    
});

它对我有用。希望它也能帮助其他人:)

首先按照@Muhammad Suleman 的建议更改端口号

之后,如果问题仍然存在,请在应用程序 A 中更改 livereload:false 并保留 livereload:true 在应用程序 B.

options: {                    
           livereload: false
          }

P.S.- sublime text 2 livereload 相关问题由此解决。

如果有人在 grunt 中使用 watch 并且错误仍然显示 'Port is already used by some process',您还必须在 GruntFile.js 的 watch 中将行 livereload:true 更改为 livereload:9001一台服务器。