Remove Console Loggers
Enabled Avoid shipping console.logs and debuggers into production.
By default, your application will allow log all activity in the browser when you write console.log(user)
that can lead to some unwanted information leakage.
ℹ Read more about it here.
Fortunately, nuxt-security
module removes both log
and debug
console outputs by default so your application is not leaking this information.
This functionality is delivered by the amazing Vite Plugin by Talljack that you can check out here.
import type { FilterPattern } from '@rollup/pluginutils'
export interface Options {
/**
* don't remove console.log and debugger these module
*
* @default []
*/
external?: Array<string>
/**
* remove console type of these module
*
* @default ['log']
*/
consoleType?: Array<'log' | 'warn' | 'error' | 'info' | 'debug'>
/**
* Rules to include transforming target.
*
* @default [/\.[jt]sx?$/, /\.vue\??/]
*/
include?: FilterPattern
/**
* Rules to exclude transforming target.
*
* @default [/node_modules/, /\.git/]
*/
exclude?: FilterPattern
}
If you would like to add some custom functionality to it, you can do so by doing the following:
nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-security'],
security: {
removeLoggers: {
external: [],
consoleType: ['log', 'debug'],
include: [/\.[jt]sx?$/, /\.vue\??/],
exclude: [/node_modules/, /\.git/]
}
}
})
However, if you prefer not to have this, you can always disable this functionality from the module configuration (which is not recommended but possible) like the following:
nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-security'],
security: {
removeLoggers: false
}
})