Skip to content

Commit ec64500

Browse files
author
Valentyn
authored
Merge pull request #40 from malinushj/master
Browsersync injects .css files
2 parents 60a07cc + 53768da commit ec64500

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,32 @@ BrowserSyncPlugin.prototype.apply = function (compiler) {
3333
});
3434

3535
compiler.plugin('done', function (stats) {
36+
37+
// assets contains all the compiled assets
38+
var assets = _.keys(stats.compilation.assets),
39+
isCSS = _(assets)
40+
// organize the assets for cleaner use
41+
.map(function(asset){
42+
return {
43+
name: asset,
44+
emitted: stats.compilation.assets[asset].emitted
45+
}
46+
})
47+
// remove asset files that have not been emitted
48+
.filter(function(asset){ return asset.emitted })
49+
// true if all assets contain .css, false for anything else (.js, .img, etc)
50+
.every(function(asset){
51+
return asset.name.match('.css') !== null;
52+
});
53+
3654
if (self.isWebpackWatching) {
3755
if (self.isBrowserSyncRunning) {
3856
if (self.options.reload) {
39-
self.browserSync.reload();
57+
if (isCSS)
58+
// inject css if all compiled assets are css
59+
self.browserSync.reload('*.css');
60+
else
61+
self.browserSync.reload();
4062
}
4163
} else {
4264
if (_.isFunction(self.options.callback)) {

0 commit comments

Comments
 (0)