[英]Grunt 'watch' command not working
When I run the grunt watch
task in my terminal, it doesn't seem to be picking up any changes when I modify files. 当我在终端中运行grunt watch
任务时,修改文件时似乎没有任何变化。
I'm not sure if it's my file structure or the configuration in my Gruntfile.js
. 我不确定是我的文件结构还是Gruntfile.js
的配置。 Can anyone let me know what I have done wrong? 谁能让我知道我做错了什么?
sass: {
dist: {
options: {
style: 'compressed',
require: 'susy'
},
files: {
'app/styles/css/main.css': 'app/styles/sass/main.scss'
}
}
},
css: {
files: ['css/*.scss'],
tasks: ['sass'],
options: {
spawn: false,
}
},
watch: {
css: {
files: 'app/styles/sass/*.scss',
tasks: ['sass'],
options: {
livereload: true,
},
}
}
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-sprite-generator');
grunt.registerTask('watchfiles', ['sass', 'watch' ]);
Assuming you want watch to listen for changes to the .scss files in the atoms subdir, in your watch css task config change files: 'app/styles/sass/*.scss'
to files: 'app/styles/sass/**/*.scss'
假设您希望手表侦听files: 'app/styles/sass/*.scss'
files: 'app/styles/sass/**/*.scss'
更改,请在手表css任务配置更改files: 'app/styles/sass/*.scss'
更改为files: 'app/styles/sass/**/*.scss'
Right now you are only watching files with the extension .scss which are also immediate children of your sass directory. 现在,您只在查看扩展名为.scss的文件,这些文件也是sass目录的直接子级。 Adding the two asterisks **/*.scss
tells grunt-contrib-watch that you want to watch all of the files with the exention .scss in the sass dirs subdirs recursively. 添加两个星号**/*.scss
告诉grunt-contrib-watch您想递归地查看sass dirs子目录中带有.scss扩展名的所有文件。
The suggestion in the comments under you question to create a task called watchfiles
is not a good one, in my opinion. 我认为,在您提出问题的评论中,建议创建一个名为watchfiles
的任务不是一个好建议。 That suggestion is to promote task naming which is overly generic and not descriptive of what the task does, and creates an extra layer which is simply unnecessary. 该建议是为了促进过于笼统的任务命名,而不是描述任务的功能,并创建一个多余的层,这根本是不必要的。
To eliminate any other layers, which add uncertainty, when testing whether this works or not, invoke the watch:css
task directly by running the command grunt watch:css
in the same directory as your Gruntfile.js
, make changes, and observe results. 要消除任何其他增加不确定性的层,在测试是否Gruntfile.js
,请通过在与Gruntfile.js
相同的目录中运行grunt watch:css
命令直接调用watch:css
任务,进行更改并观察结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.