首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将服务器任务添加到我的gruntfile.js中,该任务包含连接到中间件代理的连接任务,但未找到

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

Stack Overflow用户
提问于 2017-06-08 14:00:44
回答 1查看 522关注 0票数 0

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

运行“服务器”任务 警告:找不到“连接:服务器”任务。继续使用武力。

任何帮助都将不胜感激!

代码语言:javascript
复制
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'
        ]);
    });

日志:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-12 15:32:41

我认为您缺少了对grunt-connect和调用grunt.loadNpmTasks('grunt-contrib-connect');的依赖。grunt-connect proxy只是在上面添加了代理中间件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44437863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档