Let's Talk

Contact UsLet's Talk Solution

    Software Development, Web Development

    Using Browserlist with Gulp and Autoprefixer: A Beginner’s Guide

    Using Browserlist with Gulp and Autoprefixer: A Beginner’s Guide

    Do you use Gulp to compile your Sass files or build your HTML or JS assets? If yes, then you also need to know about Browser-sync and Browserlist. Both of them are tools that are used as an extension of the Chrome browser and help you to test websites in various different browsers without having the actual Chrome browser installed on your machine.

    Gulp is a task-based build system and automation tool for code. It automates tasks like compiling Sass, minification, unit testing, etc. It is developed by Eric Schoffstall and it has become very popular among front-end developers due to its ease of use, flexible API, and integration possibilities.

    In this blog post, we will cover how we integrated Gulp with Browserlist tool to automate browser testing across the local development environment, staging server, Staging server with Capistrano, and CI servers like Jenkins, etc which helps us in faster feedback cycle during the development phase and more stable end product at production phase too.

    What is Browserlist?

    Browserslist is a tool that allows specifying which browsers should be supported in your frontend app by specifying “queries” in a config file. It’s used by frameworks/libraries such as React, Angular, and Vue, but it’s not limited to them.

    Browserlist is a great tool for developers because it allows you to sync your local development environment with the browsers that are hosting them. This means when an error occurs in code, we can easily see what severity of flaw this could potentially be without having any issues on our end by simply opening up Browsers List and clicking Play Local Dev Environment button from there! Another benefit includes being able to customize which preferences ( CSS/JS ) get pushed down while syncing as well if needed – all via one simple interface too!

    Install Browserlist manually in your local machine and register it with CI servers

    Install the Browserlist extension on Chrome and add “http://localhost:8000” to your trusted sources. Then, open settings for both Firefox or Safari (depending on which one you use) in addition to containing localhost as an active connection option under “ BMCulerAgent Advanced Settings .”

    Next, enter Heroku/ Azure credentials if needed; make sure they are correctly entered before continuing with the next steps!

    Integrate Gulp with Browserlist

    We can use different plugins to set up various tasks like running a task with specific options, starting other browser tests in certain orders, and more. You’ll find all the necessary tools for this blog post on our Github page! First, we need install “Gulp-Browserlist” – which will make sure that when you start gluing any file from within NPM packages or locally installed scripts then it automatically starts BrowserList so there’s no need to manually execute its commands anymore.

    Running Gulp task with Browserlist

    Let’s now start a simple Gulp task with Browserlist by changing our gulpfile.js file. This will open up one line for us in the output window which displays “Starting” at the top left followed by information about what we’re doing (running browser list), how it works if someone else wants to use this tool too they just need access from their computer running under the same setup as ours because there are many ways you can get online but only certain ones to work perfectly fine without any problems ever once every few weeks.

    Installing the required tools for Browserlist integration

    Now let you need to set up your local machine with all the required tools to sync your browser with the testing browsers. You can install them on your local machine and then start Browserlist there.

    Node.js – It is a server-side JavaScript runtime environment that can be used to build Single Page Applications.

    PhantomJS – It is a headless WebKit used for running browser tests.

    Gulp – is a task-based build system and automation tool for code. It automates tasks like compiling Sass, minification, unit testing, etc.

    Using Autoprefixer with Gulp

    Autoprefixtsion allows us to add vendor-specific CSS declarations automatically so that our styles will stay up-to-date even if the website’s original author hasn’t added them yet. This means faster load times for visitors because their browser doesn’t have any extra work Cut down on server round trips by downloading only what you need instead wasting bandwidth with older versions; all this while keeping the ema style sheet completely customizable through design firms’ varying approaches!

    Using Browserlist with Autoprefixer and PostCSS

    So far, we have added the final layer of Autoprefixer integration. We need to import PostCSS plugin in order to transform our CSS files using this library and produce suitable output for Browserlist or even better yet – use their auto preference tool!

    Now let’s run our CSS transformation task using Gulp. This finishes up the Browserlist integration for us, and when you execute tests from now on in order to see what changes have been made it will be as if all of this was done live-right before your eyes! You can also view any output/diff that may come about due simply because something changed within one file or another.

    Summary

    In order to use browserlist with gulp and autoprefixer, you need to first install the gulp-autoprefixer module. Once that is installed, you can add it to your gulpfile.js file like this

    var autoprefixer = require(‘gulp-autoprefixer’);
    gulp.task(‘styles’, function() {
    return gulp.src(‘css/style.css’)
    .pipe(autoprefixer({
    browsers: [‘last 2 versions’],
    cascade: false
    }))
    .pipe(gulp.dest(‘dist’));
    });

    Once you have completed the above steps, running the gulp styles task will automatically prefix your CSS properties with vendor-specific ones. For more information on how to do that please refer back again here in this article by following these instructions carefully!

    Written by Aayush
    Writer, editor, and marketing professional with 10 years of experience, Aayush Singh is a digital nomad. With a focus on engaging digital content and SEO campaigns for SMB, and enterprise clients, he is the content creator & manager at SERP WIZARD.