grunt-contrib-connect仅适用于keepalive [英] grunt-contrib-connect works only with keepalive

查看:150
本文介绍了grunt-contrib-connect仅适用于keepalive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试连接服务器时发生了一些奇怪的事情。
终端没有错误,它显示开始连接网络服务器 http://0.0.0.0:5555,然后完成没有错误。但是,当我服务于 http:// localhost:5555 / 时 - 我得到了典型的未找到页面。
在Chrome控制台中有一个警告和一个错误:

  i18n-values:缺少primaryParagraph的值
http:// localhost:5555 /:1 GET http:// localhost:5555 / net :: ERR_CONNECTION_REFUSED



更令人惊讶的是,当我定义Keepalive时:确实一切正常。真的,我不明白为什么会这样。



我的Gruntfile.js

 'use strict'; 

module.exports = function(grunt){

//任务
grunt.initConfig({
//编译SASS
sass :{
dist:{
files:[{
expand:true,
flatten:true,
src:['assets / source / sass / *。scss ','app / shared / ** / *。scss','app / components / ** / *。scss'],
dest:'assets / source / css /',
ext: '.css'
}]
}
},

//连接并缩小CSS
cssmin:{
styles:{
档案:{
'public / css / style.min.css':['assets / source / css / *。css','assets / source / libs / ** / *。css', 'app / shared / ** / * .css','app / components / ** / * .css']
}
}
},

// autoprefix
autoprefixer:{
options:{
browsersers:['> 1%','Android 2','last 2 versions','Firefox ESR',' Opera 12.1','ie 7','ie 8','ie 9']
},
no_dest:{
src:'public / css / style.min.css'
}
},

//编译Coffeescript
咖啡:{
编译:{
options:{
separator:' ;'
},
文件:{
'public / js / scripts.js':['app / *。coffee','app / shared / ** / * module *。咖啡','app / shared / ** / *。coffee','app / components / ** / * module * .coffee','app / components / ** / *。coffee']
}



// concat and minify JS
concat:{
options:{
separator:';'
},
脚本:{'b $ b src:['assets / source / libs / angular / angular.js','assets / source / js / *。js','assets / source / libs / * .js','assets / source / libs / ** / *。js'],
dest:'public / js / vendor.js'
}
},

u glify:{
scripts:{
files:{
'public / js / scripts.min.js':'public / js / scripts.js',
'public / js / vendor.min.js':'public / js / vendor.js'
}
}
},

//手表
手表:{
options:{
livereload:true
},
scripts:{
files:['app / * module * .coffee','app / *路由* .coffee ' '应用程序/ *咖啡', '应用程序/共享/ ** / * *模块.coffee', '应用程序/共享/ ** / *。咖啡',' 应用/组件/ ** / * *模块.coffee ' '应用程序/部件/ ** / *。咖啡', '资产/源/ JS / *。JS', '资产/源/库/ *。JS',' 资产/源/库/ ** / $ .js'],
任务:['coffee','concat','uglify']
},
css:{'b $ b files:['资产/源极/ SASS / *。SCSS', '应用程序/共享/ ** / *。SCSS', '应用程序/部件/ ** / *。SCSS', '资产/源极/ CSS / *。CSS',资产/源极/升ibs / ** / * .css','app / shared / ** / * .css','app / components / ** / * .css'],
任务:['sass','cssmin ','autoprefixer']
}
},

// minification
imagemin:{
dynamic:{
files:[{
展开:true,
cwd:'assets / img /',
src:['*。{png,jpg,gif}'],
dest:'public / img /'
}]
}
},

// bower
bower:{
install:{
options :{
targetDir:'assets / source / libs /',
layout:'byComponent',
cleanBowerDir:false
}
}
},

//服务器
连接:{
服务器:{
选项:{
端口:5555
}
}
}

});

grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-contrib-connect');

//一些默认任务

grunt.registerTask('default',['coffee','concat','uglify','sass','cssmin', 'autoprefixer']);
grunt.registerTask('publish',['bower','coffee','concat','uglify','sass','cssmin','autoprefixer']);
grunt.registerTask('serv',['connect','watch']);
};


解决方案

抱歉说,但这只是 Grunt如何连接



< blockquote>

请注意,只有grunt正在运行,此服务器才会运行。一旦咕噜的任务完成,Web服务器停止。这种行为可以通过keepalive选项来改变,并且可以通过运行像grunt connect :: keepalive这样的任务来启用ad-hoc。


这是一个有意的功能。 Grunt connect仅用于运行构建或测试任务时使用,并不打算成为本地服务器用于在网站上播放。



如果您需要小型本地服务器的静态文件(html / css / js / image),那么我会推荐 npm模块HTTP服务器 。安装和运行非常简单:
$ b

 〜$ npm install -g http-server 
〜$ cd / path / to / your / project
〜$ http-server

祝你好运。


Something strange happens, when I try to connect to server. There are no errors in terminal, it says "Started connect web server on http://0.0.0.0:5555", then done without errors. But when I serf to http://localhost:5555/ - I get typical "page not found". In chrome console one warning and one error:

i18n-values: Missing value for "primaryParagraph"
http://localhost:5555/:1 GET http://localhost:5555/ net::ERR_CONNECTION_REFUSED

The more surprising is that when I define keepalive:true everything works fine. Really, I don't get why is it so.

My Gruntfile.js

'use strict';

module.exports = function( grunt ) {

// tasks
grunt.initConfig({
    // compile SASS
     sass: {
        dist: {
          files: [{
            expand: true,
            flatten: true,
            src: ['assets/source/sass/*.scss','app/shared/**/*.scss','app/components/**/*.scss'],
            dest: 'assets/source/css/',
            ext: '.css'
          }]
        }
    },

    // concat and minify CSS
    cssmin: {
        styles: {    
            files: {
                'public/css/style.min.css': ['assets/source/css/*.css','assets/source/libs/**/*.css','app/shared/**/*.css','app/components/**/*.css']
            }
        }
    },

    // autoprefix
    autoprefixer: {
        options: {
          browsers: ['> 1%', 'Android 2', 'last 2 versions', 'Firefox ESR', 'Opera 12.1', 'ie 7', 'ie 8', 'ie 9']
        },
        no_dest: {
          src: 'public/css/style.min.css'
        }
    },

    // compile Coffeescript
    coffee: {
      compile: {
        options: {
            separator: ';'
        },
        files: {
          'public/js/scripts.js': ['app/*.coffee','app/shared/**/*module*.coffee','app/shared/**/*.coffee','app/components/**/*module*.coffee','app/components/**/*.coffee']
        }
      }
    },

    // concat and minify JS
    concat: {
        options: {
            separator: ';'
        },
        scripts: {
            src: ['assets/source/libs/angular/angular.js', 'assets/source/js/*.js','assets/source/libs/*.js','assets/source/libs/**/*.js'],
            dest: 'public/js/vendor.js'
        }
    },

    uglify: {
        scripts: {
            files: {
                'public/js/scripts.min.js': 'public/js/scripts.js',
                'public/js/vendor.min.js': 'public/js/vendor.js'
            }
        }
    },

    // watch
    watch: {
        options: {
            livereload: true
        },
        scripts: {
            files: ['app/*module*.coffee','app/*routing*.coffee','app/*.coffee','app/shared/**/*module*.coffee','app/shared/**/*.coffee','app/components/**/*module*.coffee','app/components/**/*.coffee','assets/source/js/*.js','assets/source/libs/*.js','assets/source/libs/**/*.js'],
            tasks: [ 'coffee', 'concat', 'uglify' ]
        },
        css: {
            files: ['assets/source/sass/*.scss','app/shared/**/*.scss','app/components/**/*.scss','assets/source/css/*.css','assets/source/libs/**/*.css','app/shared/**/*.css','app/components/**/*.css'],
            tasks: [ 'sass', 'cssmin', 'autoprefixer' ]
        }
    },

    // minification
    imagemin: {
        dynamic: {
            files: [{
                expand: true,
                cwd: 'assets/img/',
                src: ['*.{png,jpg,gif}'],
                dest: 'public/img/'
            }]
        }
    },

    // bower
    bower: {
        install: {
          options: {
            targetDir: 'assets/source/libs/',
            layout: 'byComponent',
            cleanBowerDir: false
          }
        }
      },

    // server
      connect: {
        server: {
          options: {
            port: 5555
          }
        }
      }

});

grunt.loadNpmTasks( 'grunt-contrib-coffee');
grunt.loadNpmTasks( 'grunt-contrib-concat');
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-autoprefixer' );
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-contrib-connect');

// some default tasks

grunt.registerTask('default', [ 'coffee', 'concat', 'uglify' , 'sass', 'cssmin', 'autoprefixer']);
grunt.registerTask('publish', [ 'bower', 'coffee', 'concat', 'uglify' , 'sass', 'cssmin', 'autoprefixer']);
grunt.registerTask('serv', [ 'connect', 'watch']);
};

解决方案

Sorry to say, but that is just how Grunt connect works:

Note that this server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. This behavior can be changed with the keepalive option, and can be enabled ad-hoc by running the task like grunt connect::keepalive.

This is an intentional feature. Grunt connect is only intended to be used while running build or test tasks, it is not intended to be a local server for playing around with a site.

If you need a small, local server for static files (html/css/js/image) then I would recommend the npm module "http-server". It's very easy to install and run:

~$ npm install -g http-server
~$ cd /path/to/your/project
~$ http-server

Good luck.

这篇关于grunt-contrib-connect仅适用于keepalive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