addyosmani / addyosmani/gulp-uncss-task

CSS gets duplicated

Abierto
#3 5 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
61
Forks
9
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.