Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Last active May 29, 2017 04:02
Show Gist options
  • Save amcdnl/19904a939b3be3e8bc5d to your computer and use it in GitHub Desktop.
Save amcdnl/19904a939b3be3e8bc5d to your computer and use it in GitHub Desktop.
import angular from 'angular';
export var appModule = angular.module('app', []);
var container = angular.element('#app-container'),
noAngularDOM, injector, $compile, $rootScope;
angular.element(document).ready(() => {
noAngularDOM = container[0].cloneNode(true);
angular.bootstrap(container, [appModule.name]);
});
export function __unload(){
container = angular.element('#app-container');
if(!injector){
injector = container.injector();
$compile = injector.get('$compile');
$rootScope = injector.get('$rootScope');
}
//$rootScope.$destroy();
container.remove();
document.body.appendChild(noAngularDOM.cloneNode(true));
angular.bootstrap(container, [appModule.name]);
//$compile(angular.element('#app-container'))($rootScope);
//$rootScope.$digest();
}
<!doctype html>
<html lang="en" data-framework="angularjs">
<head>
<meta charset="utf-8">
</head>
<body>
<div id="app-container">
<div ui-view></div>
</div>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.trace = true
System.import('app/app').then(function(mod){
(function (bs) {
bs.socket.on('custom-event', function (data) {
console.log('reloaded file:', data.file);
var path = data.file.split("wwwroot\\dist\\")
var modPath = System.normalizeSync(path[1]);
System.delete(modPath);
System.import(modPath).then(function(){
mod.__unload();
});
});
})(___browserSync___);
}).catch(console.error.bind(console));
</script>
</body>
</html>
var gulp = require('gulp');
var bs = require('browser-sync').create();
var proxyMiddleware = require('http-proxy-middleware');
var historyApiFallback = require('connect-history-api-fallback');
var baseUrl = 'localhost';
gulp.task('serve', function(done) {
var apiProxy = proxyMiddleware('/api', {
target: baseUrl,
ws: true
});
bs.init({
open: false,
port: 9000,
injectChanges: true,
files: ['wwwroot/index.html'],
server: {
baseDir: ['wwwroot'],
middleware: [ apiProxy, historyApiFallback() ]
}
}, function (err, instance) {
bs.watch("wwwroot/dist/**/*.js").on('change', function (file) {
instance.io.sockets.emit('custom-event', {file: file});
});
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment