我正在编写一个node.js程序,它将查看一个充满大量(300-s)数量的scss项目的目录.将配置Grunt-watch(通过节点模块或单独运行,无论运行什么),以便每当更改scss文件时,它将使用罗盘编译,输出文件移动到单独的目录,例如:
./1234/style.scss被更改>> grunt-watch运行grunt-compass >> /foo/bar/baz/1234/style.css更新
文件所在的项目目录显然非常重要(如果grunt-compass将所有已编译的文件发送到同一目录,它们将混乱且无法使用,并且grunt自动化将是无目的的).我命令确保所有文件都路由到正确的位置,每次更新css文件时,我都会动态更改grunt-compass设置.
示例gruntfile:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
files: './*/*.scss',
tasks: ['compass']
},
compass: {
origin:{
options: {
//temportary settings to be changed later
sassDir: './',
cssDir: './bar',
specify: './foo.scss'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.event.on('watch', function(action, filepath, target) {
var path = require('path');
grunt.log.writeln(target + ': ' + filepath + ' might have ' + action);
var siteDirectory = path.dirname(filepath);
//changes sass directory to that of the changed file
var …Run Code Online (Sandbox Code Playgroud)