能否在WordPress中使用gulp-uncss? 如果可以,那么使其工作的步骤是什么?
//Include Gulp
var gulp = require('gulp');
//Include plugins
var uncss = require('gulp-uncss');
//Rename is included to rename the uncssed file
var rename = require('gulp-rename');
//Uncss task
gulp.task('uncss', function() {
//Where the bloated CSS lives
gulp.src('lib/bootstrap/css/bootstrap.min.css')
.pipe(uncss({
html: [
'http://wordpress[dot]dev/','http://wordpress-gulp[dot]dev/page-1/'
]
}))
//Add a suffix to avoid confusion
.pipe(rename({suffix: '.clean'}))
//The destination of new uncssed file
.pipe(gulp.dest('lib/bootstrap/css/'));
这就是最基本的做法。如果你有很多页面,我建议使用WordPress的Grunt Sitemap Generator插件,链接在https://gist.github.com/lgladdy/10586308。
按照说明安装它,然后访问yourwordpresdomain.com?show_sitemap。
复制数组并将其内容粘贴在此处:
.pipe(uncss({
html: [
REPLACE THIS URLS ====> 'URL-1/','URL-2/page-1/'
]
}))