aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-12 14:45:42 +0100
committerChocobozzz <me@florianbigard.com>2017-12-12 14:45:42 +0100
commit77d07d690968a9631fc0c8bafbaebd27a5ebaab6 (patch)
treed513fdc81ed82b60edaa0b683f5f8d8dc9fc9db3
parentb2731bff2834fb6aacf166cf435030bf96eb12f3 (diff)
downloadPeerTube-77d07d690968a9631fc0c8bafbaebd27a5ebaab6.tar.gz
PeerTube-77d07d690968a9631fc0c8bafbaebd27a5ebaab6.tar.zst
PeerTube-77d07d690968a9631fc0c8bafbaebd27a5ebaab6.zip
Add hmr
-rw-r--r--client/package.json1
-rw-r--r--client/src/environments/environment.prod.ts1
-rw-r--r--client/src/environments/environment.ts1
-rw-r--r--client/src/hmr.ts16
-rw-r--r--client/src/main.ts16
-rw-r--r--client/yarn.lock4
-rwxr-xr-xscripts/watch/client.sh2
7 files changed, 38 insertions, 3 deletions
diff --git a/client/package.json b/client/package.json
index b8103d433..14c20e8d9 100644
--- a/client/package.json
+++ b/client/package.json
@@ -33,6 +33,7 @@
33 "@angular/platform-browser": "~5.1.0", 33 "@angular/platform-browser": "~5.1.0",
34 "@angular/platform-browser-dynamic": "~5.1.0", 34 "@angular/platform-browser-dynamic": "~5.1.0",
35 "@angular/router": "~5.1.0", 35 "@angular/router": "~5.1.0",
36 "@angularclass/hmr": "^2.1.3",
36 "@ngx-meta/core": "^4.0.1", 37 "@ngx-meta/core": "^4.0.1",
37 "@types/core-js": "^0.9.28", 38 "@types/core-js": "^0.9.28",
38 "@types/markdown-it": "^0.0.4", 39 "@types/markdown-it": "^0.0.4",
diff --git a/client/src/environments/environment.prod.ts b/client/src/environments/environment.prod.ts
index c9f5a3b63..d5dfe5573 100644
--- a/client/src/environments/environment.prod.ts
+++ b/client/src/environments/environment.prod.ts
@@ -1,4 +1,5 @@
1export const environment = { 1export const environment = {
2 production: true, 2 production: true,
3 hmr: false,
3 apiUrl: '' 4 apiUrl: ''
4} 5}
diff --git a/client/src/environments/environment.ts b/client/src/environments/environment.ts
index 43d788541..42b8baee8 100644
--- a/client/src/environments/environment.ts
+++ b/client/src/environments/environment.ts
@@ -5,5 +5,6 @@
5 5
6export const environment = { 6export const environment = {
7 production: false, 7 production: false,
8 hmr: true,
8 apiUrl: 'http://localhost:9000' 9 apiUrl: 'http://localhost:9000'
9} 10}
diff --git a/client/src/hmr.ts b/client/src/hmr.ts
new file mode 100644
index 000000000..4d707a250
--- /dev/null
+++ b/client/src/hmr.ts
@@ -0,0 +1,16 @@
1import { NgModuleRef, ApplicationRef } from '@angular/core'
2import { createNewHosts } from '@angularclass/hmr'
3
4export const hmrBootstrap = (module: any, bootstrap: () => Promise<NgModuleRef<any>>) => {
5 let ngModule: NgModuleRef<any>
6 module.hot.accept()
7 bootstrap()
8 .then(mod => ngModule = mod)
9 module.hot.dispose(() => {
10 const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef)
11 const elements = appRef.components.map(c => c.location.nativeElement)
12 const makeVisible = createNewHosts(elements)
13 ngModule.destroy()
14 makeVisible()
15 })
16}
diff --git a/client/src/main.ts b/client/src/main.ts
index f3825fe50..b02b6830f 100644
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -4,10 +4,22 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
4import { AppModule } from './app/app.module' 4import { AppModule } from './app/app.module'
5import { environment } from './environments/environment' 5import { environment } from './environments/environment'
6 6
7import { hmrBootstrap } from './hmr'
8
7if (environment.production) { 9if (environment.production) {
8 enableProdMode() 10 enableProdMode()
9} 11}
10 12
11platformBrowserDynamic() 13const bootstrap = () => platformBrowserDynamic()
12 .bootstrapModule(AppModule) 14 .bootstrapModule(AppModule)
13 .catch(err => console.log(err)) 15
16if (environment.hmr) {
17 if (module[ 'hot' ]) {
18 hmrBootstrap(module, bootstrap)
19 } else {
20 console.error('HMR is not enabled for webpack-dev-server!')
21 console.log('Are you using the --hmr flag for ng serve?')
22 }
23} else {
24 bootstrap()
25}
diff --git a/client/yarn.lock b/client/yarn.lock
index b21624ec5..5c63a68a6 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -158,6 +158,10 @@
158 dependencies: 158 dependencies:
159 tslib "^1.7.1" 159 tslib "^1.7.1"
160 160
161"@angularclass/hmr@^2.1.3":
162 version "2.1.3"
163 resolved "https://registry.yarnpkg.com/@angularclass/hmr/-/hmr-2.1.3.tgz#34e658ed3da37f23b0a200e2da5a89be92bb209f"
164
161"@ngtools/json-schema@1.1.0", "@ngtools/json-schema@^1.1.0": 165"@ngtools/json-schema@1.1.0", "@ngtools/json-schema@^1.1.0":
162 version "1.1.0" 166 version "1.1.0"
163 resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922" 167 resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922"
diff --git a/scripts/watch/client.sh b/scripts/watch/client.sh
index b754ade76..6d4759b4e 100755
--- a/scripts/watch/client.sh
+++ b/scripts/watch/client.sh
@@ -2,4 +2,4 @@
2 2
3cd client || exit -1 3cd client || exit -1
4 4
5ng server --host localhost --port 3000 5ng server --hmr --host localhost --port 3000