将服务器任务添加到我的gruntfile.js,其中包含连接任务以连接到中间件代理,但找不到



我将新的服务器任务添加到我现有的Gruntfile中,该任务包含唯一将内容构建到缩小文件中的任务。我需要添加服务器/服务任务。对我来说,服务器任务的目标是连接到遇到/web/*时将中间件代理重定向到其他URL。我不断收到以下错误:

运行"服务器"任务

警告:未找到任务"连接:服务器"。使用 - 努力继续。

任何帮助将不胜感激!

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:AltProjectwebappWEB-INFfront-endscreening>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:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-watchpackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-watchpackage.json...OK
Loading "watch.js" tasks...OK
+ watch
Registering "grunt-contrib-concat" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-concatpackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-concatpackage.json...OK
Loading "concat.js" tasks...OK
+ concat
Registering "grunt-contrib-uglify" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-uglifypackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-uglifypackage.json...OK
Loading "uglify.js" tasks...OK
+ uglify
Registering "grunt-contrib-copy" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-copypackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-contrib-copypackage.json...OK
Loading "copy.js" tasks...OK
+ copy
Registering "grunt-concat-css" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-concat-csspackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-concat-csspackage.json...OK
Loading "concat_css.js" tasks...OK
+ concat_css
Registering "grunt-processhtml" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-processhtmlpackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-processhtmlpackage.json...OK
Loading "processhtml.js" tasks...OK
+ processhtml
Registering "rebase" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesrebasepackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesrebasepackage.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:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-lineendingpackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-lineendingpackage.json...OK
Loading "lineending.js" tasks...OK
+ lineending
Registering "grunt-text-replace" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-text-replacepackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-text-replacepackage.json...OK
Loading "text-replace.js" tasks...OK
+ replace
Registering "grunt-connect-proxy" local Npm module tasks.
Reading C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-connect-proxypackage.json...OK
Parsing C:AltProjectwebappWEB-INFfront-endscreeningnode_modulesgrunt-connect-proxypackage.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.

我认为您缺少对grunt-contrib-connect的依赖性,并致电grunt.loadNpmTasks('grunt-contrib-connect');。grunt-connect-Proxy只是在其顶部添加代理中间件。

最新更新