6

As I got from the webpack cumbersome documentation here webpack -p will set

  1. --define process.env.NODE_ENV="'production'" for DefinePlugin
  2. --optimize-minimize flag that will include the TerserPlugin

As I got from the same documentation here webpack --mode=production will set

  1. --define process.env.NODE_ENV="'production'" for DefinePlugin
  2. TerserPlugin
  3. FlagDependencyUsagePlugin
  4. FlagIncludedChunksPlugin
  5. ModuleConcatenationPlugin
  6. NoEmitOnErrorsPlugin
  7. OccurrenceOrderPlugin
  8. SideEffectsFlagPlugin

(Bolded items are shared behaviour between the two different flags.)

Shall I consider --mode=production as a "full" version of -p? Some guides on the internet use -p, other use --mode=production and some even use both of them.

Also it would be great to know if --mode=production has any difference versus --mode production because for me both version work absolutely fine

Also, there is a thread here, that says that -p "Run commands in parallel." Is that a flag to node, that has the same name as -p for webpack?

I am using webpack ^4.41.2

fires3as0n
  • 421
  • 5
  • 13

1 Answers1

2

Shall I consider --mode=production as a "full" version of -p? Some guides on the internet use -p, other use --mode=production and some even use both of them.

According to the documentation under CLI > Shortcuts -p is analogous to --mode=production:

enter image description here

(Image of the docs taken from here: https://webpack.js.org/api/cli/#shortcuts)

So whether using one or the other (or both - but this is not recommended as may cause confusion to others), you should not see any difference in webpack's output.

You could confirm this by running webpack first with -p, noting the hashes of the output files, and then doing the same with --mode=production, and comparing the hashes.

Here is a quick test I ran using a single entry file index.js which just does console.log("HELLO"):

enter image description here

As you can see the hash for both cases is de140f9e5092685464e8.

Admittedly the entry file here may not have a large enough surface area to prove concretely that both -p and --mode production produce the same result, but it should suffice in demonstrating the outlined approach.


Also it would be great to know if --mode=production has any difference versus --mode production because for me both version work absolutely fine

There is no difference between the two ways of specifying flags and their values:

$ webpack --mode production
$ webpack --mode=production # equivalent to the above

Whatever flag parsing library webpack uses (might even be bespoke) takes care of either case for you, so you can take whichever approach you prefer. This is quite common behaviour for CLIs.


Also, there is a thread here, that says that -p "Run commands in parallel." Is that a flag to node, that has the same name as -p for webpack?

I believe the -p flag referenced here is for the npm-run-all library, as it used in the example in the answer as an npm script, as follows:

"test": "npm-run-all -p -r webdriver-start http-server protractor"
sdgluck
  • 24,894
  • 8
  • 75
  • 90