The Quasar application does not eliminate console.log() statements during production builds

I've been facing difficulties in removing the console.log() from my Quasar app for production builds.

Despite checking solutions on various platforms like StackOverflow, Quasar forums, and GitHub, I am still struggling to eliminate the console.log statements and warnings.

I have experimented with different configurations in the

quasar.conf.js

module.exports = function (api) {
    build: {
      uglifyOptions: {
        compress: { drop_console: true },
      },
      devtool: 'source-map',
      sourceMap: true,      
      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })
      }
    }
}
module.exports = function (api) {
    build: {
      uglifyOptions: {
        compress: { drop_console: true },
      }
    }
}
module.exports = function (api) {
    build: {
      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })
      }
    }
}

Regardless of trying these methods, the resulting output remains the same.

quasar inspect -c build -p optimization.minimizer

output

[
  TerserPlugin {
    options: {
      test: /\.[cm]?js(\?.*)?$/i {
        [lastIndex]: 0
      },
      minimizer: {
        options: {
          compress: {
            drop_console: true,
            drop_debugger: true
          }
        }
      }
    }
]

eslintrc.js

module.exports = {
  rules: {
    // allow async-await
    'generator-star-spacing': 'off',
    // allow paren-less arrow functions
    'arrow-parens': 'off',
    'one-var': 'off',
    'optional-chaning': 0,
    'import/first': 'off',
    'import/named': 'error',
    'import/namespace': 'error',
    'import/default': 'error',
    'import/export': 'error',
    'import/extensions': 'off',
    'import/no-unresolved': 'off',
    'import/no-extraneous-dependencies': 'off',
    'prefer-promise-reject-errors': 'off',
    'vue/multi-word-component-names': 0,
    // allow debugger during development only
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  },
}

Answer №1

If anyone encounters a similar issue, I managed to solve it.

I had been utilizing node-polyfill and although I'm not entirely sure what it did, it prevented Terser from removing console statements.

Previous (Faulty version)

const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')

module.exports = function (api) {
    build: {

      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })

       chain.plugin('node-polyfill').use(new NodePolyfillPlugin())
      }
    }
}

Updated version

const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')

