From 718dd762cf86ce7ce1a6a4d87fd48e58aeb44626 Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sun, 16 May 2021 11:40:31 +0100 Subject: [PATCH] Trial using lazy loading imports. --- src/allPages.ts | 84 +++++++++-------------- src/pages/Home.ts | 2 + src/pages/KeyValue/KeyValueDelete.ts | 2 + src/pages/KeyValue/KeyValueNew.ts | 1 + src/pages/KeyValue/KeyValueSecret.ts | 2 + src/pages/KeyValue/KeyValueSecretsEdit.ts | 1 + src/pages/KeyValue/KeyValueVersions.ts | 2 + src/pages/KeyValue/KeyValueView.ts | 2 + src/pages/Login.ts | 2 + src/pages/Me.ts | 2 + src/pages/NewEngines/NewKVEngine.ts | 2 + src/pages/NewEngines/NewTOTPEngine.ts | 2 + src/pages/NewEngines/NewTransitEngine.ts | 2 + src/pages/NewSecretsEngine.ts | 2 + src/pages/PwGen.ts | 2 + src/pages/SetLanguage.ts | 2 + src/pages/SetVaultURL.ts | 2 + src/pages/TOTP/NewTOTP.ts | 2 + src/pages/TOTP/TOTPView.ts | 2 + src/pages/Transit/NewTransitKey.ts | 2 + src/pages/Transit/TransitDecrypt.ts | 2 + src/pages/Transit/TransitEncrypt.ts | 2 + src/pages/Transit/TransitRewrap.ts | 2 + src/pages/Transit/TransitView.ts | 2 + src/pages/Transit/TransitViewSecret.ts | 2 + src/pages/Unseal.ts | 2 + tsconfig.json | 2 +- webpack.config.js | 9 ++- 28 files changed, 87 insertions(+), 56 deletions(-) diff --git a/src/allPages.ts b/src/allPages.ts index 0538e80..1e3a352 100644 --- a/src/allPages.ts +++ b/src/allPages.ts @@ -1,68 +1,46 @@ -import { HomePage } from "./pages/Home"; -import { KeyValueDeletePage } from "./pages/KeyValue/KeyValueDelete"; -import { KeyValueNewPage } from "./pages/KeyValue/KeyValueNew"; -import { KeyValueSecretEditPage } from "./pages/KeyValue/KeyValueSecretsEdit"; -import { KeyValueSecretPage } from "./pages/KeyValue/KeyValueSecret"; -import { KeyValueVersionsPage } from "./pages/KeyValue/KeyValueVersions"; -import { KeyValueViewPage } from "./pages/KeyValue/KeyValueView"; -import { LoginPage } from "./pages/Login"; -import { MePage } from "./pages/Me"; -import { NewKVEnginePage } from "./pages/NewEngines/NewKVEngine"; -import { NewSecretsEnginePage } from "./pages/NewSecretsEngine"; -import { NewTOTPEnginePage } from "./pages/NewEngines/NewTOTPEngine"; -import { NewTOTPPage } from "./pages/TOTP/NewTOTP"; -import { NewTransitEnginePage } from "./pages/NewEngines/NewTransitEngine"; -import { NewTransitKeyPage } from "./pages/Transit/NewTransitKey"; import { Page } from "./types/Page"; -import { PwGenPage } from "./pages/PwGen"; -import { SetLanguagePage } from "./pages/SetLanguage"; -import { SetVaultURLPage } from "./pages/SetVaultURL"; -import { TOTPViewPage } from "./pages/TOTP/TOTPView"; -import { TransitDecryptPage } from "./pages/Transit/TransitDecrypt"; -import { TransitEncryptPage } from "./pages/Transit/TransitEncrypt"; -import { TransitRewrapPage } from "./pages/Transit/TransitRewrap"; -import { TransitViewPage } from "./pages/Transit/TransitView"; -import { TransitViewSecretPage } from "./pages/Transit/TransitViewSecret"; -import { UnsealPage } from "./pages/Unseal"; import { getObjectKeys } from "./utils"; /* eslint-disable */ import { PageType } from "z-pagerouter"; /* eslint-enable */ +type importType = Promise<{ + default: { new (...args: unknown[]): Page }; +}>; + type pagesList = { - [key: string]: Page; + [key: string]: importType; }; export const allPages: pagesList = { - HOME: new HomePage(), - ME: new MePage(), - TOTP: new TOTPViewPage(), - NEW_TOTP: new NewTOTPPage(), - LOGIN: new LoginPage(), - SET_VAULT_URL: new SetVaultURLPage(), - UNSEAL: new UnsealPage(), - SET_LANGUAGE: new SetLanguagePage(), - TRANSIT_NEW_KEY: new NewTransitKeyPage(), - TRANSIT_VIEW: new TransitViewPage(), - TRANSIT_VIEW_SECRET: new TransitViewSecretPage(), - TRANSIT_ENCRYPT: new TransitEncryptPage(), - TRANSIT_DECRYPT: new TransitDecryptPage(), - TRANSIT_REWRAP: new TransitRewrapPage(), - KEY_VALUE_VIEW: new KeyValueViewPage(), - KEY_VALUE_SECRET: new KeyValueSecretPage(), - KEY_VALUE_VERSIONS: new KeyValueVersionsPage(), - KEY_VALUE_NEW_SECRET: new KeyValueNewPage(), - KEY_VALUE_DELETE: new KeyValueDeletePage(), - KEY_VALUE_SECRET_EDIT: new KeyValueSecretEditPage(), - PW_GEN: new PwGenPage(), - NEW_SECRETS_ENGINE: new NewSecretsEnginePage(), - NEW_KV_ENGINE: new NewKVEnginePage(), - NEW_TOTP_ENGINE: new NewTOTPEnginePage(), - NEW_TRANSIT_ENGINE: new NewTransitEnginePage(), + HOME: import("./pages/Home"), + ME: import("./pages/Me"), + TOTP: import("./pages/TOTP/TOTPView"), + NEW_TOTP: import("./pages/TOTP/NewTOTP"), + LOGIN: import("./pages/Login"), + SET_VAULT_URL: import("./pages/SetVaultURL"), + UNSEAL: import("./pages/Unseal"), + SET_LANGUAGE: import("./pages/SetLanguage"), + TRANSIT_NEW_KEY: import("./pages/Transit/NewTransitKey"), + TRANSIT_VIEW: import("./pages/Transit/TransitView"), + TRANSIT_VIEW_SECRET: import("./pages/Transit/TransitViewSecret"), + TRANSIT_ENCRYPT: import("./pages/Transit/TransitEncrypt"), + TRANSIT_DECRYPT: import("./pages/Transit/TransitDecrypt"), + TRANSIT_REWRAP: import("./pages/Transit/TransitRewrap"), + KEY_VALUE_VIEW: import("./pages/KeyValue/KeyValueView"), + KEY_VALUE_SECRET: import("./pages/KeyValue/KeyValueSecret"), + KEY_VALUE_VERSIONS: import("./pages/KeyValue/KeyValueVersions"), + KEY_VALUE_NEW_SECRET: import("./pages/KeyValue/KeyValueNew"), + KEY_VALUE_DELETE: import("./pages/KeyValue/KeyValueDelete"), + KEY_VALUE_SECRET_EDIT: import("./pages/KeyValue/KeyValueSecretsEdit"), + PW_GEN: import("./pages/PwGen"), + NEW_SECRETS_ENGINE: import("./pages/NewSecretsEngine"), + NEW_KV_ENGINE: import("./pages/NewEngines/NewKVEngine"), + NEW_TOTP_ENGINE: import("./pages/NewEngines/NewTOTPEngine"), + NEW_TRANSIT_ENGINE: import("./pages/NewEngines/NewTransitEngine"), }; - // This should implement all o PageListType class PageList { constructor(pages: pagesList) { @@ -74,7 +52,7 @@ class PageList { return getObjectKeys(this.pages); } async getPage(pageID: string): Promise { - return this.pages[pageID]; + return new (await this.pages[pageID]).default(); } } diff --git a/src/pages/Home.ts b/src/pages/Home.ts index b9edc6a..e28001d 100644 --- a/src/pages/Home.ts +++ b/src/pages/Home.ts @@ -134,3 +134,5 @@ export class HomePage extends Page { return i18next.t("home_page_title"); } } + +export { HomePage as default }; diff --git a/src/pages/KeyValue/KeyValueDelete.ts b/src/pages/KeyValue/KeyValueDelete.ts index 1c34e10..381230f 100644 --- a/src/pages/KeyValue/KeyValueDelete.ts +++ b/src/pages/KeyValue/KeyValueDelete.ts @@ -55,3 +55,5 @@ export class KeyValueDeletePage extends Page { return i18next.t("kv_delete_title"); } } + +export { KeyValueDeletePage as default }; diff --git a/src/pages/KeyValue/KeyValueNew.ts b/src/pages/KeyValue/KeyValueNew.ts index 93ecd41..e877107 100644 --- a/src/pages/KeyValue/KeyValueNew.ts +++ b/src/pages/KeyValue/KeyValueNew.ts @@ -90,3 +90,4 @@ export class KeyValueNewPage extends Page { return i18next.t("kv_new_title"); } } +export { KeyValueNewPage as default }; diff --git a/src/pages/KeyValue/KeyValueSecret.ts b/src/pages/KeyValue/KeyValueSecret.ts index e19024a..e2c4f78 100644 --- a/src/pages/KeyValue/KeyValueSecret.ts +++ b/src/pages/KeyValue/KeyValueSecret.ts @@ -186,3 +186,5 @@ export class KeyValueSecretPage extends Page { return i18next.t("kv_secret_title"); } } + +export { KeyValueSecretPage as default }; diff --git a/src/pages/KeyValue/KeyValueSecretsEdit.ts b/src/pages/KeyValue/KeyValueSecretsEdit.ts index 52e8b5f..3baf5de 100644 --- a/src/pages/KeyValue/KeyValueSecretsEdit.ts +++ b/src/pages/KeyValue/KeyValueSecretsEdit.ts @@ -87,3 +87,4 @@ export class KeyValueSecretEditPage extends Page { return i18next.t("kv_sec_edit_title"); } } +export { KeyValueSecretEditPage as default }; diff --git a/src/pages/KeyValue/KeyValueVersions.ts b/src/pages/KeyValue/KeyValueVersions.ts index bbd15de..3500ecf 100644 --- a/src/pages/KeyValue/KeyValueVersions.ts +++ b/src/pages/KeyValue/KeyValueVersions.ts @@ -54,3 +54,5 @@ export class KeyValueVersionsPage extends Page { return i18next.t("kv_sec_versions_title"); } } + +export { KeyValueVersionsPage as default }; diff --git a/src/pages/KeyValue/KeyValueView.ts b/src/pages/KeyValue/KeyValueView.ts index 71f34ba..5a77cc9 100644 --- a/src/pages/KeyValue/KeyValueView.ts +++ b/src/pages/KeyValue/KeyValueView.ts @@ -104,3 +104,5 @@ export class KeyValueViewPage extends Page { return i18next.t("kv_view_title"); } } + +export { KeyValueViewPage as default }; diff --git a/src/pages/Login.ts b/src/pages/Login.ts index b588e85..6dc7f1c 100644 --- a/src/pages/Login.ts +++ b/src/pages/Login.ts @@ -174,3 +174,5 @@ export class LoginPage extends Page { return i18next.t("log_in_title"); } } + +export { LoginPage as default }; diff --git a/src/pages/Me.ts b/src/pages/Me.ts index b63e9ab..d9f7b1c 100644 --- a/src/pages/Me.ts +++ b/src/pages/Me.ts @@ -98,3 +98,5 @@ export class MePage extends Page { return i18next.t("me_page_title"); } } + +export { MePage as default }; diff --git a/src/pages/NewEngines/NewKVEngine.ts b/src/pages/NewEngines/NewKVEngine.ts index 306c6dc..be30aed 100644 --- a/src/pages/NewEngines/NewKVEngine.ts +++ b/src/pages/NewEngines/NewKVEngine.ts @@ -85,3 +85,5 @@ export class NewKVEnginePage extends Page { return i18next.t("new_kv_engine_title"); } } + +export { NewKVEnginePage as default }; diff --git a/src/pages/NewEngines/NewTOTPEngine.ts b/src/pages/NewEngines/NewTOTPEngine.ts index 382064d..1c5ec7d 100644 --- a/src/pages/NewEngines/NewTOTPEngine.ts +++ b/src/pages/NewEngines/NewTOTPEngine.ts @@ -67,3 +67,5 @@ export class NewTOTPEnginePage extends Page { return i18next.t("new_totp_engine_title"); } } + +export { NewTOTPEnginePage as default }; diff --git a/src/pages/NewEngines/NewTransitEngine.ts b/src/pages/NewEngines/NewTransitEngine.ts index 0566932..de72b62 100644 --- a/src/pages/NewEngines/NewTransitEngine.ts +++ b/src/pages/NewEngines/NewTransitEngine.ts @@ -67,3 +67,5 @@ export class NewTransitEnginePage extends Page { return i18next.t("new_transit_engine_title"); } } + +export { NewTransitEnginePage as default }; diff --git a/src/pages/NewSecretsEngine.ts b/src/pages/NewSecretsEngine.ts index cc0776f..57171e7 100644 --- a/src/pages/NewSecretsEngine.ts +++ b/src/pages/NewSecretsEngine.ts @@ -45,3 +45,5 @@ export class NewSecretsEnginePage extends Page { return i18next.t("new_secrets_engine_title"); } } + +export { NewSecretsEnginePage as default }; diff --git a/src/pages/PwGen.ts b/src/pages/PwGen.ts index b72e48f..c9483fe 100644 --- a/src/pages/PwGen.ts +++ b/src/pages/PwGen.ts @@ -146,3 +146,5 @@ export class PwGenPage extends Page { return i18next.t("password_generator_title"); } } + +export { PwGenPage as default }; diff --git a/src/pages/SetLanguage.ts b/src/pages/SetLanguage.ts index 7d5d0ef..6441cac 100644 --- a/src/pages/SetLanguage.ts +++ b/src/pages/SetLanguage.ts @@ -67,3 +67,5 @@ export class SetLanguagePage extends Page { return i18next.t("set_language_title"); } } + +export { SetLanguagePage as default }; diff --git a/src/pages/SetVaultURL.ts b/src/pages/SetVaultURL.ts index e4d8d83..bf44e36 100644 --- a/src/pages/SetVaultURL.ts +++ b/src/pages/SetVaultURL.ts @@ -52,3 +52,5 @@ export class SetVaultURLPage extends Page { return "Set Vault URL"; } } + +export { SetVaultURLPage as default }; diff --git a/src/pages/TOTP/NewTOTP.ts b/src/pages/TOTP/NewTOTP.ts index 17623b9..0351f79 100644 --- a/src/pages/TOTP/NewTOTP.ts +++ b/src/pages/TOTP/NewTOTP.ts @@ -114,3 +114,5 @@ export class NewTOTPPage extends Page { return i18next.t("totp_new_title"); } } + +export { NewTOTPPage as default }; diff --git a/src/pages/TOTP/TOTPView.ts b/src/pages/TOTP/TOTPView.ts index 7ec65ae..9739314 100644 --- a/src/pages/TOTP/TOTPView.ts +++ b/src/pages/TOTP/TOTPView.ts @@ -113,3 +113,5 @@ export class TOTPViewPage extends Page { return i18next.t("totp_view_title"); } } + +export { TOTPViewPage as default }; diff --git a/src/pages/Transit/NewTransitKey.ts b/src/pages/Transit/NewTransitKey.ts index 362a4fc..d88e6be 100644 --- a/src/pages/Transit/NewTransitKey.ts +++ b/src/pages/Transit/NewTransitKey.ts @@ -95,3 +95,5 @@ export class NewTransitKeyPage extends Page { return i18next.t("transit_new_key_title"); } } + +export { NewTransitKeyPage as default }; diff --git a/src/pages/Transit/TransitDecrypt.ts b/src/pages/Transit/TransitDecrypt.ts index b2c53c2..1ded3e3 100644 --- a/src/pages/Transit/TransitDecrypt.ts +++ b/src/pages/Transit/TransitDecrypt.ts @@ -122,3 +122,5 @@ export class TransitDecryptPage extends Page { return i18next.t("transit_decrypt_title"); } } + +export { TransitDecryptPage as default }; diff --git a/src/pages/Transit/TransitEncrypt.ts b/src/pages/Transit/TransitEncrypt.ts index 3f02c1e..cd45dc9 100644 --- a/src/pages/Transit/TransitEncrypt.ts +++ b/src/pages/Transit/TransitEncrypt.ts @@ -120,3 +120,5 @@ export class TransitEncryptPage extends Page { return i18next.t("transit_encrypt_title"); } } + +export { TransitEncryptPage as default }; diff --git a/src/pages/Transit/TransitRewrap.ts b/src/pages/Transit/TransitRewrap.ts index 426e4a4..88f3efb 100644 --- a/src/pages/Transit/TransitRewrap.ts +++ b/src/pages/Transit/TransitRewrap.ts @@ -113,3 +113,5 @@ export class TransitRewrapPage extends Page { return i18next.t("transit_rewrap_title"); } } + +export { TransitRewrapPage as default }; diff --git a/src/pages/Transit/TransitView.ts b/src/pages/Transit/TransitView.ts index 7450d46..ad87d94 100644 --- a/src/pages/Transit/TransitView.ts +++ b/src/pages/Transit/TransitView.ts @@ -78,3 +78,5 @@ export class TransitViewPage extends Page { return i18next.t("transit_view_title"); } } + +export { TransitViewPage as default }; diff --git a/src/pages/Transit/TransitViewSecret.ts b/src/pages/Transit/TransitViewSecret.ts index 24dce71..3a1aea9 100644 --- a/src/pages/Transit/TransitViewSecret.ts +++ b/src/pages/Transit/TransitViewSecret.ts @@ -66,3 +66,5 @@ export class TransitViewSecretPage extends Page { return i18next.t("transit_view_secret_title"); } } + +export { TransitViewSecretPage as default }; diff --git a/src/pages/Unseal.ts b/src/pages/Unseal.ts index 139f52e..bf9ff50 100644 --- a/src/pages/Unseal.ts +++ b/src/pages/Unseal.ts @@ -192,3 +192,5 @@ export class UnsealPage extends Page { return i18next.t("unseal_vault_text"); } } + +export { UnsealPage as default }; diff --git a/tsconfig.json b/tsconfig.json index 1285d12..b19f4e0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,7 @@ "outDir": "./dist/", "noImplicitAny": false, "allowSyntheticDefaultImports": true, - "module": "es6", + "module": "es2020", "target": "es2019", "strictBindCallApply": true, "noImplicitThis": true, diff --git a/webpack.config.js b/webpack.config.js index 3c04412..6096886 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -22,7 +22,8 @@ module.exports = { entry: './src/main.ts', output: { path: path.resolve(__dirname, 'dist'), - filename: 'bundle.js', + chunkFilename: '[name].js', + filename: '[name].[contenthash].js', }, stats: { preset: VERBOSE ? "detailed" : "normal", @@ -44,7 +45,11 @@ module.exports = { modules: ['node_modules'], extensions: ['.tsx', '.ts', '.js', ".mjs"], }, - + optimization: { + splitChunks: { + chunks: 'all', + }, + }, module: { rules: [ {