1. <small id='Sqyxc'></small><noframes id='Sqyxc'>

    2. <tfoot id='Sqyxc'></tfoot>
    3. <i id='Sqyxc'><tr id='Sqyxc'><dt id='Sqyxc'><q id='Sqyxc'><span id='Sqyxc'><b id='Sqyxc'><form id='Sqyxc'><ins id='Sqyxc'></ins><ul id='Sqyxc'></ul><sub id='Sqyxc'></sub></form><legend id='Sqyxc'></legend><bdo id='Sqyxc'><pre id='Sqyxc'><center id='Sqyxc'></center></pre></bdo></b><th id='Sqyxc'></th></span></q></dt></tr></i><div id='Sqyxc'><tfoot id='Sqyxc'></tfoot><dl id='Sqyxc'><fieldset id='Sqyxc'></fieldset></dl></div>
        <bdo id='Sqyxc'></bdo><ul id='Sqyxc'></ul>

        <legend id='Sqyxc'><style id='Sqyxc'><dir id='Sqyxc'><q id='Sqyxc'></q></dir></style></legend>
      1. 在 gulp 任务中很好地抛出错误

        时间:2023-05-29
          <bdo id='Csohe'></bdo><ul id='Csohe'></ul>

                <small id='Csohe'></small><noframes id='Csohe'>

                <i id='Csohe'><tr id='Csohe'><dt id='Csohe'><q id='Csohe'><span id='Csohe'><b id='Csohe'><form id='Csohe'><ins id='Csohe'></ins><ul id='Csohe'></ul><sub id='Csohe'></sub></form><legend id='Csohe'></legend><bdo id='Csohe'><pre id='Csohe'><center id='Csohe'></center></pre></bdo></b><th id='Csohe'></th></span></q></dt></tr></i><div id='Csohe'><tfoot id='Csohe'></tfoot><dl id='Csohe'><fieldset id='Csohe'></fieldset></dl></div>
                    <tbody id='Csohe'></tbody>
                  <tfoot id='Csohe'></tfoot><legend id='Csohe'><style id='Csohe'><dir id='Csohe'><q id='Csohe'></q></dir></style></legend>
                • 本文介绍了在 gulp 任务中很好地抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在创建一个在某些情况下可能会失败的 gulp 任务.

                  gulp.task('favicon', function () {尝试 {require('child_process').execSync('icotool --version');} 捕捉( e ) {var err = new Error('生成 favicon 需要 Unix bash 和 icotool');抛出错误;}返回 gulp.src('', {read: false}).管道(外壳(['./generate-favicon.sh']));});

                  当通过 gulp 运行我的任务并遇到错误时,该错误将呈现得相当难看.我想以一种方式呈现错误,例如,jslint gulp-util 的 PluginError.

                  它实际上只是在其中创建一个 PluginError 并抛出它,但这似乎不太正确.另一个不太好的解决方案是设置

                  err.showStack = false;

                  至少有更好的错误输出.gulp.task.Error 会很好.

                  解决方案

                  据我所知,从 gulp 中抛出错误并不是很好.但是我发现了这个我曾经为我工作的博客条目.

                  http://gotofritz.net/博客/geekery/how-to-generate-error-in-gulp-task/

                  编辑:gulp-util已弃用.相反,请使用 plugin-error 包.p>

                  我的例子:

                  var gulp = require('gulp');var error = require('plugin-error');gulp.task('部署',函数(cb){if(typeof(specialId) === '未定义') {var err = new PluginError({插件:'部署',消息:'specialId 为空.'});}}

                  I am creating a gulp task which might fail under certain circumstances.

                  gulp.task('favicon', function () {
                    try {
                      require('child_process').execSync('icotool --version');
                    } catch( e ) {
                      var err = new Error( 'Unix bash and icotool required for generating favicon' );
                      throw err;
                    }
                  
                    return gulp.src('', {read: false})
                      .pipe(shell([
                        './generate-favicon.sh'
                      ]));
                  });
                  

                  When running my task via gulp and running into the error, the error will be presented rather ugly. I would like to present the error in a way as it is done by e.g. jslint gulp-util's PluginError.

                  It actually works to just create a PluginError there and throw it but that doesn't seem quite right. Another solution not that nice would be to set

                  err.showStack = false;
                  

                  for at least a little nicer error output. A gulp.task.Error would be nice.

                  解决方案

                  From what I've seen its not great to throw an error from gulp. But I found this blog entry that I used to work for me.

                  http://gotofritz.net/blog/geekery/how-to-generate-error-in-gulp-task/

                  Edit: gulp-util has been deprecated. Instead, use the plugin-error package.

                  My Example:

                  var gulp = require('gulp');
                  var error = require('plugin-error');
                  gulp.task('deploy', function(cb) {
                    if(typeof(specialId) === 'undefined') {
                      var err = new PluginError({
                        plugin: 'deploy',
                        message: 'specialId is empty.'
                      });
                    }
                  }
                  

                  这篇关于在 gulp 任务中很好地抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何连接我的 angular2 应用程序 javascript 文件 下一篇:将html模板文件合并为一个JS文件

                  相关文章

                  最新文章

                    • <bdo id='dF34H'></bdo><ul id='dF34H'></ul>
                    <legend id='dF34H'><style id='dF34H'><dir id='dF34H'><q id='dF34H'></q></dir></style></legend>

                      <small id='dF34H'></small><noframes id='dF34H'>

                      <i id='dF34H'><tr id='dF34H'><dt id='dF34H'><q id='dF34H'><span id='dF34H'><b id='dF34H'><form id='dF34H'><ins id='dF34H'></ins><ul id='dF34H'></ul><sub id='dF34H'></sub></form><legend id='dF34H'></legend><bdo id='dF34H'><pre id='dF34H'><center id='dF34H'></center></pre></bdo></b><th id='dF34H'></th></span></q></dt></tr></i><div id='dF34H'><tfoot id='dF34H'></tfoot><dl id='dF34H'><fieldset id='dF34H'></fieldset></dl></div>

                      <tfoot id='dF34H'></tfoot>