From feef1b236b3bf3f6976a0dc7818410ac47dc66ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20G=C3=B6rg=C3=BCl=C3=BC?= Date: Sun, 17 Mar 2024 03:37:38 +0300 Subject: [PATCH] style: minor code quality changes --- .env | 10 +++++----- create-firebase-json.js | 5 ++--- nuxt.config.js | 22 +++++++++++----------- plugins/firebase.client.js | 37 ++++++++++++++++--------------------- tsconfig.json | 3 +-- 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/.env b/.env index 85f79d56..6386551b 100755 --- a/.env +++ b/.env @@ -1,17 +1,16 @@ -# YOU MUST RESTART THE APP IF YOU MAKE CHANGES IN THIS FILE +SERVER_HOST="localhost" +SERVER_PORT=3000 -HOST="localhost" -PORT=3000 +EMULATOR_PORT=8026 APP_URL="https://vergihesaplayici.com" APP_NAME="Vergi Hesaplayıcı" APP_PRIMARY_COLOR="#88df95" APP_SECONDARY_COLOR="#00262c" -# Source: https://www.csgb.gov.tr/asgari-ucret +# https://www.csgb.gov.tr/asgari-ucret MINIMUM_WAGE=17002.12 -# These are not sensitive. So, it's OK to show it publicly. FIREBASE_API_KEY="AIzaSyD6VJhwtSsEpkLx2a-WsnhfU1rjUKz2DtA" FIREBASE_AUTH_DOMAIN="vergihesaplayici.firebaseapp.com" FIREBASE_DATABASE_URL="https://vergihesaplayici.firebaseio.com" @@ -20,4 +19,5 @@ FIREBASE_STORAGE_BUCKET="vergihesaplayici.appspot.com" FIREBASE_MESSAGING_SENDER_ID="779771263802" FIREBASE_APP_ID="1:779771263802:web:3786e5cc27855757536e03" FIREBASE_MEASUREMENT_ID="G-2HW9TT5V7E" + RECAPTCHA_V3_PUBLIC_KEY="6Ld-dw0eAAAAAAJU0zFz1OrzbgRPbx66kwp9BCHl" diff --git a/create-firebase-json.js b/create-firebase-json.js index ff61bb50..8b5d78aa 100644 --- a/create-firebase-json.js +++ b/create-firebase-json.js @@ -77,7 +77,6 @@ const redirections301 = [ ] ]; -// create-csp-nonce-txt.js const cspNonce = fs.readFileSync(path.join(__dirname, "csp-nonce.txt"), { encoding: "utf-8" }); const firebaseJson = { @@ -117,7 +116,7 @@ const firebaseJson = { "https://www.google.com/recaptcha/", "https://www.gstatic.com/recaptcha/", "https://www.googletagmanager.com", - "https://cdn.jsdelivr.net" // For Workbox in static/sw.js + "https://cdn.jsdelivr.net" // For Workbox in `static/sw.js` ], "frame-src": [ "'self'", @@ -180,7 +179,7 @@ const firebaseJson = { }, emulators: { hosting: { - port: 8026 + port: process.env.EMULATOR_PORT }, ui: { enabled: true diff --git a/nuxt.config.js b/nuxt.config.js index 33c59ee4..712d7f9a 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -2,7 +2,7 @@ import fs from "fs"; import path from "path"; import tr from "vuetify/es5/locale/tr"; -const cspNonceTxtPath = path.join(__dirname, "csp-nonce.txt"); +const cspNonceTxtPath = path.resolve(__dirname, "csp-nonce.txt"); const isCspNonceTxtExists = fs.existsSync(cspNonceTxtPath); const cspNonce = isCspNonceTxtExists ? fs.readFileSync(cspNonceTxtPath, { encoding: "utf-8" }) : @@ -15,8 +15,8 @@ export default { fallback: "404.html" }, server: { - host: process.env.HOST, - port: process.env.PORT + host: process.env.SERVER_HOST, + port: process.env.SERVER_PORT }, head: { titleTemplate: `%s - ${process.env.APP_NAME}`, @@ -54,7 +54,7 @@ export default { ], link: [ { - hid: "shortcut-icon", // Override @nuxtjs/pwa + hid: "shortcut-icon", // Overriding `@nuxtjs/pwa` rel: "icon", href: "/favicon.svg", type: "image/svg+xml" @@ -91,8 +91,8 @@ export default { "@nuxtjs/svg", "@nuxtjs/pwa", "@/modules/append-canonical-to-head.js", - "@/modules/append-calculator-presets-to-sitemap.js", // Must be before "@nuxtjs/sitemap" - "@/modules/append-articles-to-sitemap.js", // Must be before "@nuxtjs/sitemap" + "@/modules/append-calculator-presets-to-sitemap.js", // It must be before `@nuxtjs/sitemap` + "@/modules/append-articles-to-sitemap.js", // It must be before `@nuxtjs/sitemap` "@nuxtjs/sitemap" ], router: { @@ -105,8 +105,7 @@ export default { ignoreOrder: true }, html: { - minify: { - // https://stackoverflow.com/a/64739284/7841581 + minify: { // https://stackoverflow.com/a/64739284/7841581 collapseBooleanAttributes: true, decodeEntities: true, minifyCSS: true, @@ -117,7 +116,7 @@ export default { trimCustomFragments: true, useShortDoctype: true, preserveLineBreaks: false, - collapseWhitespace: false // "true" makes v-main's padding-left twice the width of v-navigation-drawer when it's builded + collapseWhitespace: true } } }, @@ -130,7 +129,7 @@ export default { ] }, plugins: [ - "@/plugins/firebase.client.js", + process.env.NODE_ENV ? "@/plugins/firebase.client.js" : null, "@/plugins/vue-clipboard2.client.js", "@/plugins/vue-html2canvas.client.js", "@/plugins/number-directive.client.js" @@ -198,7 +197,8 @@ export default { } }, - // Disable unused Nuxt features + // Disable unused Nuxt features for a small bundle size. + // This is not documented by Nuxt. loadingIndicator: false, fetch: { client: false diff --git a/plugins/firebase.client.js b/plugins/firebase.client.js index 7c562489..5b886bb7 100644 --- a/plugins/firebase.client.js +++ b/plugins/firebase.client.js @@ -1,31 +1,26 @@ -/* eslint-disable import/no-mutable-exports */ import { initializeApp } from "firebase/app"; import { initializeAnalytics } from "firebase/analytics"; import { initializePerformance } from "firebase/performance"; import { initializeAppCheck, ReCaptchaV3Provider } from "firebase/app-check"; -let firebaseApp = null; +const firebaseApp = initializeApp({ + apiKey: process.env.FIREBASE_API_KEY, + authDomain: process.env.FIREBASE_AUTH_DOMAIN, + databaseURL: process.env.FIREBASE_DATABASE_URL, + projectId: process.env.FIREBASE_PROJECT_ID, + storageBucket: process.env.FIREBASE_STORAGE_BUCKET, + messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID, + appId: process.env.FIREBASE_APP_ID, + measurementId: process.env.FIREBASE_MEASUREMENT_ID +}); -if (process.env.NODE_ENV === "production") { - firebaseApp = initializeApp({ - apiKey: process.env.FIREBASE_API_KEY, - authDomain: process.env.FIREBASE_AUTH_DOMAIN, - databaseURL: process.env.FIREBASE_DATABASE_URL, - projectId: process.env.FIREBASE_PROJECT_ID, - storageBucket: process.env.FIREBASE_STORAGE_BUCKET, - messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID, - appId: process.env.FIREBASE_APP_ID, - measurementId: process.env.FIREBASE_MEASUREMENT_ID - }); +initializeAnalytics(firebaseApp); - initializeAnalytics(firebaseApp); +initializePerformance(firebaseApp); - initializePerformance(firebaseApp); - - initializeAppCheck(firebaseApp, { - provider: new ReCaptchaV3Provider(process.env.RECAPTCHA_V3_PUBLIC_KEY), - isTokenAutoRefreshEnabled: true - }); -} +initializeAppCheck(firebaseApp, { + provider: new ReCaptchaV3Provider(process.env.RECAPTCHA_V3_PUBLIC_KEY), + isTokenAutoRefreshEnabled: true +}); export default firebaseApp; diff --git a/tsconfig.json b/tsconfig.json index 6c20f19e..45fec3e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,6 @@ "include": [ "domain/**/db/*.js", "domain/**/*.page-def.js", - "types/*.d.js", - "page-def/*.page-def.js" + "types/*.d.js" ] }