2017-06-08 4 views
0

私は、既存のgruntfileに新しいサーバタスクを追加しました。 server/serveタスクを追加する必要があります。サーバータスクの目的は、/web/*に遭遇したときに他のURLにリダイレクトするためにミドルウェアのプロキシに接続することです。タスクは、 "接続:サーバーが見つかりません" "サーバー" タスクミートウェアプロキシに接続するための接続タスクを含むgruntfile.jsにサーバタスクを追加しました。

警告を実行

:私は、次のエラーを取得してください。続行するには--forceを使用します。

ご協力いただければ幸いです!

module.exports = function (grunt) { 
    grunt.loadNpmTasks('grunt-connect-proxy'); 
    grunt.initConfig({ 
     connect: { 
      server: { 
       options: { 
        port: 8080, 
        hostname: 'localhost', 
        middleware: function (connect, options) { 
         var proxy = require('grunt-connect-proxy/lib/utils').proxyRequest; 
         return [ 
          // Include the proxy first 
          proxy, 
          // Serve static files. 
          connect.static(options.base), 
          // Make empty directories browsable. 
          connect.directory(options.base) 
         ]; 
        } 
       }, 
       proxies: [ 
        { 
         context: '/web/*', 
         host: 'blah.com', 
         port: 8080, 
         https: true, 
         secure: false, 
         changeOrigin: true 
        } 
       ] 
      } 
     }, 
     pkg: grunt.file.readJSON('package.json'), 
}); 

    grunt.registerTask('server', function (target) { 
     grunt.task.run([ 
      'configureProxies:server', 
      'connect:server' 
     ]); 
    }); 

ログイン:

C:\AltProject\webapp\WEB-INF\front-end\screening>grunt server --verbose 
Initializing 
Command-line options: --verbose 

Reading "Gruntfile.js" Gruntfile...OK 

Registering Gruntfile tasks. 

Registering "grunt-contrib-watch" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-watch\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-watch\package.json...OK 
Loading "watch.js" tasks...OK 
+ watch 

Registering "grunt-contrib-concat" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-concat\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-concat\package.json...OK 
Loading "concat.js" tasks...OK 
+ concat 

Registering "grunt-contrib-uglify" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-uglify\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-uglify\package.json...OK 
Loading "uglify.js" tasks...OK 
+ uglify 

Registering "grunt-contrib-copy" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-copy\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-contrib-copy\package.json...OK 
Loading "copy.js" tasks...OK 
+ copy 

Registering "grunt-concat-css" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-concat-css\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-concat-css\package.json...OK 
Loading "concat_css.js" tasks...OK 
+ concat_css 

Registering "grunt-processhtml" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-processhtml\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-processhtml\package.json...OK 
Loading "processhtml.js" tasks...OK 
+ processhtml 

Registering "rebase" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\rebase\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\rebase\package.json...OK 
Loading "grunt-rebase.js" tasks...OK 
+ rebase 
Loading "gulp-rebase.js" tasks...OK 
>> No tasks were registered or unregistered. 

Registering "grunt-lineending" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-lineending\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-lineending\package.json...OK 
Loading "lineending.js" tasks...OK 
+ lineending 

Registering "grunt-text-replace" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-text-replace\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-text-replace\package.json...OK 
Loading "text-replace.js" tasks...OK 
+ replace 

Registering "grunt-connect-proxy" local Npm module tasks. 
Reading C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-connect-proxy\package.json...OK 
Parsing C:\AltProject\webapp\WEB-INF\front-end\screening\node_modules\grunt-connect-proxy\package.json...OK 
Loading "connect_proxy.js" tasks...OK 
+ configureProxies 
Reading package.json...OK 
Parsing package.json...OK 
Initializing config...OK 
Loading "Gruntfile.js" tasks...OK 
+ build, server 

Running tasks: server 

Running "server" task 
Warning: Task "connect:server" not found. Use --force to continue. 

Aborted due to warnings. 
+0

grunt-connect-proxyをpackage.jsonに追加しましたか? – amiramw

+0

はい、これが追加されました。 – saumj

+0

--verboseでgruntを実行するとログを共有できますか? – amiramw

答えて

0

私はあなたがしてgrunt.loadNpmTasks('grunt-contrib-connect');に呼接続作男-contribの依存を欠けていると思います。 grunt-connect-proxyは、その上にプロキシミドルウェアを追加するだけです。

+0

ありがとうございました! – saumj

関連する問題