javascript - TypeError:无法将类作为函数调用
问题描述
我正在构建一个新的 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))
});
解决方案
推荐阅读
- javascript - 在特定日期和时间后使 div id 消失
- ios - 如何调试“LIBPLATFORM 客户端中的错误:尝试递归锁定 os_unfair_lock”崩溃?
- websocket - 如何在应用程序中处理 websockets 数据。在哪里缓冲?
- ios14 - 是否可以本地化 iOS 14“选择更多”对话框显示的 NSPhotoLibraryUsageDescription 字符串?
- python - 如何仅删除数据框中的尾随空列?
- html - 在 Vue3 中使用 Font Awesome 和 Bulma
- grafana - 为什么grafana在不正确的时间段显示值?
- redhat - kinit:在获取默认 ccache 时连接被拒绝
- react-native - 组件重新渲染 onChangeText
- soap - HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“协商”