Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/options.snippetOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
* Install:
* npm install browser-sync
*
* Run:
* node <yourfile.js>
*
* This example shows how you can place the snippet anywhere.
*/

"use strict";

var path = require("path");
var browserSync = require("../packages/browser-sync").create();
var cwd = path.join(__dirname, "..");
var fixtures_dir = path.join(cwd, "packages/browser-sync/test/fixtures");

browserSync.init({
files: [path.join(fixtures_dir, "css/*.css")],
server: fixtures_dir,
snippetOptions: {
rule: {
match: /<\/head>/i,
fn: function (snippet, match) {
return snippet + match;
},
},
},
});
2 changes: 2 additions & 0 deletions packages/browser-sync/templates/script-tags.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
script.src = '%script%'.replace("HOST", location.hostname);
if (document.body) {
document.body.appendChild(script);
} else if (document.head) {
document.head.appendChild(script);
}
} catch (e) {
console.error("Browsersync: could not append script tag", e);
Expand Down