Utils

Remove Console Loggers

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, the Nuxt Security module removes all console outputs by default so your application is not leaking this information. Nuxt Security also removes all debugger statements from your code.

Options

This feature is enabled globally default.

You can disable the feature by setting removeLoggers: false:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-security'],

  security: {
    removeLoggers: false
  }
})

Alternative method - deprecated

By default when you set removeLoggers: true, Nuxt Security uses the native Vite features to remove statements.

In addition, Nuxt Security also supports an alternative method for removing console outputs, via the amazing unplugin-remove Vite Plugin by Talljack that you can check out here.

The unplugin-remove method is being deprecated and will be removed in a future release. Please note that unplugin-remove will not remove debugger statements from your code. ::If you want to use the unplugin-remove plugin method, pass an object to the removeLoggers configuration instead of passing true.
nuxt.config.ts
export default defineNuxtConfig({
  modules: ['nuxt-security'],

  security: {
    removeLoggers: {
      external: [],
      consoleType: ['log', 'debug'],
      include: [/\.[jt]sx?$/, /\.vue\??/],
      exclude: [/node_modules/, /\.git/]
    }
  }
})
The removeLoggers object can be configured with following values.
// https://github.com/Talljack/unplugin-remove/blob/main/src/types.ts
type RemoveOptions {
  /**
   * 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
}