Problem/Motivation

I am on a clean install of Drupal 8.9.2, running on an Ubuntu 20.04 LTS web server. Since this is a webserver, no browser is installed (i.e. I am using this in a headless environment).

I've installed Boostrap Barrio and Bootstrap 4 - Barrio SASS Starter Kit by means of composer.

I've followed the exact instructions for installing the starter kit and then used the included script to produce a custom subtheme.

It all works as expected until I run gulp. It never terminates, but hangs with the following message output last:

[Browsersync] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)

I understand that the problem is that there is no browser installed, but have no clue about what to do with this.

I've tried to fix by installing Firefox on the server (sudo apt install firefox). The "Couldn't open browser" message disappear, but gulp still hangs without terminating. Last output message is now:

[Browsersync] Reloading Browsers... (buffered 3 events)

Are the browserSync steps required to to use Barrio SASS Starter Kit, or can I just delete them from the gulpfile.js?

How and where do I set the open option to false?

I think the documentation for installing this project assumes too much about the environment where the install takes place. The best would be to have the install bash script ask or check up on the environment and either adapt the subtheme created to the environment, or at at least tell the developer about what is missing and how to fix it.

Steps to reproduce

  1. Install project according to instructions on a web server where no browser is installed.
  2. Run gulp

Proposed resolution

Bash script to create subtheme is changed to sniff the environment for requirements and if something is missing, tell developer how to fix it.

Comments

gisle created an issue. See original summary.

gisle’s picture

Title: Message: Couldn't open browser » Gulp message: Couldn't open browser

Improved title.

gisle’s picture

Issue summary: View changes
gisle’s picture

I've experimented a bit, and changed gulpfile.js to not use browserSync. It now looks like this:

let gulp = require('gulp'),
  sass = require('gulp-sass'),
  sourcemaps = require('gulp-sourcemaps'),
  cleanCss = require('gulp-clean-css'),
  rename = require('gulp-rename'),
  postcss = require('gulp-postcss'),
  autoprefixer = require('autoprefixer')

const paths = {
  scss: {
    src: './scss/style.scss',
    dest: './css',
    watch: './scss/**/*.scss',
    bootstrap: './node_modules/bootstrap/scss/bootstrap.scss'
  },
  js: {
    bootstrap: './node_modules/bootstrap/dist/js/bootstrap.min.js',
    jquery: './node_modules/jquery/dist/jquery.min.js',
    popper: 'node_modules/popper.js/dist/umd/popper.min.js',
    popper: 'node_modules/popper.js/dist/umd/popper.min.js.map',
    dest: './js'
  }
}

// Compile sass into CSS & auto-inject into browsers
function styles () {
  return gulp.src([paths.scss.bootstrap, paths.scss.src])
    .pipe(sourcemaps.init())
    .pipe(sass().on('error', sass.logError))
    .pipe(postcss([autoprefixer({
      browsers: [
        'Chrome >= 35',
        'Firefox >= 38',
        'Edge >= 12',
        'Explorer >= 10',
        'iOS >= 8',
        'Safari >= 8',
        'Android 2.3',
        'Android >= 4',
        'Opera >= 12']
    })]))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(paths.scss.dest))
    .pipe(cleanCss())
    .pipe(rename({ suffix: '.min' }))
    .pipe(gulp.dest(paths.scss.dest))
}

// Move the javascript files into our js folder
function js () {
  return gulp.src([paths.js.bootstrap, paths.js.jquery, paths.js.popper])
    .pipe(gulp.dest(paths.js.dest))
}

const build = gulp.series(styles, gulp.parallel(js))

exports.styles = styles
exports.js = js

exports.default = build

 
This makes gulp run and terminate without a glitch, and generates the css from the scss. I.e. it produces fresh copies of:

css/bootstrap.css
css/bootstrap.min.css
css/style.css
css/style.min.css

 
One strange thing remains. When I visit the front page with my regular browser, the site appear unstyled.

However, if I visit settings and change theme settings and change the setting for "Google Fonts combination" from "None" to anything else, the site are styled by the subtheme. Weird.

cfbauer’s picture

@gisle -- Do css sourcemaps work for you with this approach? I tried and am not seeing any generated sourcemaps.

gisle’s picture

I do not use generated css sourcemaps for anything, so I can't tell you if they work for me (but if you think they should be generated anyway, tell me where to look and what to look for, and I'll check again).

niklp’s picture

I'm using this setup too with the same issues and questions!

If the OP has any links/info would they be kind enough to ping me on slack/twitter with anything they know? I'll doubtless miss it here :)

gisle’s picture

OP here. Everything I know about this is already in the issue summary nd my subsequent comments.

This is a support request where I hope the one of the maintainers of the project would chip in provide some more documentation.

splash112’s picture

Just adding "open: false," will at least get gulp going and monitoring any changes. Make sure you disable CSS and JS aggregation or you will not see any changes. Works for me in WSL2.

browserSync.init({
proxy: "http://yourdomain.com",
open: false,
});

gisle’s picture

I added the line as suggested in comment #9.

It still looks like the processing gulpfile.js does something weird (i.e. it starts up and outputs "Reloading browsers" and never terminates to show the CLI prompt).

I am on a Ubuntu 20.04 LTS cloud server, not MS Windows (WSL2). I don't know whether that makes a difference.

Just adding "open: false," will at least get gulp going and monitoring any changes.

What does that mean? I've no problem getting gulp going. My problem is that it does not terminate, but stays active. I don't want it "monitoring any changes", but simply process the files and return to the CLI prompt.

I notice that it monitors the changes I make to the SCSS markip and also regenerates the CSS to reflect those changes. Is this how it is supposed to work?

mxmilkiib’s picture

> Is this how it is supposed to work?

Yes.

I also get the "Couldn't open browser" message though, and I'm not sure how that relates to getting sourcemaps working (with a remote environment), which would be handy.

gisle’s picture

Status: Active » Closed (works as designed)

Thanks! I' understand how this is supposed to work now. Could be better documented tho'