Search code examples
parceljs

Remove console.logs using Parcel?


Trying to remove console.log statements using Parcel.

Here's package.json:

{
  "dependencies": {
    "jquery": "^3.3.1",
    "select2": "^4.0.6-rc.1"
  },
  "devDependencies": {
    "cssnano": "^4.1.9",
    "parcel-plugin-web-extension": "^1.5.1"
  }
}

The Parcel docs on transformations says:

Parcel automatically runs these transforms when it finds a configuration file (e.g. .babelrc, .postcssrc) in a module.

I've added this .uglifyrc to my project root:

{
  "compress": {
    "pure_funcs": ["console.log"]
  }
}

But when I run parcel build src/index.js none of the console.log statements are removed from the dist/index.js.

Think I'm missing something obvious here. Thanks!

Edit: looks like Parcel supported Uglify at some point and may still, though per @MTCoster's comment the docs don't indicate that it does.

So I replaced my .uglifyrc file with this .babelrc file and console.log calls are now gone:

{
  "plugins": ["transform-remove-console"]
}

Solution

  • Parcel doesn't have documented support of Uglifier. Use Babel instead:

    Replace .uglifyrc file with this .babelrc file and console.log calls are now gone:

    {
      "plugins": ["transform-remove-console"]
    }