This repository has been archived on 2023-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
old-monorepo/_Dashboard/tasks/hotreload.js

43 lines
1 KiB
JavaScript

const { series, src, dest } = require('gulp');
const inject = require('gulp-inject-string');
const browserSync = require('browser-sync').create();
function startBrowserSync(done) {
browserSync.init(
{
ui: false,
localOnly: true,
port: 35829,
ghostMode: false,
open: false,
notify: false,
logSnippet: false,
},
function (error) {
done(error);
},
);
}
function injectBrowserSync() {
return src('app/renderer/index.html')
.pipe(inject.before('</body>', browserSync.getOption('snippet')))
.pipe(
inject.after('script-src', " 'unsafe-eval' " + browserSync.getOption('urls').get('local')),
)
.pipe(dest('build/renderer'));
}
function reloadBrowser(done) {
browserSync.reload();
done();
}
startBrowserSync.displayName = 'start-hotreload';
injectBrowserSync.displayName = 'inject-hotreload';
reloadBrowser.displayName = 'reload-hotreload';
exports.start = series(startBrowserSync, injectBrowserSync);
exports.inject = injectBrowserSync;
exports.reload = reloadBrowser;