Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp streams out of order #25

Open
ryanaltvater opened this issue Aug 21, 2019 · 0 comments
Open

Gulp streams out of order #25

ryanaltvater opened this issue Aug 21, 2019 · 0 comments

Comments

@ryanaltvater
Copy link

ryanaltvater commented Aug 21, 2019

I've tried a handful of different possible solutions to the problem I'm having, and just can't seem to get the streams to run sequentially in order. I added some logging to the stream so that I can see the order in which things are being read. I used the docs to write the below code a few different ways, but same results each time. Am I missing something? What might I be doing wrong? Thank you in advance!

Package:

"paths": {
    "src": {
        "scss": "./src/assets/scss/"
    },
    "dev": {
        "css": "./dev/assets/css/"
    },
    "dist": {
        "css": "./dist/assets/css/"
    }
},
"devDependencies": {
    "browser-sync": "^2.26.7",
    "fancy-log": "^1.3.3",
    "gulp": "^4.0.2",
    "gulp-autoprefixer": "^6.1.0",
    "gulp-clean-css": "^4.2.0",
    "gulp-environments": "^0.1.2",
    "gulp-flatten": "^0.4.0",
    "gulp-group-css-media-queries": "^1.2.0",
    "gulp-if-env": "^0.1.0",
    "gulp-load-plugins": "^2.0.0",
    "gulp-notify": "^3.0.0",
    "gulp-plumber": "^1.1.0",
    "gulp-rename": "^1.2.3",
    "gulp-sass": "^4.0.2",
    "gulp-sourcemaps": "^2.6.4",
    "gulp-strip-css-comments": "^2.0.0",
    "merge2": "^1.2.4"
}

Gulp:

const { src, dest, lastRun, watch, series } = require('gulp');
const $ = require('gulp-load-plugins') ({
    pattern: ['*'],
    scope: ['devDependencies']
});
const pkg = require('./package.json');
const browserSync = require('browser-sync').create();

function css() {
    return $.merge2(
        src([
            pkg.paths.src.scss + '**/*.scss',
            '!' + pkg.paths.src.scss + 'projects/example-project/example.scss'
        ])
            .on('end', function() {
                $.fancyLog('cssDev');
            })
            .pipe($.plumber({
                errorHandler: $.notify.onError('Error: <%= error.message %>')
            }))
            .pipe($.sourcemaps.init())
            .pipe($.sass())
            .pipe($.stripCssComments({
                preserve: false
            }))
            .pipe($.autoprefixer({
                cascade: false
            }))
            .pipe($.groupCssMediaQueries())
            .pipe($.sourcemaps.write('./'))
            .pipe($.flatten({
                includeParents: 1
            }))
            .pipe(dest(pkg.paths.dev.css))
            .pipe(browserSync.stream()),
        src([
            pkg.paths.dev.css + '**/*.css'
        ])
            .on('end', function() {
                $.fancyLog('cssDist');
            })
            .pipe($.ifEnv.includes('sandbox', 'production', $.cleanCss({
                level: {
                    2: {
                        restructureRules: true
                    }
                }
            })))
            .pipe($.ifEnv.includes('sandbox', 'production', $.rename({
                suffix: '.min'
            })))
            .pipe($.ifEnv.includes('sandbox', 'production', $.flatten({
                includeParents: 1
            })))
            .pipe($.ifEnv.includes('sandbox', 'production', dest(pkg.paths.dist.css)))
    );
};

exports.css = css;

Command:

gulp css --env production

Output:

Using gulpfile ~/Sites/red-hat/webdms/gulpfile.js
Starting 'css'...
cssDist
cssDev
Finished 'css' after 2.22 s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant