addyosmani / addyosmani/gulp-uncss-task

CSS gets duplicated

Ouverte
#3 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
61
Forks
9
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.