[英]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.