Code Monkey home page Code Monkey logo

unplugin-remove's Introduction

unplugin-remove

Auto remove console[log|warn|error|info|debug] and debugger in production mode.

Install

pnpm i unplugin-remove -D

or

yarn add unplugin-remove -D
Vite
// vite.config.ts
import viteRemove from 'unplugin-remove/vite'

export default defineConfig({
  plugins: [
    viteRemove({ /* options */ }),
  ],
})

Example: playground/


Rollup
// rollup.config.js
import rollupRemove from 'unplugin-remove/rollup'

export default {
  plugins: [
    rollupRemove({ /* options */ }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    process.env.MODE === 'production' ? require('unplugin-remove/webpack')({ /* options */ }) : null
  ].filter(Boolean)
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'
import esbuildRemove from 'unplugin-remove/esbuild'

build({
  plugins: [esbuildRemove()],
})


Configuration

The following show the default values of the configuration

Remove({
  // don't remove console.([log|warn|error|info|debug]) and debugger these module
  external: [],

  // remove console type of these module
  // enum: ['log', 'warn', 'error', 'info', 'debug']
  consoleType: ['log'],

  // filters for transforming targets
  include: [/\.[jt]sx?$/, /\.vue\??/],
  exclude: [/node_modules/, /\.git/],
})

License

MIT License © 2022-PRESENT Talljack

unplugin-remove's People

Contributors

dependabot[bot] avatar talljack avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

unplugin-remove's Issues

v0.1.5 is not released to npm

This is the current version that can be installed on npm, but according to the github commit, the current version should be v0.1.5

截圖 2023-11-07 晚上11 02 33

Deprecated dependency in magic-string

Hey Buddy,

One of the users of Nuxt Security (which uses unplugin-remove under the hood for removing loggers functionality) reported that one of the dependencies of nuxt-security - unplugin-remove and more specifically magic-string has a deprecated dependency and it results in a warning.

More details Baroshem/nuxt-security#342 (comment)

I would really appreciate if you could take a look at it as using deprecated dependencies should be avoided in general.

If you need any assistance from my side, please just let me know and I will do my best to help :)

ERROR Unexpected token (Note that you need plugins to import files that are not JavaScript)

Hi,

Another issue was recently reported in Nuxt-Security : Baroshem/nuxt-security#343

OP is using the following syntax:

false && console.log('.....')

Which results in ERROR Unexpected token (Note that you need plugins to import files that are not JavaScript)

I guess removing the console.log('.....') part results in invalid JavaScript:

false &&

Suggestion: instead of removing the console.log('.....') part, you could maybe replace it with a noop such as (() => {})()

Plugin can cause build failure with Vite

Bug initially reported in Nuxt Security Baroshem/nuxt-security#306

Please see repro and details there

The bug happens when console.log is removed from a lambda void-returning arrow-syntax function with a single instruction.

I guess the parser is a bit too aggressive and transforms :

const test = () => console.log('Test')

Into

const test = () =>

Which is invalid Javascript

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.