0

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"]
}
kareem
  • 690
  • 1
  • 9
  • 20
  • From the linked page: “*You can transform JavaScript using Babel, CSS using PostCSS, and HTML using PostHTML.*” - Nothing in there about uglify – MTCoster Feb 13 '19 at 21:59
  • Interesting, good catch. I found the Uglifier stuff in old Parcel GH Issues. Maybe they dropped support. Will try Babel. Thanks! – kareem Feb 13 '19 at 23:26

1 Answers1

4

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"]
}
kareem
  • 690
  • 1
  • 9
  • 20