【发布时间】:2014-06-02 19:35:09
【问题描述】:
我正在尝试设置 Grunt 以在使用 Express 的简单项目中进行更改(使用 grunt-contrib-watch)时编译 sass。我的 gruntfile 有一个“服务器”任务,我用它来运行我的应用程序;此任务编译 sass 并运行应用程序。
启动服务器时sass的初始编译工作正常。但是,当应用程序运行时检测到更改并且任务似乎开始但似乎从未完成。 以下是我的输出副本:
Running "sass:dist" (sass) task
File public/stylesheets/main.css created.
Running "concurrent:main" (concurrent) task
Running "watch" task
Waiting...Running "nodemon:main" (nodemon) task
2 Jun 19:55:25 - [nodemon] v0.7.10
2 Jun 19:55:25 - [nodemon] to restart at any time, enter `rs`
2 Jun 19:55:25 - [nodemon] watching: C:\Development\grunt-test
2 Jun 19:55:25 - [nodemon] starting `node app.js`
OK
>> File "assets\stylesheets\main.scss" changed.
Running "sass:dist" (sass) task
sass 任务永远不会完成。这似乎只发生在我运行“服务器”任务时,如果我运行“监视”任务它可以正常工作。
这是我的 Gruntfile.js,它重现了该问题:
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: [{
expand: true,
cwd: 'assets/stylesheets',
src: ['*.scss'],
dest: 'public/stylesheets',
ext: '.css'
}]
}
},
nodemon: {
main: {}
},
watch: {
scss: {
files: 'assets/stylesheets/**/*',
tasks: ['compile']
}
},
concurrent: {
main: {
tasks: ['nodemon', 'watch'],
options: {
logConcurrentOutput: true
}
}
}
});
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.registerTask('compile', ['sass']);
grunt.registerTask('server', ['compile', 'concurrent']);
};
这是我的 package.json 文件:
{
"name": "grunt-test",
"description": "grunt-test",
"version": "0.0.1",
"private": true,
"main": "app.js",
"dependencies": {
"express": "4.x",
"debug": "0.8.1"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.5.3",
"grunt-nodemon": "^0.1.2",
"grunt-concurrent": "^0.4.3",
"grunt-contrib-sass": "^0.7.3"
}
}
任何帮助将不胜感激。
【问题讨论】:
标签: javascript node.js gruntjs grunt-contrib-watch