diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-07 16:50:33 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-07 16:50:33 +0200 |
commit | 6cca7360eb9027e1544f7513df7da4684061ef7e (patch) | |
tree | 16550f99324234a94cb7cdb098001051400079c9 | |
parent | 09f35e2a6fa71d593c9b22f90109e91fc6be89a1 (diff) | |
download | PeerTube-6cca7360eb9027e1544f7513df7da4684061ef7e.tar.gz PeerTube-6cca7360eb9027e1544f7513df7da4684061ef7e.tar.zst PeerTube-6cca7360eb9027e1544f7513df7da4684061ef7e.zip |
Reduce bundle sizes
-rw-r--r-- | .github/CONTRIBUTING.md | 1 | ||||
-rw-r--r-- | client/src/assets/player/peertube-link-button.ts | 1 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-plugin.ts | 17 | ||||
-rw-r--r-- | client/src/assets/player/peertube-videojs-typings.ts | 2 | ||||
-rw-r--r-- | client/src/assets/player/resolution-menu-item.ts | 1 | ||||
-rw-r--r-- | client/src/assets/player/settings-menu-item.ts | 1 | ||||
-rw-r--r-- | client/src/assets/player/utils.ts | 25 | ||||
-rw-r--r-- | client/tsconfig.json | 3 | ||||
-rw-r--r-- | client/webpack/webpack.video-embed.js | 7 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rwxr-xr-x | scripts/build/client.sh | 2 | ||||
-rwxr-xr-x | scripts/client-report.sh | 6 | ||||
-rwxr-xr-x | scripts/dev/client.sh | 2 | ||||
-rwxr-xr-x | scripts/dev/index.sh | 2 | ||||
-rwxr-xr-x | scripts/e2e.sh | 2 | ||||
-rwxr-xr-x | scripts/watch/server.sh | 2 | ||||
-rw-r--r-- | yarn.lock | 2 |
17 files changed, 62 insertions, 17 deletions
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d057cd3f3..56ea110b3 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md | |||
@@ -133,6 +133,7 @@ with the `root` as username and `test{1,2,3}` for the password. | |||
133 | ### Unit tests | 133 | ### Unit tests |
134 | 134 | ||
135 | Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user. | 135 | Create a PostgreSQL user **with the same name as your username** in order to avoid using the *postgres* user. |
136 | |||
136 | Then, we can create the databases (if they don't already exist): | 137 | Then, we can create the databases (if they don't already exist): |
137 | 138 | ||
138 | ``` | 139 | ``` |
diff --git a/client/src/assets/player/peertube-link-button.ts b/client/src/assets/player/peertube-link-button.ts index 26f8b9d73..715207bc0 100644 --- a/client/src/assets/player/peertube-link-button.ts +++ b/client/src/assets/player/peertube-link-button.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import * as videojs from 'video.js' | ||
1 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 2 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
2 | import { buildVideoLink } from './utils' | 3 | import { buildVideoLink } from './utils' |
3 | 4 | ||
diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 9babe556a..b54f096b2 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts | |||
@@ -4,9 +4,16 @@ import { VideoFile } from '../../../../shared/models/videos/video.model' | |||
4 | import { renderVideo } from './video-renderer' | 4 | import { renderVideo } from './video-renderer' |
5 | import './settings-menu-button' | 5 | import './settings-menu-button' |
6 | import { PeertubePluginOptions, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 6 | import { PeertubePluginOptions, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
7 | import { getAverageBandwidth, getStoredMute, getStoredVolume, saveAverageBandwidth, saveMuteInStore, saveVolumeInStore } from './utils' | 7 | import { |
8 | import minBy from 'lodash-es/minBy' | 8 | getAverageBandwidth, |
9 | import maxBy from 'lodash-es/maxBy' | 9 | getStoredMute, |
10 | getStoredVolume, | ||
11 | saveAverageBandwidth, | ||
12 | saveMuteInStore, | ||
13 | saveVolumeInStore, | ||
14 | videoFileMaxByResolution, | ||
15 | videoFileMinByResolution | ||
16 | } from './utils' | ||
10 | import * as CacheChunkStore from 'cache-chunk-store' | 17 | import * as CacheChunkStore from 'cache-chunk-store' |
11 | import { PeertubeChunkStore } from './peertube-chunk-store' | 18 | import { PeertubeChunkStore } from './peertube-chunk-store' |
12 | 19 | ||
@@ -339,9 +346,9 @@ class PeerTubePlugin extends Plugin { | |||
339 | }) | 346 | }) |
340 | 347 | ||
341 | // If the download speed is too bad, return the lowest resolution we have | 348 | // If the download speed is too bad, return the lowest resolution we have |
342 | if (filteredFiles.length === 0) return minBy(this.videoFiles, 'resolution.id') | 349 | if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) |
343 | 350 | ||
344 | return maxBy(filteredFiles, 'resolution.id') | 351 | return videoFileMaxByResolution(filteredFiles) |
345 | } | 352 | } |
346 | 353 | ||
347 | private getAndSaveActualDownloadSpeed () { | 354 | private getAndSaveActualDownloadSpeed () { |
diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index abdf333e1..50d6039ea 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts | |||
@@ -2,7 +2,7 @@ import * as videojs from 'video.js' | |||
2 | import { VideoFile } from '../../../../shared/models/videos/video.model' | 2 | import { VideoFile } from '../../../../shared/models/videos/video.model' |
3 | import { PeerTubePlugin } from './peertube-videojs-plugin' | 3 | import { PeerTubePlugin } from './peertube-videojs-plugin' |
4 | 4 | ||
5 | declare module 'video.js' { | 5 | declare namespace videojs { |
6 | interface Player { | 6 | interface Player { |
7 | peertube (): PeerTubePlugin | 7 | peertube (): PeerTubePlugin |
8 | } | 8 | } |
diff --git a/client/src/assets/player/resolution-menu-item.ts b/client/src/assets/player/resolution-menu-item.ts index 4b1ed0642..3fe1d8f0f 100644 --- a/client/src/assets/player/resolution-menu-item.ts +++ b/client/src/assets/player/resolution-menu-item.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | import * as videojs from 'video.js' | ||
1 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 2 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
2 | 3 | ||
3 | const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem') | 4 | const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem') |
diff --git a/client/src/assets/player/settings-menu-item.ts b/client/src/assets/player/settings-menu-item.ts index f595fd459..88985e1ae 100644 --- a/client/src/assets/player/settings-menu-item.ts +++ b/client/src/assets/player/settings-menu-item.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | // Author: Yanko Shterev | 1 | // Author: Yanko Shterev |
2 | // Thanks https://github.com/yshterev/videojs-settings-menu | 2 | // Thanks https://github.com/yshterev/videojs-settings-menu |
3 | 3 | ||
4 | import * as videojs from 'video.js' | ||
4 | import { toTitleCase } from './utils' | 5 | import { toTitleCase } from './utils' |
5 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 6 | import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' |
6 | 7 | ||
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index ce7aaea2a..4eaf53720 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' | 1 | import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' |
2 | import { VideoFile } from '../../../../shared/models/videos' | ||
2 | 3 | ||
3 | function toTitleCase (str: string) { | 4 | function toTitleCase (str: string) { |
4 | return str.charAt(0).toUpperCase() + str.slice(1) | 5 | return str.charAt(0).toUpperCase() + str.slice(1) |
@@ -97,6 +98,28 @@ function copyToClipboard (text: string) { | |||
97 | document.body.removeChild(el) | 98 | document.body.removeChild(el) |
98 | } | 99 | } |
99 | 100 | ||
101 | function videoFileMaxByResolution (files: VideoFile[]) { | ||
102 | let max = files[0] | ||
103 | |||
104 | for (let i = 1; i < files.length; i++) { | ||
105 | const file = files[i] | ||
106 | if (max.resolution.id < file.resolution.id) max = file | ||
107 | } | ||
108 | |||
109 | return max | ||
110 | } | ||
111 | |||
112 | function videoFileMinByResolution (files: VideoFile[]) { | ||
113 | let min = files[0] | ||
114 | |||
115 | for (let i = 1; i < files.length; i++) { | ||
116 | const file = files[i] | ||
117 | if (min.resolution.id > file.resolution.id) min = file | ||
118 | } | ||
119 | |||
120 | return min | ||
121 | } | ||
122 | |||
100 | export { | 123 | export { |
101 | toTitleCase, | 124 | toTitleCase, |
102 | buildVideoLink, | 125 | buildVideoLink, |
@@ -107,6 +130,8 @@ export { | |||
107 | saveMuteInStore, | 130 | saveMuteInStore, |
108 | buildVideoEmbed, | 131 | buildVideoEmbed, |
109 | getStoredMute, | 132 | getStoredMute, |
133 | videoFileMaxByResolution, | ||
134 | videoFileMinByResolution, | ||
110 | copyToClipboard, | 135 | copyToClipboard, |
111 | isMobile, | 136 | isMobile, |
112 | bytes | 137 | bytes |
diff --git a/client/tsconfig.json b/client/tsconfig.json index 8ce9c5f96..cb6d39245 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json | |||
@@ -19,7 +19,8 @@ | |||
19 | ], | 19 | ], |
20 | "baseUrl": "src", | 20 | "baseUrl": "src", |
21 | "paths": { | 21 | "paths": { |
22 | "@app/*": [ "app/*" ] | 22 | "@app/*": [ "app/*" ], |
23 | "video.js": [ "../node_modules/video.js/dist/alt/video.core.js" ] | ||
23 | } | 24 | } |
24 | } | 25 | } |
25 | } | 26 | } |
diff --git a/client/webpack/webpack.video-embed.js b/client/webpack/webpack.video-embed.js index 5a4e35dea..403a65930 100644 --- a/client/webpack/webpack.video-embed.js +++ b/client/webpack/webpack.video-embed.js | |||
@@ -1,4 +1,5 @@ | |||
1 | const helpers = require('./helpers') | 1 | const helpers = require('./helpers') |
2 | const path = require('path') | ||
2 | 3 | ||
3 | const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin | 4 | const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin |
4 | const HtmlWebpackPlugin = require('html-webpack-plugin') | 5 | const HtmlWebpackPlugin = require('html-webpack-plugin') |
@@ -24,7 +25,11 @@ module.exports = function () { | |||
24 | */ | 25 | */ |
25 | extensions: [ '.ts', '.js', '.json', '.scss' ], | 26 | extensions: [ '.ts', '.js', '.json', '.scss' ], |
26 | 27 | ||
27 | modules: [ helpers.root('src'), helpers.root('node_modules') ] | 28 | modules: [ helpers.root('src'), helpers.root('node_modules') ], |
29 | |||
30 | alias: { | ||
31 | 'video.js$': path.resolve('node_modules/video.js/dist/alt/video.core.js') | ||
32 | } | ||
28 | }, | 33 | }, |
29 | 34 | ||
30 | output: { | 35 | output: { |
diff --git a/package.json b/package.json index 4daeecb88..b963e67a4 100644 --- a/package.json +++ b/package.json | |||
@@ -54,6 +54,7 @@ | |||
54 | "nodemon": "nodemon", | 54 | "nodemon": "nodemon", |
55 | "ts-node": "ts-node", | 55 | "ts-node": "ts-node", |
56 | "tslint": "tslint", | 56 | "tslint": "tslint", |
57 | "concurrently": "concurrently", | ||
57 | "sasslint": "sass-lint --verbose --no-exit", | 58 | "sasslint": "sass-lint --verbose --no-exit", |
58 | "sasslint:fix": "sass-lint-auto-fix -c .sass-lint.yml --verbose", | 59 | "sasslint:fix": "sass-lint-auto-fix -c .sass-lint.yml --verbose", |
59 | "mocha": "mocha", | 60 | "mocha": "mocha", |
@@ -82,7 +83,7 @@ | |||
82 | "bluebird": "^3.5.0", | 83 | "bluebird": "^3.5.0", |
83 | "body-parser": "^1.12.4", | 84 | "body-parser": "^1.12.4", |
84 | "commander": "^2.13.0", | 85 | "commander": "^2.13.0", |
85 | "concurrently": "^3.1.0", | 86 | "concurrently": "^3.5.1", |
86 | "config": "^1.14.0", | 87 | "config": "^1.14.0", |
87 | "cors": "^2.8.1", | 88 | "cors": "^2.8.1", |
88 | "create-torrent": "^3.24.5", | 89 | "create-torrent": "^3.24.5", |
diff --git a/scripts/build/client.sh b/scripts/build/client.sh index d3da7cfcf..58aca437b 100755 --- a/scripts/build/client.sh +++ b/scripts/build/client.sh | |||
@@ -21,7 +21,7 @@ for lang in "$languages"; do | |||
21 | rm -r "./dist/$lang/assets" | 21 | rm -r "./dist/$lang/assets" |
22 | done | 22 | done |
23 | 23 | ||
24 | NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production | 24 | NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json" |
25 | 25 | ||
26 | # Copy runtime locales | 26 | # Copy runtime locales |
27 | cp -r "./src/locale/target" "./dist/locale" \ No newline at end of file | 27 | cp -r "./src/locale/target" "./dist/locale" \ No newline at end of file |
diff --git a/scripts/client-report.sh b/scripts/client-report.sh index 4dd4b418b..df7ccda27 100755 --- a/scripts/client-report.sh +++ b/scripts/client-report.sh | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | cd client | 5 | gawk -i inplace 'BEGIN { found=0 } { if (found || $0 ~ /^{/) { found=1; print }}' ./client/dist/embed-stats.json |
6 | 6 | ||
7 | npm run webpack-bundle-analyzer ./dist/stats.json | 7 | npm run concurrently -- -k \ |
8 | "cd client && npm run webpack-bundle-analyzer -- -p 8888 ./dist/en_US/stats.json" \ | ||
9 | "cd client && npm run webpack-bundle-analyzer -- -p 8889 ./dist/embed-stats.json" \ No newline at end of file | ||
diff --git a/scripts/dev/client.sh b/scripts/dev/client.sh index ecd934888..c630de2c4 100755 --- a/scripts/dev/client.sh +++ b/scripts/dev/client.sh | |||
@@ -2,6 +2,6 @@ | |||
2 | 2 | ||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | NODE_ENV=test concurrently -k \ | 5 | NODE_ENV=test npm run concurrently -- -k \ |
6 | "npm run watch:client" \ | 6 | "npm run watch:client" \ |
7 | "npm run build:server && NODE_ENV=test npm start" | 7 | "npm run build:server && NODE_ENV=test npm start" |
diff --git a/scripts/dev/index.sh b/scripts/dev/index.sh index dcbf62d37..7fc1560ab 100755 --- a/scripts/dev/index.sh +++ b/scripts/dev/index.sh | |||
@@ -2,6 +2,6 @@ | |||
2 | 2 | ||
3 | set -eu | 3 | set -eu |
4 | 4 | ||
5 | NODE_ENV=test concurrently -k \ | 5 | NODE_ENV=test npm run concurrently -- -k \ |
6 | "npm run watch:client" \ | 6 | "npm run watch:client" \ |
7 | "npm run watch:server" | 7 | "npm run watch:server" |
diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 0e70e6e51..1e31cd57c 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh | |||
@@ -10,7 +10,7 @@ npm run clean:server:test | |||
10 | npm run webpack -- --config webpack/webpack.video-embed.js --mode development | 10 | npm run webpack -- --config webpack/webpack.video-embed.js --mode development |
11 | ) | 11 | ) |
12 | 12 | ||
13 | concurrently -k -s first \ | 13 | npm run concurrently -- -k -s first \ |
14 | "cd client && npm run ng -- e2e --port 3333" \ | 14 | "cd client && npm run ng -- e2e --port 3333" \ |
15 | "NODE_ENV=test NODE_APP_INSTANCE=1 NODE_CONFIG='{ \"log\": { \"level\": \"warning\" } }' npm start" | 15 | "NODE_ENV=test NODE_APP_INSTANCE=1 NODE_CONFIG='{ \"log\": { \"level\": \"warning\" } }' npm start" |
16 | 16 | ||
diff --git a/scripts/watch/server.sh b/scripts/watch/server.sh index badbf3da0..da8bff1da 100755 --- a/scripts/watch/server.sh +++ b/scripts/watch/server.sh | |||
@@ -7,6 +7,6 @@ mkdir -p "./client/dist" | |||
7 | rm -r "./client/dist/locale" | 7 | rm -r "./client/dist/locale" |
8 | cp -r "./client/src/locale/target" "./client/dist/locale" | 8 | cp -r "./client/src/locale/target" "./client/dist/locale" |
9 | 9 | ||
10 | NODE_ENV=test concurrently -k \ | 10 | NODE_ENV=test npm run concurrently -- -k \ |
11 | "npm run tsc -- --sourceMap && npm run nodemon -- --delay 2 --watch ./dist dist/server" \ | 11 | "npm run tsc -- --sourceMap && npm run nodemon -- --delay 2 --watch ./dist dist/server" \ |
12 | "npm run tsc -- --sourceMap --preserveWatchOutput -w" | 12 | "npm run tsc -- --sourceMap --preserveWatchOutput -w" |
@@ -1572,7 +1572,7 @@ concat-stream@^1.4.1, concat-stream@^1.4.6, concat-stream@^1.4.7, concat-stream@ | |||
1572 | readable-stream "^2.2.2" | 1572 | readable-stream "^2.2.2" |
1573 | typedarray "^0.0.6" | 1573 | typedarray "^0.0.6" |
1574 | 1574 | ||
1575 | concurrently@^3.1.0: | 1575 | concurrently@^3.5.1: |
1576 | version "3.5.1" | 1576 | version "3.5.1" |
1577 | resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-3.5.1.tgz#ee8b60018bbe86b02df13e5249453c6ececd2521" | 1577 | resolved "https://registry.yarnpkg.com/concurrently/-/concurrently-3.5.1.tgz#ee8b60018bbe86b02df13e5249453c6ececd2521" |
1578 | dependencies: | 1578 | dependencies: |