GULP-第一次有条件地运行任务,然后始终处于监视状态(完成不是功能)

问题描述 投票:0回答:1

我有RealFaviconGenerator的任务,该任务基于一个文件创建所有图标”]

function generateFavicon(done) {
 return $.realFavicon.generateFavicon({
    masterPicture: 'app/favicon.svg',
    dest: 'app/favicon/',
    iconsPath: '/favicon',
    design: {
      ios: {
        pictureAspect: 'backgroundAndMargin',
        backgroundColor: '#ffffff',
        margin: '14%',
        assets: {
          ios6AndPriorIcons: false,
          ios7AndLaterIcons: false,
          precomposedIcons: false,
          declareOnlyDefaultIcon: true
        }
      },
      desktopBrowser: {},
      windows: {
        pictureAspect: 'noChange',
        backgroundColor: '#ffffff',
        onConflict: 'override',
        assets: {
          windows80Ie10Tile: false,
          windows10Ie11EdgeTiles: {
            small: false,
            medium: true,
            big: false,
            rectangle: false
          }
        }
      },
      androidChrome: {
        pictureAspect: 'noChange',
        themeColor: '#ffffff',
        manifest: {
          display: 'standalone',
          orientation: 'notSet',
          onConflict: 'override',
          declared: true
        },
        assets: {
          legacyIcon: false,
          lowResolutionIcons: false
        }
      },
      safariPinnedTab: {
        pictureAspect: 'blackAndWhite',
        threshold: 57.03125,
        themeColor: '#004c96'
      }
    },
    settings: {
      scalingAlgorithm: 'Mitchell',
      errorOnImageTooSmall: false,
      readmeFile: false,
      htmlCodeFile: false,
      usePathAsIs: false
    },
    markupFile: FAVICON_DATA_FILE
  }, function () {
    done();
  });
}

仅当缺少创建gulp serve任务的收藏夹文件夹时,我才想在运行generateFavicon时运行此任务。

所以我做到了:

serve = series(clean, favicon = (done) => {
    fs.existsSync('app/favicon/') ? done() : generateFavicon();
}, parallel(views, styles, scripts, modernizr, fonts), startAppServer);

通过执行此任务,将创建我需要的所有资产,但是该系列将无法继续:

[09:37:24] Starting 'serve'...
[09:37:24] Starting 'clean'...
[09:37:24] Finished 'clean' after 7.27 ms
[09:37:24] Starting 'favicon'...
[09:37:59] 'favicon' errored after 35 s
[09:37:59] TypeError: done is not a function

现在在目录存在时再次运行gulp serve将使一切正常:

[09:43:51] Starting 'serve'...
[09:43:51] Starting 'clean'...
[09:43:51] Finished 'clean' after 6.99 ms
[09:43:51] Starting 'favicon'...
[09:43:51] Finished 'favicon' after 293 μs
[09:43:51] Starting 'views'...
[09:43:51] Starting 'styles'...
[09:43:51] Starting 'scripts'...
[09:43:51] Starting 'modernizr'...
[09:43:51] Starting 'fonts'...
[09:43:58] Finished 'fonts' after 6.76 s
[09:43:59] Finished 'modernizr' after 7.77 s
[09:44:11] Finished 'scripts' after 19 s
[09:44:11] Finished 'views' after 19 s
[09:44:11] Finished 'styles' after 20 s
[09:44:11] Starting 'startAppServer'...
[Browsersync] Access URLs:
 ---------------------------------------
        Local: http://localhost:9000
    External: http://192.168.13.117:9000
---------------------------------------
        UI: http://localhost:3001
UI External: http://localhost:3001
---------------------------------------
[Browsersync] Serving files from: .tmp
[Browsersync] Serving files from: app

尽管在另一端,从favicon文件更改(并且更改)并且可以正常运行时,我也有一块手表:

watch('app/favicon.svg', generateFavicon);

[09:47:57] Starting 'generateFavicon'...
[09:48:28] Finished 'generateFavicon' after 31 s

我该如何处理错误“完成不是函数?” d

我有来自RealFaviconGenerator的任务,该任务基于单个文件创建所有图标图标:function generateFavicon(done){return $ .realFavicon.generateFavicon({masterPicture:'app / ...

gulp
1个回答
0
投票
您需要在服务任务中将完成传递给您的generateFavicon:
© www.soinside.com 2019 - 2024. All rights reserved.