我正在開發一個輕量級的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
上找到任何選項,以縮小&保留/* … */
的評論。
有沒有人想出瞭解決方案?