Skip to content

Commit

Permalink
Allow Sass compilation to restart after gulp dev errors
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Nov 28, 2022
1 parent c0e14e1 commit 79c959d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 38 deletions.
126 changes: 90 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"minimatch": "^5.1.0",
"node-sass": "^8.0.0",
"nunjucks": "^3.2.3",
"plugin-error": "^2.0.0",
"postcss": "^8.4.19",
"postcss-pseudo-classes": "^0.2.1",
"postcss-scss": "^4.0.5",
Expand Down
18 changes: 16 additions & 2 deletions tasks/gulp/compile-assets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import uglify from 'gulp-uglify'
import merge from 'merge-stream'
import minimatch from 'minimatch'
import nodeSass from 'node-sass'
import PluginError from 'plugin-error'
import slash from 'slash'

import configPaths from '../../config/paths.js'
import { getListing } from '../../lib/file-helper.js'
import { componentNameToJavaScriptModuleName } from '../../lib/helper-functions.js'
import { destination, isDist, isPackage } from '../task-arguments.mjs'
import { destination, isDev, isDist, isPackage } from '../task-arguments.mjs'

const sass = gulpSass(nodeSass)

Expand Down Expand Up @@ -82,9 +83,22 @@ compileStylesheets.displayName = 'compile:scss'
*/
function compileStylesheet (stream, options = {}) {
return stream
.pipe(plumber())
.pipe(plumber(function (cause) {
const error = new PluginError('gulp-sass', cause.messageFormatted)
error.showProperties = false

// Gulp continue (watch)
if (isDev) {
console.error(error.toString())
return this.emit('end')
}

// Gulp exit with error
return stream.emit('error', error)
}))
.pipe(sass(options))
.pipe(postcss())
.pipe(plumber.stop())
}

/**
Expand Down
1 change: 1 addition & 0 deletions tasks/task-arguments.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export const destination = destPath
export const isPackage = target === 'package'
export const isPublic = target === 'public'
export const isDist = target === 'dist'
export const isDev = isPublic && tasks.includes('dev')

0 comments on commit 79c959d

Please sign in to comment.