disable console instead of dropping

This commit is contained in:
Laila Los
2023-07-06 06:40:57 +02:00
parent a8fc236d8e
commit 3da7acec65
3 changed files with 61 additions and 10 deletions
+56
View File
@@ -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
View File
@@ -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
View File
@@ -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 = {