如何在表的旁边工作时发出咕gr的发声任务? [英] How to get grunt serve task working alongside watch?
问题描述
我最近已经安装并启动并运行它,但是我似乎无法使其与监视任务同时运行?在我的grunt文件中,如果在监视之前注册了服务任务,则服务器会启动,但监视任务不会...,反之亦然.这是服务包,并且我正在使用Im和附带的Grunt文件:
I've recently installed and got a it up and running but I can't seem to get it running concurrently with my watch task? In my grunt file, if register the serve task before watch, the server spins up and but the watch task doesn't....and vice versa. This is the serve package and Im using and Grunt file attached:
https://www.npmjs.com/package/grunt-serve
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'js/libs/*.js', // All JS in the libs folder
'js/global.js' // This specific file
],
dest: 'js/build/production.js',
}
},
uglify: {
options: {
mangle: false
},
my_target: {
files: {
'js/build/production.min.js': ['js/build/production.js']
}
}
},
imagemin: {
dynamic: {
files: [{
expand: true,
cwd: 'images/',
src: ['**/*.{png,jpg,gif}'],
dest: 'images/build/'
}]
}
},
sass: {
//options: {
// style: 'compressed'
//},
dist: {
files: [{
expand: true,
cwd: 'css',
src: ['*.scss'],
dest: 'css/build/',
ext: '.css'
}]
}
},
serve: {
options: {
port: 9000
}
},
watch: {
options: {
livereload: true,
},
css: {
files: ['css/**/*.scss'],
tasks: ['sass'],
options: {
spawn: false,
}
},
scripts: {
files: ['js/*.js'],
tasks: ['concat', 'uglify'],
options: {
spawn: false,
},
}
}
});
// Load all Grunt tasks automatically wihtout having to enter manaually
require('load-grunt-tasks')(grunt);
grunt.registerTask(
'default',
[
'concat',
'uglify',
'sass',
'serve',
'watch'
]
);
};
推荐答案
Grunt serve
和grunt watch
都是阻止任务.您可以使用 grunt-concurrent
这样的插件在单独的线程中同时运行两者. https://github.com/sindresorhus/grunt-concurrent
Grunt serve
and grunt watch
are both blocking tasks. You can use a plugin like grunt-concurrent
to run both at the same time in separate threads. https://github.com/sindresorhus/grunt-concurrent
concurrent: {
target1: ['serve', 'watch'],
}
//aslo update your default task
grunt.registerTask(
'default',
[
'concat',
'uglify',
'sass',
'concurrent:target1'
]
);
此外,您还可以使用grunt-concurrent
并行运行uglify和sass任务,这可以缩短构建时间.
Additionally you could also use grunt-concurrent
to run your uglify and sass tasks in parallel which may improve build time.
这篇关于如何在表的旁边工作时发出咕gr的发声任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!