我最近安装并运行了它,但我似乎无法让它与我的监视任务同时运行?在我的grunt文件中,如果在观察之前注册了服务任务,则服务器会旋转,但是监视任务不会....反之亦然。这是服务包和Im使用和附加的Grunt文件:
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'
]
);
};
答案 0 :(得分:2)
Grunt <header>
</header>
<p>
More episodes in this series
</p>
<br/>
<p>
HTML5 & CSS3 Fundamentals: Development for Absolute Beginners Creating Tables - 09 Creating Tables - 09 13:00
<br>
<br/>
</p>
<div class='embed-container'><iframe src='https://www.youtube.com/embed//iLEGE7k9FD4' frameborder='0' allowfullscreen></iframe></div>
和grunt serve
都是阻止任务。您可以使用grunt-concurrent
之类的插件在不同的线程中同时运行这两个插件。 https://github.com/sindresorhus/grunt-concurrent
watch
此外,您还可以使用concurrent: {
target1: ['serve', 'watch'],
}
//aslo update your default task
grunt.registerTask(
'default',
[
'concat',
'uglify',
'sass',
'concurrent:target1'
]
);
并行运行uglify和sass任务,这可能会缩短构建时间。