-
Notifications
You must be signed in to change notification settings - Fork 331
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
Allow Sass compilation to restart after gulp dev
errors
#3034
Conversation
Probably also comes under #2243 |
6310282
to
e3665b4
Compare
d4079e2
to
c0f1861
Compare
c0f1861
to
34a84a9
Compare
compileStylesheets, | ||
npmScriptTask('build:sassdoc') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, makes more sense to only build the docs if we could actually build the stylesheet 🙌🏻
tasks/gulp/compile-assets.mjs
Outdated
.pipe(sass(options).on('error', (cause) => { | ||
const error = new PluginError('gulp-sass', cause.messageFormatted) | ||
error.showProperties = false | ||
|
||
// Gulp continue (watch) | ||
if (isDev) { | ||
console.error(error.toString()) | ||
return stream.emit('end') | ||
} | ||
|
||
// Gulp exit with error | ||
return stream.emit('error', error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick I see what this does, but it feels a bit narrow. If we'd introduce a new plugin or custom transform that'd emit error, we'd be back to square one.
Wondering if something like adding a final handling of error
on the watch
stream (found via this StackOverflow comment) could get us not to worry about task errors in dev long term? It may be an outdated solution though 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry @romaricpascal I've only taken this from the docs:
https://github.com/dlmanning/gulp-sass#render-your-css
Their approach suggests we swallow all errors with this.emit('end')
inside the logger:
.pipe(sass().on('error', sass.logError))
This is perfect for development and doesn't stop gulp.watch()
This is awful for production as we no longer "break the build"
So I've gone one step better and emitted an error when not developing
Wondering if something like adding a final handling of error on the watch stream (found via this StackOverflow comment) could get us not to worry about task errors in dev long term? It may be an outdated solution though 😬
We'd lose Gulp's PluginError()
flagging gulp-sass as the culprit (with fancy error output). Plus we'd lose per-plugin control of error.showProperties = false
where we know the log formatter already includes this
Also if you use stream.on('error')
to trigger stream.emit('error', error)
we get an infinite loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer to the gulp-sass
recommendation 😄
I think what I was looking for is a more systematic approach to handling transforms breaking, as for now it happens with Sass, but could happen on other transforms and the watch
task would break again. It felt very gulp-sass-specific, hence my link to the example that turns error
into end
(not error
so no looping) globally on the watch streams (so the build still breaks when not watching).
Similarly, the PluginError
bit should ideally be part of any piping, imho. This way it won't just be Sass letting us know that it's gulp-sass breaking (though the error and stacktrace will likely already provide plenty to pinpoint things, no?)
If we're happy to revisit if a newer plugin breaks, then fine going with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, yeah I understand, it's good feedback
I've pushed again with the error handler moved into gulp-plumber
so it listens for PostCSS errors too
Similarly, the PluginError bit should ideally be part of any piping, imho. This way it won't just be Sass letting us know that it's gulp-sass breaking (though the error and stacktrace will likely already provide plenty to pinpoint things, no?)
Sounds good, I'll nominate you for taking this further 😆
Hopefully we're good to get this first improvement PR in though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Yeah, using plumber
to handle makes things more generic 🙌🏻 Shame Gulp doesn't have that built in 😢
34a84a9
to
79c959d
Compare
79c959d
to
b635511
Compare
Gets changes into the browser slightly faster
b635511
to
3703211
Compare
This PR fixes an issue with our Sass compilation
compile:scss
Gulp tasknpm start
*.scss
invalid, save itgulp.watch()
to kick incompile:scss
Gulp task shows error + hangs 🔥npm start
again 😭Development: we now
.emit('end')
for the Sass compiler to resume on next saveProduction: we still
.emit('error')
for the Sass compiler to crash and break the buildMerge this PR and you can save, error, save, error, save, fix—all day long 😊