0

我在带有 WordPress 网站的 MAMP 上使用 grunt-uncss。我已经把我所有的 css 文件合并到一个文件中。

结果:一个 url 需要 40 分钟才能完成。那不可能是有效的。此外,uncss 只是吐出与它开始时相同的 css。

许多错误是“ReferenceError:找不到变量:jQuery”,但它就像 PhantomJS/UnCSS 试图解析内联 javascript?

以下是其他一些:

SyntaxError: 意外的标记 '%'

local:193 in setContent :2 SyntaxError: Invalid escape in identifier: '\'

local:427 in setContent :2 SyntaxError: Unexpected token '<'

local:891 in setContent :2 SyntaxError: Unexpected token ','

我尝试了不同的方法,包括为 jQuery 添加更多时间(超时)来加载等,以及过去七个小时的谷歌搜索。我很确定问题出在 PhantomJS 上,但对它不太熟悉。寻求帮助

这是我的 gruntfile

module.exports = function(grunt) {

   require('time-grunt')(grunt);

  // 1. All configuration goes here 
     grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

      jshint: {
        all: ['gruntfile.js']
      },

  exec: {
      get_grunt_sitemap: {
         command: 'curl --silent --output sitemap.json http://localhost:8888/applus/?show_sitemap'
      }
    },

  uncss: {
     dist: {
        options: {
      ignore       : [
                /expanded/,
                /js/,
                /wp-/,
                /align/,
                /admin-bar/,
                /\w\.in/,
                ".fade",
                ".collapse",
                ".collapsing",
                /(#|\.)navbar(\-[a-zA-Z]+)?/,
                /(#|\.)dropdown(\-[a-zA-Z]+)?/,
                /(#|\.)(open)/,
                ".modal",
                ".modal.fade.in",
                ".modal-dialog",
                ".modal-document",
                ".modal-scrollbar-measure",
                ".modal-backdrop.fade",
                ".modal-backdrop.in",
                ".modal.fade.modal-dialog",
                ".modal.in.modal-dialog",
                ".modal-open",
                ".in",
                ".modal-backdrop",
                '.hidden-xs', 
                'hidden-sm'

                ],
      stylesheets  : ['wp-content/themes/vest/css/consolidated.css'],
      ignoreSheets : [/fonts.googleapis/],
      urls         : [], //Overwritten in load_sitemap_and_uncss task
    },
    files: {
      'wp-content/themes/vest/style.test.css': ['**/*.php']
    }
  }
}

  });

// 3. Where we tell Grunt we plan to use this plug-in.
      grunt.loadNpmTasks('grunt-contrib-jshint');
      grunt.loadNpmTasks('grunt-exec');   
      grunt.loadNpmTasks('grunt-uncss');

// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
      grunt.registerTask('load_sitemap_json', function() {
      var sitemap_urls = grunt.file.readJSON('./sitemap.json');
      grunt.config.set('uncss.dist.options.urls', sitemap_urls);
 });

  grunt.registerTask('deploy'['jshint','exec:get_grunt_sitemap','load_sitemap_json','uncss:dist']);  
 };
4

1 回答 1

0

好的,所以回答我自己的问题。似乎我错误地配置了 MAMP 的样式表和文件 url?一旦我创建了文件的硬链接。除了那些由用户交互触发的事件之外,一切似乎都正常工作。

以下是我所做的更改:

stylesheets  : ['http://localhost:8888/wp-content/themes/vest/css/consolidated.css'],



files: [{
                nonull: true,
                src: ['http://localhost:8888/applus'],
                dest: '/Applications/MAMP/htdocs/applus/wp-content/themes/cannavest/uncss-style.css'
    }]

提示:对于 WordPress,您应该查看您的页面源代码,然后按照它们在页面源代码中显示的特定顺序将所有 css 复制到一个 css 文件中(因此 - 合并.css)。这样,您可以保持与完成的站点一样多的 css 继承。

于 2016-11-28T18:28:04.623 回答