我正在构建一个新的 gulpfile,其中一项任务是使用 purgecss
但是,每次我运行任务时都会收到此错误。
TypeError: Cannot call a class as a function
我不明白为什么会发生这种情况,谷歌搜索对我没有帮助。Javascript 对我来说不是一个强大的领域。
吞咽任务。
/**
* Custom PurgeCSS Extractor
* https://gist.github.com/taylorbryant/91fc05b12472a88a8b6494f610647cd4
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
// purge task
gulp.task("purge", async () => {
return gulp.src(pkg.paths.dist.css + '*.css')
.pipe($.purgecss({
content: [pkg.paths.templates + "/**/*.{html,htm,twig}", pkg.paths.templates + "/**/**/*.{html,htm,twig}", pkg.paths.templates + "*.{html,htm,twig}"],
extractors: [{
extractor: TailwindExtractor,
extensions: ["html", "htm", "twig"]
}]
}))
.pipe($.if(["*.css", "!*.purge.css"],
$.rename({
suffix: ".purge"
})
))
.pipe(gulp.dest(pkg.paths.dist.css))
});
// end purge task
感谢你的帮助。
编辑- 切换到一个简化的任务,但仍然得到同样的错误
/**
* Custom PurgeCSS Extractor
* https://gist.github.com/taylorbryant/91fc05b12472a88a8b6494f610647cd4
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
// purge task
gulp.task("purge", async () => {
$.fancylog.info("-> purging unused css");
return gulp.src(pkg.paths.dist.css + '*.css')
.pipe($.plumber({ errorHandler: onError }))
.pipe(
$.purgecss({
content: [pkg.paths.templates + "*.{html,htm,twig}"]
})
)
.pipe(gulp.dest(pkg.paths.dist.css))
});