[英]grunt watch not compiling all sass files despite being "watched"
Basically at the moment I have 2 issues that I can't seem to find answers to.基本上目前我有两个问题似乎无法找到答案。 When I save my main
styles.scss
, sass compiles ok, though when I save either _globals.scss
or any other scss file, grunt watch seems to detect the change, but it doesn't compile!当我保存我的主要
styles.scss
,sass 编译正常,但当我保存_globals.scss
或任何其他 scss 文件时,grunt watch 似乎检测到更改,但它不会编译! What would I need to do to rectify this?我需要做什么来纠正这个问题?
My 2nd issue is when I have got a scss file in a directory within the scss folder for example: pages/_gallery.scss
(which is being imported in the main styles.scss
), grunt watch doesn't see it, I understand this is because of probably because of my cwd
path, though how do I make this more generic?我的第二个问题是当我在 scss 文件夹中的目录中有一个 scss 文件时,例如:
pages/_gallery.scss
(它正在导入到 main styles.scss
),grunt watch 没有看到它,我明白这一点是因为可能是因为我的cwd
路径,但我如何使它更通用?
Here is my Gruntfile.js:这是我的 Gruntfile.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
scripts: {
files: ['public/resources/site/js/*.js'],
tasks: ['newer:jshint', 'newer:uglify:dist'],
options: {
spawn: false,
livereload: true,
},
},
sass: {
files: ['public/resources/site/scss/*.scss'],
tasks: ['newer:sass:app'],
options: {
livereload: true
}
},
php:{
files: ['public/index.php'],
options: {
livereload: true
}
}
},
sass: {
app: {
files: [{
expand: true,
cwd: 'public/resources/site/scss/',
src: ['*.scss'],
dest: 'public/resources/site/css/',
ext: '.css'
}]
},
options: {
sourceMap: true,
outputStyle: 'compressed'
}
},
uglify: {
dist: {
options: {
sourceMap: true,
mangle: true
},
files: [{
expand: true,
cwd: 'public/resources/site/js/',
src: ['*.js'],
dest: 'public/resources/site/js/',
ext: '.min.js'
}]
}
},
jshint: {
options: {
force: true
},
files: [
'public/resources/site/js/*.js',
'!public/resources/site/js/*.min.js'
]
},
notify: {
watch: {
options: {
title: 'Tasks Complete',
message: 'Files Processed & Compiled',
}
}
}
});
// Load tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-newer');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-notify');
// Default task(s).
grunt.registerTask('default', []);
grunt.task.run('notify_hooks');
};
To make subdirectories work you need a globbing pattern ;要使子目录工作,您需要一个通配模式;
'public/resources/site/scss/**/*.scss'
I think that your watch task is flawed due to newer
.我认为您的 watch 任务由于
newer
而存在缺陷。 Watch detects a change to _globals
, but the sass task knows only to compile the main styles.scss
. Watch 检测到
_globals
的变化,但 sass 任务只知道编译主要的styles.scss
。 However, newer
sees that this file has not changed, so it does not run the step.但是,
newer
看到这个文件没有改变,所以它不运行该步骤。
Try removing newer
from the watch task list.尝试从监视任务列表中删除
newer
的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.