Javascript Grunt--在同一端口上运行Connect和Express服务器
对于Grunt,我是新手,我很好奇是否可以在同一个端口上同时运行两台服务器。我已经有点麻烦了。。。问题可能在Grunt文件中 我使用和来实现各自的功能。理想情况下,grunt服务器将启动connect服务器、livereload和express服务器 我的Grunt文件在下面。谢谢Javascript Grunt--在同一端口上运行Connect和Express服务器,javascript,angularjs,express,gruntjs,Javascript,Angularjs,Express,Gruntjs,对于Grunt,我是新手,我很好奇是否可以在同一个端口上同时运行两台服务器。我已经有点麻烦了。。。问题可能在Grunt文件中 我使用和来实现各自的功能。理想情况下,grunt服务器将启动connect服务器、livereload和express服务器 我的Grunt文件在下面。谢谢 'use strict'; module.exports = function (grunt) { require('load-grunt-tasks')(grunt); grunt.initConfig
'use strict';
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
yeoman: {
// configurable paths
app: require('./bower.json').appPath || 'app',
dist: 'dist'
},
watch: {
styles: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{css,less}'],
tasks: ['copy:styles', 'autoprefixer', 'less']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/{,*/}*.html',
'.tmp/styles/{,*/}*.{css,less}',
'{.tmp,<%= yeoman.app %>}/scripts/{,*/}*.js',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
autoprefixer: {
options: ['last 1 version'],
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729,
keepalive: true
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
]
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'<%= yeoman.app %>'
]
}
},
dist: {
options: {
base: '<%= yeoman.dist %>'
}
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js'
]
},
less: {
development: {
options: {
paths: ["<%= yeoman.app %>/styles"],
yuicompress: true
}
},
files: {
"<%= yeoman.app %>/styles/style.css": "<%= yeoman.app %>/styles/style.less"
}
},
/*shell: {
launchExpress: {
command: function () {
console.log('Launching the API...');
return 'coffee server.coffee';
},
options: {
stdout: true
}
}
},*/
coffee: {
compile: {
files: {
'./server.js': './server.coffee'
}
}
},
express: {
options: {
// Override defaults here
},
dev: {
options: {
script: './server.js'
}
},
prod: {
options: {
script: './server.js',
node_env: 'production'
}
},
test: {
options: {
script: './server.js'
}
}
},
// not used since Uglify task does concat,
// but still available if needed
/*concat: {
dist: {}
},*/
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/scripts/{,*/}*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yeoman.dist %>/styles/fonts/*'
]
}
}
},
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
cssmin: {
// By default, your `index.html` <!-- Usemin Block --> will take care of
// minification. This option is pre-configured if you do not wish to use
// Usemin blocks.
// dist: {
// files: {
// '<%= yeoman.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css',
// '<%= yeoman.app %>/styles/{,*/}*.css'
// ]
// }
// }
},
htmlmin: {
dist: {
options: {
/*removeCommentsFromCDATA: true,
// https://github.com/yeoman/grunt-usemin/issues/44
//collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeOptionalTags: true*/
},
files: [{
expand: true,
cwd: '<%= yeoman.app %>',
src: ['*.html', 'views/*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
// Put files not handled in other tasks here
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'bower_components/**/*',
'images/{,*/}*.{gif,webp}',
'styles/fonts/*'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/images',
src: [
'generated/*'
]
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
concurrent: {
server: [
'coffee',
'copy:styles'
],
test: [
'coffee',
'copy:styles'
],
dist: [
'copy:styles',
'imagemin',
'svgmin',
'htmlmin'
]
},
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html']
}
},
ngmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.dist %>/scripts',
src: '*.js',
dest: '<%= yeoman.dist %>/scripts'
}]
}
},
uglify: {
dist: {
files: {
'<%= yeoman.dist %>/scripts/scripts.js': [
'<%= yeoman.dist %>/scripts/scripts.js'
]
}
}
}
});
grunt.registerTask('server', function (target) {
if (target === 'dist') {
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'concurrent:server',
'autoprefixer',
'express:dev',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test'
]);
grunt.registerTask('build', [
'clean:dist',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'copy:dist',
'cdnify',
'ngmin',
'cssmin',
'uglify',
'rev',
'usemin'
]);
grunt.registerTask('default', [
'jshint',
'test',
'build'
]);
};
“严格使用”;
module.exports=函数(grunt){
要求('load-grunt-tasks')(grunt);
grunt.initConfig({
约曼:{
//可配置路径
app:require('./bower.json').appPath | |“app”,
dist:“dist”
},
观察:{
风格:{
文件:['/styles/{,*/}*{css,less}'],
任务:['copy:styles','autoprefixer','less']
},
利弗雷罗德:{
选项:{
livereload:'
},
档案:[
'/{,*/}*.html',
“.tmp/styles/{,*/}*{css,less}”,
“{.tmp,}/scripts/{,*/}*.js”,
“/images/{,*/}*{png,jpg,jpeg,gif,webp,svg}”
]
}
},
自动刷新器:{
选项:[“上一版本”],
地区:{
档案:[{
是的,
cwd:“.tmp/styles/”,
src:'{,*/}*.css',,
目标:'.tmp/styles/'
}]
}
},
连接:{
选项:{
港口:9000,
//将此更改为“0.0.0.0”以从外部访问服务器。
主机名:“localhost”,
利弗雷罗德:35729,
keepalive:是的
},
利弗雷罗德:{
选项:{
开放:是的,
基数:[
“.tmp”,
''
]
}
},
测试:{
选项:{
港口:9001,
基数:[
“.tmp”,
"测试",,
''
]
}
},
地区:{
选项:{
基:“”
}
}
},
清洁:{
地区:{
档案:[{
多特:没错,
src:[
“.tmp”,
'/*',
“!/.git*”
]
}]
},
服务器:'.tmp'
},
jshint:{
选项:{
jshintrc:“.jshintrc”
},
全部:[
“Gruntfile.js”,
“/scripts/{,*/}*.js”
]
},
减:{
发展:{
选项:{
路径:[“/styles”],
yuicompress:是的
}
},
档案:{
“/styles/style.css”:“/styles/style.less”
}
},
/*外壳:{
launchExpress:{
命令:函数(){
log('启动API…');
返回“coffee server.coffee”;
},
选项:{
斯图特:是的
}
}
},*/
咖啡:{
汇编:{
档案:{
“./server.js”:“./server.coffee”
}
}
},
快递:{
选项:{
//在这里覆盖默认值
},
开发人员:{
选项:{
脚本:'./server.js'
}
},
产品:{
选项:{
脚本:'./server.js',
节点_env:'生产'
}
},
测试:{
选项:{
脚本:'./server.js'
}
}
},
//未使用,因为丑陋的任务不起作用,
//但如果需要,仍然可用
/*康卡特:{
地区:{}
},*/
修订版:{
地区:{
档案:{
src:[
“/scripts/{,*/}*.js”,
“/styles/{,*/}*.css”,
“/images/{,*/}*{png,jpg,jpeg,gif,webp,svg}”,
“/styles/fonts/*”
]
}
}
},
使用准备:{
html:“/index.html”,
选项:{
目标:“”
}
},
usemin:{
html:['/{,*/}*.html'],
css:['/styles/{,*/}*.css'],
选项:{
目录:['']
}
},
imagemin:{
地区:{
档案:[{
是的,
cwd:“/images”,
src:“{,*/}*{png,jpg,jpeg}”,
目标:'/images'
}]
}
},
斯维格明:{
地区:{
档案:[{
是的,
cwd:“/images”,
src:'{,*/}*.svg',,
目标:'/images'
}]
}
},
cssmin:{
//默认情况下,您的'index.html'将处理
//缩小。如果您不希望使用,此选项是预先配置的
//使用最小块。
//地区:{
//档案:{
//“/styles/main.css”:[
//“.tmp/styles/{,*/}*.css”,
//“/styles/{,*/}*.css”
// ]
// }
// }
},
htmlmin:{
地区:{
选项:{
/*removeCommentsFromCDATA:true,
// https://github.com/yeoman/grunt-usemin/issues/44
//拼贴空白:对,
collapseBooleanAttributes:没错,
RemoveAttribute属性:对,
删除和声明:是的,
useShortDoctype:true,
RemovemptyAttributes:没错,
removeOptionalTags:true*/
},
档案:[{
是的,
cwd:“”,
src:['*.html','views/*.html'],
目标:“”
}]
}
},
//将未在其他任务中处理的文件放在此处
副本:{
地区:{
档案:[{
是的,
多特:没错,
cwd:“”,
目标:'',
src:[
“*.{ico,png,txt}”,
“.htaccess”,
“bower_组件/***”,
'images/{,*/}*{gif,webp}',
“样式/字体/*”
]
}, {
是的,
cwd:“.tmp/images”,
目标:'/images',
src:[
'已生成/*'
]
}]
},
风格:{
是的,
cwd:“/styles”,
目标:'.tmp/styles/',
src:“{,*/}*.css”
}
},
并发:{
服务器:[
“咖啡”,
“复制:样式”
],
测试:[
“咖啡”,