首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gulp 'TypeError‘当与gulp if一起使用时未定义

gulp 'TypeError‘当与gulp if一起使用时未定义
EN

Stack Overflow用户
提问于 2015-04-02 10:59:11
回答 1查看 1K关注 0票数 1

我开始喜欢吞咽,但我一直有太多的神秘错误,很难找到,最后,我工作为我的gulpfile.js,而不是做我的工作。

无论如何,我以前尝试过gulp-uncss,在gulp-useref之外,因此在gulp-if之外,但是最后我的gulpfile.js太笨重了,无法读懂。现在它是可读的,但它不能工作。赫雷。

代码语言:javascript
复制
var p = require('gulp-load-plugins')();

gulp.task('html', function () {
    var assets = p.useref.assets();

    gulp.src('*.html')
        .pipe(assets)
        .pipe(p.if('*.js', p.uglify()))
        .pipe(p.if('*.css', p.uncss()))
        .pipe(assets.restore())
        .pipe(p.useref())
        .pipe(gulp.dest(build_folder))
        .pipe(p.size());
});

这会产生这样的结果:

代码语言:javascript
复制
[12:47:53] /long/path/web $ gulp html
[12:48:06] Using gulpfile /long/path/web/gulpfile.js
[12:48:06] Starting 'html'...
[12:48:07] 'html' errored after 507 ms
[12:48:07] TypeError: Cannot set property 'ignoreSheets' of undefined
    at Object.module.exports (/long/path/web/node_modules/gulp-uncss/index.js:14:26)
    at Gulp.<anonymous> (/long/path/web/gulpfile.js:45:31)
    at module.exports (/long/path/web/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/long/path/web/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
    at node.js:814:3
[12:48:12] /long/path/web $ 

在我的工作流程中,Uncss是至关重要的,我无法破解这里的问题。有线索吗?

编辑:这是/long/path/web/node_modules/gulp-uncss/index.js中的内容,直到第14行

代码语言:javascript
复制
'use strict';

var uncss       = require('uncss'),
    gutil       = require('gulp-util'),
    assign      = require('object-assign'),
    transform   = require('stream').Transform,

    PLUGIN_NAME = 'gulp-uncss';

module.exports = function(options) {
    var stream = new transform({ objectMode: true });

    // Ignore stylesheets in the HTML files; only use those from the stream
    options.ignoreSheets = [/\s*/];
EN

回答 1

Stack Overflow用户

发布于 2015-04-10 18:31:54

那么,您摘录的gulp-uncss/index.js状态是,它不能处理未定义的options参数--它不在您的you文件中:

代码语言:javascript
复制
.pipe(p.if('*.css',
  p.uncss({
    html: [ '*.html' ] // html files to check for styles to keep
  })
))

文档还声明,html是必需的选项属性:Npmjs.com/package/gulp uncss#html

类型:Array|String必需值。 一个数组,它可以包含相对于您的gulpfile.js的文件数组,也可以包含URL。请注意,如果要在这里传递URL,则任务将需要更长时间才能完成。如果您想直接将一些HTML传递到任务中,您可以在这里将其指定为字符串。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29411271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档