BundlerMinifier
BundlerMinifier copied to clipboard
Gulp: AssertionError [ERR_ASSERTION]: Task function must be specified
Installed product versions
- Visual Studio: 2019 enterprise
- This extension: 2.8.396 & 3.2.447
Description
I used the "Convert to Gulp" option. The gulp file generated isn't compatible with the version of Gulp being installed by the extension.
Steps to recreate
- take an existing bundleconfig.json
- open the context menu and convert to gulp
- gulp@latest is installed
- The gulp file won't run
Current behavior
The gulp file seems to be meant to use gulp@^3.
AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\TFS\houwingj\**\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\TFS\houwingj\**\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\TFS\houwingj\Cumulus\Dev03\Base2\Generic\Portal.Web\gulpfile.js:18:6)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at requireOrImport (C:\Users\reed\AppData\Roaming\npm\node_modules\gulp\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
Expected behavior
Either:
- The right version of gulp is loaded.
- Or the gulp file works with gulp 4.
See also: https://codeburst.io/switching-to-gulp-4-0-271ae63530c0
This seems to do the trick, though it's still far from the ideal syntax:
"use strict";
var gulp = require("gulp"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
htmlmin = require("gulp-htmlmin"),
merge = require("merge-stream"),
del = require("del"),
bundleconfig = require("./bundleconfig.json"),
sourcemaps = require("gulp-sourcemaps"),
uglifyes = require('uglify-es'),
composer = require('gulp-uglify/composer'),
uglify = composer(uglifyes, console);
var regex = {
css: /\.css$/,
html: /\.(html|htm)$/,
js: /\.js$/
};
function getBundles(regexPattern) {
return bundleconfig.filter(function (bundle) {
return regexPattern.test(bundle.outputFileName);
});
}
gulp.task("minjs", gulp.series(async function () {
var tasks = getBundles(regex.js).map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(sourcemaps.init())
.pipe(concat(bundle.outputFileName))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest("."));
});
merge(tasks);
}));
gulp.task("mincss", gulp.series(async function () {
var tasks = getBundles(regex.css).map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(concat(bundle.outputFileName))
.pipe(cssmin())
.pipe(gulp.dest("."));
});
merge(tasks);
}));
gulp.task("min", gulp.series("minjs", "mincss"));
gulp.task("clean", gulp.series(async function () {
var files = bundleconfig.map(function (bundle) {
return bundle.outputFileName;
});
del(files);
}));
gulp.task("watch", gulp.series(async function () {
getBundles(regex.js).forEach(function (bundle) {
gulp.watch(bundle.inputFiles, gulp.series("minjs"));
});
getBundles(regex.css).forEach(function (bundle) {
gulp.watch(bundle.inputFiles, gulp.series("mincss"));
});
}));