如何通过 clean-css 缩小来保持我的相对路径?
How to keep my relative paths with clean-css minifying?
为什么下面的 gulp 代码删除了我的相对路径?
我正在使用 clean-css:
gulp.task('build-css', function() {
return gulp.src([
'style.css',
])
.pipe(sourcemaps.init())
.pipe(cleanCSS({debug: true}))
.pipe(concat('bundle.min.css'))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist'))
.pipe(livereload());
});
原文css:
@font-face {
font-family: 'icomoon';
src: url('../fonts/social-media/icomoon.eot?mh2h47');
src: url('../fonts/social-media/icomoon.eot?mh2h47#iefix') format('embedded-opentype'),
url('../fonts/social-media/icomoon.ttf?mh2h47') format('truetype'),
url('../fonts/social-media/icomoon.woff?mh2h47') format('woff'),
url('../fonts/social-media/icomoon.svg?mh2h47#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
使用 gulp 缩小后:
@font-face{font-family:icomoon;src:url(fonts/social-media/icomoon.eot?mh2h47);src:url(fonts/social-media/icomoon.eot?mh2h47#iefix)
如何保留这些相对路径?
尝试将 rebase 选项设置为 false(默认值为 true),这样您的路径就不会被 cleanCSS 修改。
.pipe(cleanCSS( {debug: true, rebase: false} )
为什么下面的 gulp 代码删除了我的相对路径?
我正在使用 clean-css:
gulp.task('build-css', function() {
return gulp.src([
'style.css',
])
.pipe(sourcemaps.init())
.pipe(cleanCSS({debug: true}))
.pipe(concat('bundle.min.css'))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist'))
.pipe(livereload());
});
原文css:
@font-face {
font-family: 'icomoon';
src: url('../fonts/social-media/icomoon.eot?mh2h47');
src: url('../fonts/social-media/icomoon.eot?mh2h47#iefix') format('embedded-opentype'),
url('../fonts/social-media/icomoon.ttf?mh2h47') format('truetype'),
url('../fonts/social-media/icomoon.woff?mh2h47') format('woff'),
url('../fonts/social-media/icomoon.svg?mh2h47#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
使用 gulp 缩小后:
@font-face{font-family:icomoon;src:url(fonts/social-media/icomoon.eot?mh2h47);src:url(fonts/social-media/icomoon.eot?mh2h47#iefix)
如何保留这些相对路径?
尝试将 rebase 选项设置为 false(默认值为 true),这样您的路径就不会被 cleanCSS 修改。
.pipe(cleanCSS( {debug: true, rebase: false} )