我在带有 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']);
};