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 23, 2022
1 parent 6e7d89d commit d4079e2
Show file tree
Hide file tree
Showing 4 changed files with 111 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
21 changes: 19 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 @@ -83,7 +84,23 @@ compileStylesheets.displayName = 'compile:scss'
function compileStylesheet (stream, options = {}) {
return stream
.pipe(plumber())
.pipe(sass(options))

// Compile Sass to CSS
.pipe(sass(options).on('error', (error) => {
if (!isDev) {
error.showProperties = false
error.showStack = false

// Gulp exit (on error)
return stream.emit('error', error)
}

// Gulp continue (on error) via `gulp dev`
console.error(new PluginError('sass', error.messageFormatted).toString())
return stream.emit('end')
}))

// Apply PostCSS (autoprefixer etc)
.pipe(postcss())
}

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 d4079e2

Please sign in to comment.