我有一个非常基本的gulp任务,我想处理一个Stylus CSS文件(.styl)。这是gulpfile中的任务:
const gulp = require("gulp");
const gulpIf = require("gulp-if");
const useref = require("gulp-useref");
const stylus = require("gulp-stylus");
const cssnano = require("gulp-cssnano");
gulp.task("default", function(){
return gulp.src("*.htm")
.pipe(useref())
.pipe(gulpIf("*.css", stylus()))
.pipe(gulp.dest("dist"))
});这是html的特定部分。
<!--build:css css/style.min.css -->
<link rel="stylesheet" href="style.styl">
<!-- endbuild -->无论出于什么原因,Stylus文件都不会被处理,并且在没有任何处理的情况下被复制到css/style.min.css。
更奇怪的是,如果我将CSS格式化为普通的CSS文件,并将"stylus()“替换为" cssnano ()",cssnano就可以很好地工作并缩小文件。当作为自己的任务运行时,手写笔在useref和gulpIf之外工作得很好,但我更希望这样使用它。
发布于 2017-03-13 21:41:22
您是否可以尝试为useref指定它可以找到资产的根路径:
options.searchPath
类型:字符串或数组默认值:无
指定要搜索资源文件的位置(相对于当前工作目录)。可以是字符串或字符串数组。
你的任务
gulp.task("default", function(){
return gulp.src("*.htm")
.pipe(useref({
searchPath: 'assets_path_here'
}))
.pipe(gulpIf("*.css", stylus()))
.pipe(gulp.dest("dist"))
});我个人只是设置了包含整个应用程序的根目录的路径。
https://stackoverflow.com/questions/42763108
复制相似问题