module.exports = function (api) {
    build: {
      chainWebpack(chain) {
        chain.optimization.minimizer('js').tap((args) => {
          args[0].terserOptions.compress.drop_console = true
          args[0].terserOptions.compress.drop_debugger = true
          return args
        })
       chain.plugin('node-polyfill').use(
         new NodePolyfillPlugin({
           excludeAliases: ['console'],
         }),
        )
      }
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Step-by-step guide on how to prioritize rendering the login page before the ngView in AngularJS in order to

As I begin my journey with Angular JS, I am eager to implement security measures in my application. My intention is to set up a log-in page as the default landing page for my single page application. Can anyone provide guidance or recommendations on how ...

Updating a value based on a changed range slider in VueJS

My goal is to update the value once the Slider has been dragged. Below is the code I am currently using: <div id="app"> <vue-range-slider v-model="rangeSlider" v-bind="options"></vue-range-slider> <p class="mt-50">Value: { ...

The reactivity of a Vue.js computed property diminishes when it is transmitted through an event handler

Within my main application, I've implemented a Modal component that receives content via an event whenever a modal needs to be displayed. The Modal content consists of a list with an associated action for each item, such as "select" or "remove": Vue. ...

I'm looking for a way to create a Redux thunk action creator that will return a promise. How

In my code, I have a primary thunk that is triggered by a button click. Within this thunk, I need to invoke another thunk and ensure it completes before proceeding. The second thunk returns a promise. Below is an excerpt of the code in question: export f ...

Issue found in React Js test - TypeError: source.on does not exist as a function

I'm encountering an issue with my post request using multipart/form-data. Everything runs smoothly, except for the tests which are failing. When running the tests, I encounter an error message: TypeError: source.on is not a function. This is the code ...

npm was unable to locate the module named '../lib/npm.js'

Struggling with setting up nodejs and npm on a CentOS 7 machine without internet access. I tried copying the node-v6.2.1-linux-x64 folder with some lib modules to the machine, but it's throwing an error saying Error: Cannot find module '../lib/np ...

What is the procedure for iterating through the square brackets of a JSON array?

Here's the data I have: $json_data_array = '[ { "id": 1, "value": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfd7cdffcbdacccb91dcd0d2">[email protected]</a>", ...

What steps can I take to ensure a JavaScript loading image is displayed until the entire page has finished loading?

Looking to implement a JavaScript loading image that displays until the page has fully loaded? I'm currently developing an online antivirus scanner and in need of help. I am trying to set up JavaScript to show a loading image while a file is being up ...

Issue with Select2: When using a remote select2 control, the tab key press does not allow for the selection of the highlighted

I have set up select2 to load ajax data into select2 based on the example provided in this link Load ajax data into select2. In the example, I can type text, use arrow keys to navigate, and then hit tab to select the highlighted item. However, in my case, ...

Methods to Maintain Consistent HTML Table Dimensions utilizing DOM

I am facing an issue with shuffling a table that contains images. The table has 4 columns and 2 rows. To shuffle the table, I use the following code: function sortTable() { // Conveniently getting the parent table let table = document.getElementById("i ...

Show and hide components in React by simply clicking on them

I'm looking to achieve the following: If the component is visible, clicking away from it should hide the component. If the component is hidden, clicking on it (or any area that it would occupy if visible) should show the component. Is there a way to ...

Exploring Alternative Methods for Serving Static HTML Files in an Express Server

Hey there, quick question for you. Let's say I have two static HTML files that I want to serve in Express - 'index.html' and 'contact.html'. I've been playing around with some basic Express code to get them served: const expr ...

Preserving color output while executing commands in NodeJS

My Grunt task involves shelling out via node to run "composer install". var done = this.async(); var exec = require('child_process').exec; var composer = exec( 'php bin/composer.phar install', function(error, stdout, stderr) { ...

The significance of having spaces in the PATH for npm

Attempting to set up gulp, but encountering the following error: module.js:471^throw err : cannot find module 'C:\c\Users\Joe's Steezy Laptop\AppData\Roaming\npm\node_modules\gulp-cli\bin\gul ...

Is there a versatile Node.js HTTP request module that is compatible with both server-side and browser-side development, particularly when packaged with Webpack?

Currently, I am searching for a request module that can operate seamlessly in both the Node.js server and the client when compiled with Webpack. The requirements are quite straightforward. I simply need to execute some basic HTTP Ajax requests such as get ...

Is it secure to use ES6 in Typescript with nodejs/koa?

As I transition to using TypeScript in a Node.js/koa project, I came across the need to modify the .tsconfig file to target ES6. Otherwise, an error message will appear stating: Generators are only available when targeting ECMAScript 6 or higher. // index ...

Upgrade the sorting icons in Vue tables 2

Currently, I am using vue tables 2 which by default utilizes glyphicons. However, I would like to incorporate material icons instead. I attempted to modify the span element to i and also tried adding innerText through JavaScript, but after compiling the ...

"Encountering issue with componentDidMount() not functioning as expected, despite debugger being

Hello everyone! This is my first time sharing something here, so I'm eager to hear your feedback on both how I've posted and the content itself. I've only been programming for 8 weeks now, so I'm sure there are plenty of mistakes in wha ...

Ways to emphasize a particular <li> element?

Currently, I am delving into the world of React and facing a challenge. I have been trying to solve the issue below: When fetching some JSON data, it appears in this format: [ { "answerOptions": [ "Answer A", "Answer B", ...

Merge multiple list groups into one with a single active selection using Bootstrap List group functionality

Currently, I am experimenting with merging Bootstrap's accordion and list group with JS behavior. My goal is to create a set of list groups where only one option can be active at a time within each accordion. <link rel="stylesheet" href="https:/ ...