我正在开发一个轻量级的WordPress主题,我想使用所需的style.css
文件作为我唯一的CSS文件。如何使用gulp-sass生成有效的缩小WP style.css文件?
我的要求是:
- 它必须有WordPress的stylesheet header,它
- 和CSS代码应该精缩。
我使用SASS,我用gulp-sass
来编译它。现在,我在做:
/* gulpfile.babel.js */
const base = {
src: 'src',
dest: 'my-theme'
};
const routes = {
sass: {
src: `${base.src}/scss/style.scss`,
dest: `${base.dest}/`
}
};
gulp.task('styles',() => {
return gulp.src(routes.sass.src)
.pipe(plumber((err) => {
console.error(err.message);
}))
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest(routes.sass.dest));
});
而且我style.scss
包含:
/*
Theme Name: My Theme Name
Theme URI: http://example.com/my-theme
Author: My name
Author URI: http://example.com/
Description: My theme description
Version: 1.0
License: GNU General Public License v3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Tags: custom, lightweight
Text Domain: textdomain
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/
@import 'common';
这工作,但它不适合我的第二个要求(精缩CSS)。如果我添加
.pipe(sass({outputStyle: 'compressed'}))
然后我失去标题。我无法在gulp-sass
或node-sass
上找到任何选项,以缩小&保留/* … */
的评论。
有没有人想出了解决方案?