我目前正在关注我的sass文件中的任何更改:['_ / components / sass / * .scss']
当我运行grunt watch(通过具有管理员权限的Node.js终端)时,一切似乎都正常。
如果我对.scss文件进行了任何更改,则会出现以下错误:
File "_\components\sass\styles.scss" changed.
Running "compass:dev" (compass) task
Warning: Command failed: C:\Windows\system32\cmd.exe /s /c "compass.bat --version"
The command "compass.bat" is either spelled incorctly or cannot be found.
Use --force to continue.
Aborted due to warnings.
Completed in 3.510s at Mon Aug 24 2015 13:15:13 GMT+0200 (Mitteleuropäische Somm
erzeit) - Waiting...
正如您所看到的,Grunt Watch可以正常工作。它对我的.scss文件进行了更改,但是当它尝试执行'compass:dev'时,它会尝试调用“compass.bat --version”。我想到的是,compass.bat的正确路径/ cmd命令应为:
C:\ Ruby22-x64 \ bin \ compass.bat --version
所以我怀疑这是一些PATH问题?
如何让这个程序基本上运行这个命令:
C:\Windows\system32\cmd.exe /s /c "C:\Ruby22-x64\bin\compass.bat --version"
而不是它(它目前正在做):
C:\Windows\system32\cmd.exe /s /c "compass.bat --version"
这是我的gruntfile.js:
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.initConfig({
uglify: {
my_target: {
files:{
'_/js/script.js' : ['_/components/js/*.js']
}//files
} //my_targer
}, //uglify
compass: {
dev: {
options: {
config: 'config.rb'
} //options
}// dev
}, //compass
watch: {
options: { livereload: true },
scripts: {
files: ['_/components/js/*.js'],
tasks: ['uglify']
}, //scripts
sass: {
files: ['_/components/sass/*.scss'],
tasks: ['compass:dev']
}, //sass
html : {
files: ['*.html'],
} //html
} //watch
}) //initConfig
grunt.registerTask('default', 'watch');
} //exports
这是我的config.rb文件:
css_dir = '_/css'
sass_dir = '_/components/sass'
javascripts_dir = '_/js'
output_style = :nested
这是我的package.json文件:
{
"name" : "Lorum",
"version" : "0.0.1",
"dependencies" : {
"grunt": "~0.4.5",
"grunt-contrib-watch" : "~0.6.1",
"grunt-contrib-compass" : "~1.0.3",
"grunt-contrib-uglify" : "~0.9.1",
"matchdep" : "~0.3.0 "
}
}
其他环境变量:
答案 0 :(得分:8)
I faced the same issue (windows 7 64 bits) and I solved by installing ruby and then the compass gem.
Depending on your system (I'm on windows too), you can download ruby here:
http://rubyinstaller.org/downloads/
Then don't forget to set up the environment variables on windows I think you can do that directly from the installer, but also from Computer -> Control Panel -> Edit Environment Variables. Then on System Variables, add to the Path variable the ruby path, (I did that on http://i.stack.imgur.com/928Y7.png).
Finally open a CMD terminal and write:
gem install compass
Now grunt should be working well:
grunt serve
Running "compass:server" (compass) task
directory .tmp/styles
write .tmp/styles/main.css (0.096s)
write .tmp/styles/main.css.map
Done, without errors.
I hope that helps, regards, Jose