javascript - 使用 purgecss 安全列表选项会给出 UnhandledPromiseRejectionWarning
问题描述
我正在使用 purgecss 从我的项目中删除不必要的 css。
purgecss --css static/css/*.chunk.css --content index.html static/js/*.chunk.js --output static/css/
但不幸的是,它也删除了一些我需要的 css 类,因此参考了我尝试使用安全列表选项的文档来制作一些像这样的例外
purgecss --safelist [modal] --css static/css/*.chunk.css --content index.html static/js/*.chunk.js --output static/css/
它给出了以这个结尾的长错误
at U.evaluateRule (/usr/local/lib/node_modules/purgecss/lib/purgecss.js:1:6585)
at /usr/local/lib/node_modules/purgecss/lib/purgecss.js:1:9659
(node:10023) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 593)
解决方案
让它使用替代方法工作,即使用配置文件purgecss.config.js
。
module.exports = {
content: ['build/index.html', 'build/static/js/*.chunk.js'],
css: ['build/static/css/*.chunk.css'],
output: 'build/static/css/',
safelist: [/^modal-/]
}
在package.json
文件中
"scripts": {
"postbuild": "purgecss --config ./purgecss.config.js",
.....other scripts
},
推荐阅读
- ffmpeg - ffmpeg 在我的这行代码中添加循环
- c - 接受调用阻塞线程终止
- ruby-on-rails - 显示页面 has_many has_one 关联上的未初始化常量 ruby
- python - 在 Django 中处理多种类型的用户
- javascript - 如何在不创建新 obj 的情况下连接到数组对象?
- perl - 如何在不考虑查询参数排序的情况下测试 URI 相等性
- python - 如何永久删除密集层中节点之间的连接
- wordpress - NGINX + 乘客 w/ Rails + WordPress 永久链接
- c++ - 输入 trait 以接收 T::value_type 如果存在,否则为 T
- web-services - 有人可以帮我从日本网络服务中解码这个网络服务响应吗?