首页 > 解决方案 > 使用 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)

标签: javascriptnode.jsreactjsdebuggingcss-purge

解决方案


让它使用替代方法工作,即使用配置文件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
 },

推荐阅读