0

我尝试使用 grunt 配置 uncss

我已经安装

npm install grunt-uncss --save-dev
npm install grunt-processhtml --save-dev

配置

uncss: {
    dist: {
        files: { 'dist/css/clean.css': ['index.php'] }
    }
}

最后,我将它们加载并注册一个默认任务,如下所示:

grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-processhtml');

grunt.registerTask('default', ['uncss', 'processhtml']);

结果

当我跑grunt

最后我一直看到:

运行“uncss:dist”(uncss)任务

致命错误:PhantomJS:无法打开关于:空白


更新

我补充说:

processhtml: {

    dist: {

        files: {

            'index.php': ['index.php']
        }
    }
}

运行后仍然报同样的错误grunt

4

2 回答 2

1

如果这是您的所有代码,则您没有引用任何样式表来从中删除代码。你所做的只是告诉 grunt 清理文件应该去哪里,并从 index.php 中删除任何未使用的 css。但是,它不知道 index.php 的样式在哪里,所以它无关...您需要实际配置您的 processhtml 并告诉 uncss 您要清理哪些样式表。

阅读路线的朋友:

grunt-uncss github readme.md

于 2015-05-18T16:56:32.967 回答
0

我的项目有这个问题,解决方案在这里:您需要更新 uncss 模块,记住 grunt-uncss 只是使用 uncss 节点包的一种方式。在我的情况下,我的版本是 0.12.1 并更新该软件包,问题已得到解决。让我知道这是否对您有帮助。

于 2016-09-14T02:24:10.953 回答