【发布时间】:2014-07-04 21:32:00
【问题描述】:
我实际上是在尝试构建一个 gulp,计划做一些与 Web 相关的事情,比如编译 sass、缩小 css、丑化 javascript 等等。但是我真的很难用 sass。
这是我的代码示例:
gulp.task('compile-sass', function() {
gulp.src(buildType+config.path.sass+"/main.sass")
.pipe(compass({
css: 'css',
sass: 'sass'
}))
.pipe(gulp.dest(buildType+config.path.css+"/test"));
});
所以我在这里使用指南针,因为我只有 *.sass 文件而没有 .scss,所以 gulp-sass 对我不起作用。因此,我问是否有人可以给我一个提示,为什么这个任务不起作用。这是我的控制台返回的内容:
[gulp] Starting 'compile-sass'...
[gulp] Finished 'compile-sass' after 6.11 ms
[gulp] You must compile individual stylesheets from the project directory.
events.js:72
throw er; // Unhandled 'error' event
^
[gulp] Error in plugin 'gulp-compass': Compass failed
at Transform.<anonymous> (/Users/myusername/node_modules/gulp-compass/index.js:37:28)
at ChildProcess.<anonymous> (/Users/myusername/node_modules/gulp-compass/lib/compass.js:136:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Socket.<anonymous> (child_process.js:966:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:465:12)
我知道我没有使用任何 config.rb,但有两件事: 1)我没有找到此类文件的示例 2) gulp-compass doc 给出了没有这样一个文件的例子,所以我认为它是可选的
提前致谢。
【问题讨论】:
-
buildType+config.path.sass和buildType+config.path.css的值是多少?它们是从您运行gulp的项目根目录开始的相对路径吗?关于配置,它不是gulp-compass配置,而是compassconfg itself。还有一件事,Compass 只将库添加到 SASS。其中,编译.sass和.scss的能力不是来自Compass,而是来自SASS本身,所以gulp-sass无论如何都应该为你工作。 -
感谢您的快速回答。
buildType+config.path.sass是来自 Json 配置文件的有效字符串,我在同一个 gulpfile 中的其他任务中使用它,它运行良好。当我使用gulp-sass而不是“指南针”时,读取文件时会出现另一个错误([gulp] [gulp-sass] source string:4: error: error reading values after $gray和其他类似的)。我假设 gulp-sass 不支持.sass文件,而只支持.scss。 -
gulp 不关心文件扩展名是什么。它使用了
node-sass解析器。考虑使用gulp-ruby-sass,因为它应该支持 .scss 和 .sass 扩展。然后它可以减少可能的错误以缩小您的问题范围。 -
谢谢@SteveLacy。一切都按预期工作!答案已发布。