From c42a9b4a133c754f6ac044bc0457e99603e4b526 Mon Sep 17 00:00:00 2001 From: GabrielMeyer Date: Wed, 21 Aug 2019 17:34:05 +0200 Subject: [PATCH] Adds compiling to ES5 for IE11 --- client/angular.json | 64 +++++++++++++------ client/package.json | 1 + .../core/pdf-services/pdf-document.service.ts | 5 +- client/src/polyfills.ts | 20 ++++-- client/tsconfig-es5.app.json | 6 ++ 5 files changed, 70 insertions(+), 26 deletions(-) create mode 100644 client/tsconfig-es5.app.json diff --git a/client/angular.json b/client/angular.json index da3f7e2d5..956f93226 100644 --- a/client/angular.json +++ b/client/angular.json @@ -26,9 +26,21 @@ "assets": [ "src/assets", "src/manifest.json", - { "glob": "**/*", "input": "node_modules/tinymce/skins", "output": "/tinymce/skins/" }, - { "glob": "**/*", "input": "node_modules/tinymce/themes", "output": "/tinymce/themes/" }, - { "glob": "**/*", "input": "node_modules/tinymce/plugins", "output": "/tinymce/plugins/" } + { + "glob": "**/*", + "input": "node_modules/tinymce/skins", + "output": "/tinymce/skins/" + }, + { + "glob": "**/*", + "input": "node_modules/tinymce/themes", + "output": "/tinymce/themes/" + }, + { + "glob": "**/*", + "input": "node_modules/tinymce/plugins", + "output": "/tinymce/plugins/" + } ], "styles": ["src/styles.scss"], "scripts": ["node_modules/tinymce/tinymce.min.js"], @@ -36,12 +48,10 @@ }, "configurations": { "production": { - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ], + "fileReplacements": [{ + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + }], "optimization": true, "outputHashing": "all", "sourceMap": false, @@ -52,13 +62,14 @@ "vendorChunk": false, "buildOptimizer": true, "serviceWorker": true, - "budgets": [ - { - "type": "initial", - "maximumWarning": "5mb", - "maximumError": "10mb" - } - ] + "budgets": [{ + "type": "initial", + "maximumWarning": "5mb", + "maximumError": "10mb" + }] + }, + "es5": { + "tsConfig": "./tsconfig-es5.app.json" } } }, @@ -70,6 +81,9 @@ "configurations": { "production": { "browserTarget": "client:build:production" + }, + "es5": { + "browserTarget": "client:build:es5" } } }, @@ -91,9 +105,21 @@ "assets": [ "src/assets", "src/manifest.json", - { "glob": "**/*", "input": "node_modules/tinymce/skins", "output": "/tinymce/skins/" }, - { "glob": "**/*", "input": "node_modules/tinymce/themes", "output": "/tinymce/themes/" }, - { "glob": "**/*", "input": "node_modules/tinymce/plugins", "output": "/tinymce/plugins/" } + { + "glob": "**/*", + "input": "node_modules/tinymce/skins", + "output": "/tinymce/skins/" + }, + { + "glob": "**/*", + "input": "node_modules/tinymce/themes", + "output": "/tinymce/themes/" + }, + { + "glob": "**/*", + "input": "node_modules/tinymce/plugins", + "output": "/tinymce/plugins/" + } ] } }, diff --git a/client/package.json b/client/package.json index 8d68d79be..468c28aa3 100644 --- a/client/package.json +++ b/client/package.json @@ -12,6 +12,7 @@ "ng": "ng", "ng-high-memory": "node --max_old_space_size=4096 ./node_modules/@angular/cli/bin/ng", "start": "ng serve --proxy-config proxy.conf.json --host=0.0.0.0", + "start-es5": "ng serve --proxy-config proxy.conf.json --host=0.0.0.0 --configuration es5", "build": "npm run ng-high-memory -- build --prod", "test": "ng test", "lint-check": "ng lint", diff --git a/client/src/app/core/pdf-services/pdf-document.service.ts b/client/src/app/core/pdf-services/pdf-document.service.ts index 5bb0f62b7..5303fd9ec 100644 --- a/client/src/app/core/pdf-services/pdf-document.service.ts +++ b/client/src/app/core/pdf-services/pdf-document.service.ts @@ -457,7 +457,8 @@ export class PdfDocumentService { const vfs = await this.initVfs(); await this.loadAllImages(vfs); - if (typeof Worker !== 'undefined') { + const isIE = /msie\s|trident\//i.test(window.navigator.userAgent); + if (typeof Worker !== 'undefined' && !isIE) { const worker = new Worker('./pdf-worker.worker', { type: 'module' }); @@ -485,7 +486,7 @@ export class PdfDocumentService { }); } else { this.matSnackBar.dismiss(); - this.matSnackBar.open(this.translate.instant('Web workers are not supported on your browser.'), '', { + this.matSnackBar.open(this.translate.instant('Cannot create PDF files on this browser.'), '', { duration: 0 }); } diff --git a/client/src/polyfills.ts b/client/src/polyfills.ts index 5ca2f34ee..fd0c3a7f8 100644 --- a/client/src/polyfills.ts +++ b/client/src/polyfills.ts @@ -15,11 +15,21 @@ */ /*************************************************************************************************** -* BROWSER POLYFILLS -*/ + * BROWSER POLYFILLS + */ -import 'core-js/es7/object'; -import 'core-js/es7/array'; +import 'core-js/es6/object'; +import 'core-js/es6/array'; + +// forEach fix for IE11 +if ('NodeList' in window && !NodeList.prototype.forEach) { + NodeList.prototype.forEach = function(callback, thisArg) { + thisArg = thisArg || window; + for (var i = 0; i < this.length; i++) { + callback.call(thisArg, this[i], i, this); + } + }; +} /* IE10 and IE11 requires the following for NgClass support on SVG elements */ // import 'classlist.js'; // Run `npm install --save classlist.js`. @@ -36,7 +46,7 @@ import 'core-js/es7/reflect'; * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). */ -// import 'web-animations-js'; // Run `npm install --save web-animations-js`. +// import 'web-animations-js'; // Run `npm install --save web-animations-js`. /** * By default, zone.js will patch all possible macroTask and DomEvents diff --git a/client/tsconfig-es5.app.json b/client/tsconfig-es5.app.json new file mode 100644 index 000000000..c7096a2ec --- /dev/null +++ b/client/tsconfig-es5.app.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.app.json", + "compilerOptions": { + "target": "es5" + } +}