javascript - 尝试使用 grunt uncss 删除一些 css

标签 javascript css node.js gruntjs

我继承了一个网站,其中包含几个巨大的 css 文件,使用 Firefox 中的 DUst-Me Selector 进行分析后,我返回了将近 2000 个未使用的样式。

要删除它们,我正在尝试使用 grunt uncss,问题是我收到以下错误:

grunt uncss
Running "uncss:dist" (uncss) task
Fatal error: uncss/node_modules/css: missing '}' near line 2429:5
 ->     .mobile-hidden {

这些是我的配置文件

package.json

{
  "name": "tappr-registration",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-copy": "^0.7.0",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-nodeunit": "~0.4.1",
    "grunt-contrib-uglify": "^0.6.0",
    "grunt-processhtml": "^0.3.3",
    "grunt-uncss": "^0.3.7"
     }
}

Gruntfile.js

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uncss: {
        dist: {
            options: {
                media: ['min-width'],
                timeout: 1000,
                htmlroot: 'public_html',
                report: 'max'
            },
            files: {
                'dist/clean.css': ['public_html/index.php',     'public_html/page_2.html', 'public_html/page_3.html']
            }
        }
    }
});

// Load the plugin that provides the "uncss" task.
grunt.loadNpmTasks('grunt-uncss');
grunt.loadNpmTasks('grunt-processhtml');

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

现在,我最好的猜测是我收到此错误是因为我以错误的方式指定了要包含的媒体查询,但我还没有找到一些关于 uncss 如何需要该选项的合适文档。

我已经尝试取消选项。

有人有好的建议吗?

最佳答案

信不信由你,问题是由评论引起的:

<!-- ----- Responsive 34.2857142857em ------>

之后我将它们移除,一切正常,我可以说这是非常需要的。

Running "uncss:dist" (uncss) task
File cleancss/tidy.css created: 229.48 kB → 25.98 kB

:)

关于javascript - 尝试使用 grunt uncss 删除一些 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27163905/

相关文章:

javascript - Mongoose - 链接 promise

node.js - 将 Typescript 与 Nodejs 结合使用 - 找不到 index.d.ts

javascript - WebRTC 硬编码连接(无服务器)

javascript - 用户的文本输入 - 移动前缀应限制输入的数字数量。

javascript - ngFor调用函数Angular2

javascript - 使用 Javascript 隐藏表格行

javascript - 无法在 materialize.css 中使用 javascript 更改按钮颜色

node.js - 监听附加端口 Microsoft Azure Nodejs

父元素兄弟元素的子元素的 CSS 选择器

javascript - 有没有办法从 csv 中获取文本格式?