question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow falsy values in plugins array

See original GitHub issue

Do you want to request a feature or report a bug? Feature.

What is the current behavior? passing undefined, null, or false in a plugins array results in the following error: TypeError: arguments[i].apply is not a function

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

If this is a feature request, what is motivation or use case for changing the behavior? Allowing falsy values in the plugins array would allow much simpler plugin definition:

plugins: [
    isProd ? new webpack.optimize.UglifyJsPlugin() : null,
    //or
    isDev && new someOtherPlugin(),
 ]

There are other ways to accomplish this right now, but all of them are clunkier, more verbose, and/or more repetitive. Case in point: The noop-webpack-plugin exists to enable this pattern, but it shouldn’t have to exist at all.

I’m happy to submit a PR for it when I get around to it, but won’t be hurt if anyone else would like to beat me to it.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

I installed webpack 3.5.3 to verify that this is still not supported before filing the issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

25reactions
michael-ciniawskycommented, Aug 11, 2017

Just

webpack.config.js

plugins: [
  env === 'production' : new Plugin() : false,
].filter(Boolean)

?

2reactions
alexander-akaitcommented, Feb 10, 2018

Yes, close issue, thanks everyone!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Filter Out Falsy Values From A JavaScript Array ...
This article shows you how you can use the Boolean constructor function to filter out all falsy values from an array.
Read more >
Webpack: How can we *conditionally* use a plugin?
I push onto the plugins array given a condition in my webpack.config.js ... value to webpack config and then conditionally load plugins.
Read more >
Guide to Configuring Plug-ins - Apache Maven
The key type must always be String . In contrast to value objects and collections/arrays there is no string coercion defined for maps,...
Read more >
How to Remove Falsy Values from an Array in JavaScript
Before we use a for loop to remove falsy values from an array, let's first learn about the difference between falsy and truthy...
Read more >
JavaScript: Remove falsey values from a given array
Use Array.prototype.filter() to filter out falsy values (false, null, 0, "", undefined, and NaN). Sample Solution:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found