addyosmani / addyosmani/gulp-uncss-task

CSS gets duplicated

Aperta
#3 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
61
Fork
9
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.