Gulp 4 style injection
See original GitHub issueI’m attempting to use browser-sync with Gulp 4 and the new bs .stream()
syntax, but bs is not preserving state and does a full refresh. Have you folks created a recipe / best practice for gulp v4 yet, so I can compare notes. Thanks for this awesome tool.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13
Top Results From Across the Web
gulp-style-inject - npm
A plugin for Gulp. Inject css file into html style tags.. Latest version: 0.1.3, last published: 2 years ago. Start using gulp-style-inject ......
Read more >Setting up gulp 4 for automatic Sass compilation and CSS ...
Step 1: Sass/Scss compilation · Step 2: Automating tasks · Step 3: Make it DRYer · Step 4: Let's add sourcemaps, autoprefixer and...
Read more >Gulp 4 & BrowserSync: Style Injection? - Stack Overflow
The browser-sync constructor takes an options object, which can include a files array. Most of the tutorials I've read, including the gulpfile ......
Read more >Just Sharing My Gulpfile - CSS-Tricks
Now that I could use Gulp 4.x, I re-wrote my gulpfile.js into smaller ... Runs a web server (Browsersync) for style injection and...
Read more >Gulp 4 Tutorial with Node JS, ImageMin, Browser Sync, SASS ...
This is completely updated tutorial video on Gulp 4.0 with NodeJS, BrowserSync, SASS, SourceMaps, CleanCSS , AutoPrefixer, Gulp Changed, ...
Read more >Top Related Medium Post
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@iliakan sure:
and then a separate file for css task setup:
watching is a joy in gulp4:
and then the default task… I’ve only shown css related stuff above, to keep this a simple illustration of live style injection using browser-sync and gulp4:
Fixed. Here’s where I went wrong:
The browser-sync constructor takes an options object, which can include a
files
array. Most of the tutorials I’ve read, including the gulpfile for Google’s very own Web Starter Kit, do not include this. As it turns out, this is required for style injection to preserve state.Furthermore, do not pass
.stream()
or.reload()
as the final pipe in your styles task. It is not needed, and will short circuit style injection, forcing a full refresh.Finally, the
browserSync
process must not be terminated, andwatch
andbrowserSync
tasks must execute in parallel in order for live style injection to take place.Hope this helps anybody facing this issue.