Unverified Commit 76215189 authored by Dannon's avatar Dannon Committed by GitHub
Browse files

Merge pull request #16372 from ElectronicBlueberry/prod-debugging

[23.1] Disable console instead of dropping
parents a8fc236d 3da7acec
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
/**
 * This module disables the console in production,
 * and adds the ability to toggle console logging
 * using the global functions
 * enableDebugging() and disableDebugging()
 */
import { useLocalStorage } from "@vueuse/core";
import { watch } from "vue";

export function overrideProductionConsole() {
    let defaultEnabled = true;

    if (process.env.NODE_ENV == "production") {
        defaultEnabled = false;
    }

    const isEnabled = useLocalStorage("console-debugging-enabled", defaultEnabled);

    let storedConsole = null;

    const disableConsole = () => {
        storedConsole = console;
        // eslint-disable-next-line no-global-assign
        console = {};
        Object.keys(storedConsole).forEach((key) => {
            console[key] = () => {};
        });
    };

    const enableConsole = () => {
        if (storedConsole) {
            // eslint-disable-next-line no-global-assign
            console = storedConsole;
        }
    };

    watch(
        () => isEnabled.value,
        (enabled) => {
            if (enabled) {
                enableConsole();
            } else {
                disableConsole();
            }
        },
        { immediate: true }
    );

    window.enableDebugging = () => {
        isEnabled.value = true;
    };

    window.disableDebugging = () => {
        isEnabled.value = false;
    };
}
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ import "./publicPath";
// Default Font
import "@fontsource/atkinson-hyperlegible";

import { overrideProductionConsole } from "./console";

// Module exports appear as objects on window.config in the browser
export { standardInit } from "./standardInit";
export { initializations$, addInitialization, prependInitialization, clearInitQueue } from "./initQueue";
@@ -21,6 +23,8 @@ export { getRootFromIndexLink } from "./getRootFromIndexLink";
// Client-side configuration variables (based on environment)
import config from "config";

overrideProductionConsole();

if (!config.testBuild === true) {
    console.log(`Galaxy Client '${config.name}' build, dated ${config.buildTimestamp}`);
    console.debug("Full configuration:", config);
+1 −10
Original line number Diff line number Diff line
@@ -37,16 +37,7 @@ module.exports = (env = {}, argv = {}) => {
    if (targetEnv == "production") {
        minimizations = {
            minimize: true,
            minimizer: [
                new TerserPlugin({
                    terserOptions: {
                        compress: {
                            drop_console: true,
                        },
                    },
                }),
                new CssMinimizerPlugin(),
            ],
            minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
        };
    } else {
        minimizations = {