mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-19 10:51:34 +08:00
disable console instead of dropping
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user