forked from ahmadatallah/browser-sync-spa
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (40 loc) · 1.17 KB
/
index.js
File metadata and controls
47 lines (40 loc) · 1.17 KB
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
var historyApiFallback = require("connect-history-api-fallback");
var merger = require("opt-merger");
const PLUGIN_NAME = "BrowserSync SPA";
const HISTORY_CHANGE_EVENT = "history:change";
const CLIENT_JS = "/client.js";
/**
* Plugin interface for BrowserSync
*/
var plugin = {
"plugin:name": PLUGIN_NAME,
"plugin": function (opts, instance) {
var logger = instance.getLogger(PLUGIN_NAME);
logger.info("Running...");
},
"hooks": {
"client:js": "",
"client:events": function () {
return HISTORY_CHANGE_EVENT;
}
}
}
const defaults = {
selector: "[ng-app]",
history: {}
};
/**
* Allow run-time modifications to the client-side script
* @param opts
*/
module.exports = function (opts) {
var config = merger.set({simple: true}).merge(defaults, opts);
var clientJs = require("fs").readFileSync(__dirname + CLIENT_JS, "utf-8");
plugin.hooks["client:js"] = clientJs.replace("%SELECTOR%", config.selector);
if (config.history) {
plugin.hooks["server:middleware"] = function () {
return historyApiFallback(config.history);
};
}
return plugin;
}