![](/img/trans.png)
[英]Watch multiple files with Grunt Bake without compiling all at once
[英]grunt watch not compiling all sass files despite being "watched"
基本上目前我有两个问题似乎无法找到答案。 当我保存我的主要styles.scss
,sass 编译正常,但当我保存_globals.scss
或任何其他 scss 文件时,grunt watch 似乎检测到更改,但它不会编译! 我需要做什么来纠正这个问题?
我的第二个问题是当我在 scss 文件夹中的目录中有一个 scss 文件时,例如: pages/_gallery.scss
(它正在导入到 main styles.scss
),grunt watch 没有看到它,我明白这一点是因为可能是因为我的cwd
路径,但我如何使它更通用?
这是我的 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');
};
要使子目录工作,您需要一个通配模式;
'public/resources/site/scss/**/*.scss'
我认为您的 watch 任务由于newer
而存在缺陷。 Watch 检测到_globals
的变化,但 sass 任务只知道编译主要的styles.scss
。 但是, newer
看到这个文件没有改变,所以它不运行该步骤。
尝试从监视任务列表中删除newer
的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.