最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Gulp JS 任务输出 NodeError: Callback called multiple times

网站源码admin39浏览0评论

Gulp JS 任务输出 NodeError: Callback called multiple times

Gulp JS 任务输出 NodeError: Callback called multiple times

Gulp JS 任务输出 NodeError: Callback called multiple times

我有五个 Gulp JS 任务,其中一个名为

js_bundle
的任务给我一个错误。报错如下:

NodeError: 多次调用回调函数

这是我的

gulpfile.js

const { src, dest, parallel , series , watch } = require('gulp');
// Gulp Sass
const sass = require('gulp-sass')(require('sass'));
const fileinclude = require('gulp-file-include');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const minify = require('gulp-minifier');
const strip = require('gulp-strip-comments');
const rtlcss = require('gulp-rtlcss');
const rename = require('gulp-rename');

// sasspiler = require('node-sass'); // no-need for gulp-sass v5+

var node_path = '../../../';


function html(cb) {
  src('html/src/**')
  .pipe(dest('html/dist/'));

  cb();
}

function scss(cb) {
  src(['scss/*.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(dest('assets/dist/css'));

  src(['scss/*.scss', '!scss/style-email.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(rtlcss())
  .pipe(rename({ suffix: '.rtl' }))
  .pipe(dest('assets/dist/css'));

  // EDITORS
  src(['scss/editors/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(dest('assets/dist/css/editors'));

  src(['scss/editors/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(rtlcss())
  .pipe(rename({ suffix: '.rtl' }))
  .pipe(dest('assets/dist/css/editors'));

  src(['scss/libs/*.scss'])
  // .pipe(sourcemaps.init())                                           // If you want generate source map.
  .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))   // remove {outputStyle: 'compressed'} from saas() if do not want to minify css
  // .pipe(sourcemaps.write('./'))                                      // If you want generate source map.
  .pipe(dest('assets/dist/css/libs'));

  // SKINS
  src(['scss/skins/*.scss'])
  // .pipe(sourcemaps.init())               // If you want generate source map.
  .pipe(sass().on('error', sass.logError))  // uses {outputStyle: 'compressed'} in saas() for minify css
  // .pipe(sourcemaps.write('./'))          // If you want generate source map.
  .pipe(dest('assets/dist/css/skins'));

  cb();
}

function js_scripts(cb) {
  src(['assets/src/js/*.js','!assets/src/js/bundle.js'])
  // .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js'));

  src(['assets/src/js/charts/*.js'])
  .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js/charts'));

  src(['assets/src/js/apps/*.js'])
  // .pipe(uglify())                        // If you minify the code.
  .pipe(dest('assets/dist/js/apps'));

  cb();
}

/* The task giving me the error */
function js_bundle(cb) {
  src('assets/src/js/bundle.js')
  .pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
  }))
  .pipe(strip())
  .pipe(minify({ minify: true, minifyJS: { sourceMap: false } }))     // Disable, if you dont want to minify bundle file.
  .pipe(dest('assets/dist/js'));

  src(['assets/src/js/libs/**', '!assets/src/js/libs/editors/skins/**'])
  .pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
  }))
  .pipe(strip())
  .pipe(minify({ minify: true, minifyJS: { sourceMap: false } }))     // Disable, if you dont want to minify bundle file.
  .pipe(dest('assets/dist/js/libs'));

  src('assets/src/js/libs/editors/skins/**').pipe(dest('assets/dist/js/libs/editors/skins'));

  cb();
}

function assets(cb){
  src(['assets/src/**', '!assets/src/js/**', '!assets/src/css/**'])
  .pipe(dest('assets/dist/'));

  cb();
}

exports.build = series(html, scss, js_scripts, /* The task giving me the error */ js_bundle, assets);

exports.develop = function() {
    watch(['scss/*.scss','scss/**'], scss)
    watch(['html/src/*.html','html/src/**/*.html'], html)
    watch(['assets/src/**'], assets)
    watch(['assets/src/js/*.js','assets/src/js/charts/*.js', 'assets/src/js/apps/*.js', '!assets/src/js/bundle.js'], js_scripts)
    watch(['assets/src/js/libs/**','assets/src/js/bundle.js'], js_bundle)
};

这里是导致错误的代码片段:

.pipe(fileinclude({
    prefix: '@@',
    basepath: '@file',
    context: { build: 'dist', nodeRoot: node_path }
}))

我试过以下方法:

  • 更新了我怀疑导致错误的
    gulp_file_include
    插件。
  • 控制台记录了前后的函数,检查回调函数是否重复,但无济于事。
  • 删除了
    strip
    minify
    函数,但仍然出现错误,这证实了我对
    gulp_file_include
    插件导致错误的怀疑。
  • 检查了这个 SO 问题如何修复多次调用的回调函数但没有问题作者所说的导致问题的
    gulp-imagemin
    插件

感谢任何帮助,再见

回答如下:
发布评论

评论列表(0)

  1. 暂无评论