/
index.js
70 lines (56 loc) · 1.53 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* jshint node: true */
'use strict';
var browserSync = require('browser-sync'),
broccoliFilter = require('broccoli-filter');
// yes, ghetto. need to talk to robert jackson
// to see if there is a better way of doing this
var cssPathsChanged = [];
function RegistryPlugin(inputTree) {
if (!(this instanceof RegistryPlugin)) {
return new RegistryPlugin(inputTree);
}
this.inputTree = inputTree;
}
RegistryPlugin.prototype = Object.create(broccoliFilter.prototype);
RegistryPlugin.prototype.constructor = RegistryPlugin;
RegistryPlugin.prototype.extensions = ['css'];
RegistryPlugin.prototype.targetExtension = 'css';
RegistryPlugin.prototype.processString = function(str, relativePath) {
cssPathsChanged.push(relativePath);
return str;
};
module.exports = {
name: 'ember-cli-browsersync'
included: function(app) {
if(app.env !== 'development') {
return false;
}
this._super.included.apply(this, arguments);
this.app = app;
app.registry.add('css', {
name: 'browser-sync',
ext: 'css',
toTree: function(tree) {
return RegistryPlugin(tree);
}
});
},
serverMiddleware: function(config) {
config.options.liveReload = false;
browserSync({
injectChanges: true,
reloadDelay: 10,
notify: false,
open: false,
proxy: config.options.host + ':' + config.options.port || 4200
});
},
postBuild: function (/*results*/) {
if (!cssPathsChanged.length) {
browserSync.reload();
} else {
browserSync.reload(cssPathsChanged);
cssPathsChanged = []; // reset
}
}
};