http://0.0.0.0:5555"
上连接网络服务器,然后完成没有错误。但是当我到http://localhost:5555/
时,我会找到典型的"页面未找到"。
在chrome控制台中有一个警告和一个错误:
i18n-values: Missing value for "primaryParagraph"
http://localhost:5555/:1 GET http://localhost:5555/ net::ERR_CONNECTION_REFUSED
更令人惊讶的是,当我定义keepalive:true时一切正常。真的,我不知道为什么会这样。
我的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']);
};
答案 0 :(得分:1)
很抱歉,但这只是how Grunt connect works:
请注意,只要grunt正在运行,此服务器就会运行。一旦grunt的任务完成,Web服务器就会停止。可以使用keepalive选项更改此行为,并且可以通过运行grunt connect :: keepalive等任务来临时启用。
这是一个有意的功能。 Grunt connect仅用于运行构建或测试任务时使用,它不是用于在网站上玩游戏的本地服务器。
如果您需要一个用于静态文件的小型本地服务器(html / css / js / image),那么我会推荐npm module "http-server"。安装和运行非常简单:
~$ npm install -g http-server
~$ cd /path/to/your/project
~$ http-server
祝你好运。