Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

Webpack output change v4 to v5

I'm in the process of upgrading a project that uses webpack from v4 to v5 and while it all compiles without error now (after some minimal tweaking) I noticed that the output format is quite different. Under v4 it had an outer structure like this:

(function(modules) {
...
});

whereas now in v5 it has a structure like this:

(() => {
...
})();

I think that is causing a problem for a particular way the output is being used in our project (specifically, the latter seems to be invoked, but the former doesn't seem to be).

Is there a setting that changed the default output in v5?

I tried looking at output.iife (no effect) and others in the docs, but didn't see something that looked right to me. I'm sure I'm missing something obvious.

Update:

With @felixmosh's answer, I got part of the way there. The use of the function syntax instead of the lambda syntax is consistent now, but there's still the issue that it appears the v5 variant is self-executing and the v4 wasn't.

I added a repro over on GitHub based on the webpack getting started samples: https://github.com/tlmii/webpack-v4-to-v5-example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can specify webpack's target to be es.

module.exports = {
  // ...
  target: ['web', 'es5']
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...