addyosmani / addyosmani/gulp-uncss-task

CSS gets duplicated

Đang mở
#3 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
61
Fork
9
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Addy recommended I open an issue for this, so here goes.

Let's say I have a single HTML page that references a single stylesheet, and I want to check that stylesheet for unnecessary rules. I figured the following trivial gulpfile would work:

``` javascript
var gulp = require("gulp");
var uncss = require("gulp-uncss-task");

var src = "src";
var target = "target";
var index = src + "/index.html";

gulp.task("default", function() {
gulp.src(index)
.pipe(gulp.dest(target));
gulp.src(src + "/style.css")
.pipe(uncss({
html: [index]
}))
.pipe(gulp.dest(target));
});
```

Unfortunately, running `gulp` results in `target/style.css` containing the optimized content of `src/style.css` _twice_.

If I remove the reference to `style.css` from `src/index.html`, the resulting CSS is fine. However, adding a `link` element after UnCSS processes the HTML is tedious and doesn't seem like the right approach, especially since UnCSS figures out the list of stylesheets from the HTML in the first place.

I've tried passing an empty `stylesheets` array to the `uncss` function, as well as setting the `csspath` to `"./"`, but that didn't change anything. I also tried putting the source HTML and CSS in the package root directory, because I thought it might be something path-related; no luck though.

To confirm, I tested with UnCSS itself. The following code works as expected, returning the optimized CSS a single time:

``` javascript
require('uncss')(['src/index.html'], {}, function(output) {
console.log(output);
});
```

I'm using gulp 3.2.2 and gulp-uncss-task 0.1.0, on Windows 8 x64.

For the sake of completeness, here are my HTML and CSS:

``` html

Hello, world

```

``` css
p {
font-family: Verdana;
}

div {
color: blue;
}
```

Am I missing something obvious? Thanks.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.