A
A
artekha2016-11-04 22:08:12
css
artekha, 2016-11-04 22:08:12

Why are styles duplicated?

I am compiling the project at a gallop. Styles on stylus. Everything is collected in one main.css file, and minified. But in the final main.css all styles are duplicated 2 times. How to fix it?
3e7d4f7467e34ee49acced238eb13e26.png
Here is the gallpfile itself:

'use strict';

// Require plugins
const gulp = require('gulp');
const plumber = require('gulp-plumber');
const prefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const jade = require('gulp-jade');
const stylus = require('gulp-stylus');
const uglify = require('gulp-uglify');

// Template
gulp.task('jade', function() {
  gulp.src('src/jade/pages/*.jade')
    .pipe(plumber())
    .pipe(jade({pretty: true}))
    .pipe(gulp.dest('dist/'));
})

// Styles
gulp.task('stylus', function() {
  gulp.src('src/stylus/**/*.styl')
    .pipe(plumber())
    .pipe(stylus({
      compress: true
    }))
    .pipe(concat('main.css'))
    .pipe(gulp.dest('dist/css'));
});

// Scripts
gulp.task('js', function() {
  gulp.src('src/js/**/*.js')
    .pipe(plumber())
    .pipe(concat('main.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist/js'))
});

// Watches
gulp.task('stylus:watch', function () {
  gulp.watch('src/stylus/**/*.styl', ['stylus']);
});
gulp.task('jade:watch', function () {
  gulp.watch('src/jade/**/*.jade', ['jade']);
});
gulp.task('js:watch', function () {
  gulp.watch('src/js/**/*.js', ['js']);
});

// Default task
gulp.task('default', ['stylus:watch', 'jade:watch', 'js:watch']);

Here is the stylus folder structure:
c5a7333899694e9487ce51fd9e4df257.png
Imports in main.styl
0aef55b2286f4bd3a6d6878bf8c14a84.png
PS If you do this gulp.src('src/stylus/main.styl') then watch doesn't watch changes in other files

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Edward, 2016-11-04
@edalis

Why is this pipe in the "stylus" task:
.pipe(concat('main.css'))?
He's clearly out of place here.
You already have all the styles imported into main. styl, and he is in the pipe

.pipe(stylus({
    compress: true
}))

compiles to main.css.
It turns out that you compile it, and then once again collect all the styles in a heap, in main.css...

K
Kanonier8, 2016-11-04
@Kanonier8

Try https://www.npmjs.com/package/gulp-css-purge

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question