Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.1] Disable console instead of dropping #16372

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions client/src/onload/console.js
@@ -0,0 +1,56 @@
/**
* 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 changes: 4 additions & 0 deletions client/src/onload/index.js
Expand Up @@ -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";
Expand All @@ -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);
Expand Down
11 changes: 1 addition & 10 deletions client/webpack.config.js
Expand Up @@ -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 = {
Expand Down