Gulp build任务执行失败求助:build、copy-css任务未完成,提示未标记异步完成
Hey there, let's tackle that frustrating async completion error you're seeing when running your build task. The issue points straight to your copy-css task failing to properly tell Gulp it's finished, and here's why and how to fix it:
What's Causing the Problem?
Looking at your copy-css task code, you’re calling .pipe(postcss()) without passing any plugins to it. PostCSS requires an array of plugins to execute its workflow, and when you call it empty, it can hang up and fail to send the "task complete" signal back to Gulp. That’s why Gulp thinks the task never finished.
Solution 1: Remove Unused PostCSS Pipe (If You Don’t Need It)
If you aren’t actually using PostCSS for any transformations (like autoprefixing, custom property support, etc.), just strip out the PostCSS line entirely:
gulp.task('copy-css', function () { return gulp.src('src/main/resources/**/*.css') .pipe(production(uglifycss())) .pipe(gulp.dest('target/classes/')); });
Solution 2: Properly Configure PostCSS (If You Do Need It)
If you intended to use PostCSS, pass an empty array (or your actual list of plugins) to postcss() to ensure it runs correctly and signals completion:
// Example with empty array (add your plugins here if needed) gulp.task('copy-css', function () { return gulp.src('src/main/resources/**/*.css') .pipe(postcss([])) // Empty array or list of your PostCSS plugins .pipe(production(uglifycss())) .pipe(gulp.dest('target/classes/')); });
For example, if you wanted to add autoprefixer support, first install it (npm install autoprefixer --save-dev) then update the task:
const autoprefixer = require('autoprefixer'); gulp.task('copy-css', function () { return gulp.src('src/main/resources/**/*.css') .pipe(postcss([autoprefixer()])) .pipe(production(uglifycss())) .pipe(gulp.dest('target/classes/')); });
Verify the Fix
After making either change, run gulp build again. Your copy-css task will now properly signal completion, and the entire build process will finish without errors.
内容的提问来源于stack exchange,提问作者9527 snl

