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.

discuss for remove unused argument in runtime function template in webpack5

See original GitHub issue

I’m not sure if this is a bug or expected feature(not compatibility for the wrong module library),so I marked it as discuss.

good case

when we not use module spec keyword like module,require ,import,export etc in js file

// a.js
console.log(1)

in webpack4 ,we will get output like

function(module, exports){
  console.log(1)
}

but webpack5 ( maybe this commit ) ,we will get output like

function(/* argument is omit for unused */){
  console.log(1)
}

I think this is a useful optimization in most cases。

bad case

However. suppose you have a library whick name “A”

// my simple lib A
eval("if(typeof module === 'object') module.exports='A'")

in webpack4 we will get string "A" with import A from "A"

function(module, exports){
  eval("if(typeof module === 'object') module.exports='A'")
}

but in webpack5 we get an empty object {}. because arcon ast can not detect the correlation of the module variable.so that the first module argument will be remove due to unused

function(/* argument is omit for unused */){
  eval("if(typeof module === 'object') module.exports='A'")
}

real case

we use a lib which name watermark-dom(it has a star close to 1k github npm) in webpack5

Below is the minimal reproduce link https://github.com/VisonM/webpack-reproduce-demo

Summarize

I have to say the npm package of watermark-dom is terrible, but do we still need to be compatible with such libs?if we should keep unused argument when code exist some keyword like eval,new Function etc

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
VisonMcommented, Aug 11, 2022

@alexander-akait @vankop Thanks for your patience!🌈 just closed this issue.

I think noParse is enough for such weird libraries.

I also found docs about runtime optimization in release blog, but I think it’s a little obscure for developers, I may send a docs pr to optimized, make it more understandable, but it’s a bit difficult for me, I haven’t done anything like that, but I’ll try my best.

1reaction
alexander-akaitcommented, Aug 10, 2022

but,I don’t see any instructions about this in the relevant weback documentation or migration guide, am I missing something? I think adding documentation may be helpful to those who care it, and I’m willing to contribute pr if needed

These changes happen because webpack v5 is more stricky

Workaround:

module.exports = {
  module: {
    noParse: /watermark-dom/,
  },
  target: ["web", "es5"], // remove arrow function in output
};

But I think it’s really weird and I don’t think this code should be used in libraries

And yes - welcome to update docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Command Line Interface - webpack
Used to initialize a new webpack project. npx webpack init [generation-path] [options]. example npx webpack init ./my-app --force --template=default ...
Read more >
Eliminating Unused CSS - SurviveJS
Eliminating unused CSS is possible using PurgeCSS. It performs static analysis against the source. The functionality can be enabled through purgecss-webpack- ...
Read more >
How I solved and debugged my Webpack issue through trial ...
When webpack bundles your source code, it can become difficult to track down errors and warnings to their original location.
Read more >
Can ES6 template literals be substituted at runtime (or reused)?
To make these literals work like other template engines there needs to be an intermediary form. The best way to do this is...
Read more >
How to use Webpack in ASP.Net core projects; a basic React ...
Net core Web project template and MVC support manually, ... we can remove the arguments from the webpack command in the Scripts section...
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