Webpack: do not use webpackBoostrap function wrappers

Viewed 280

I have a question, is it possible to tell webpack not to wrap modules into functions? I need to set this behavior only for specific entries.

I have a set of super legacy code that relies on global object, without explicit access to window or just plain var. But as webpack wraps code to function there is no more global scope. I created an entry point which value is array of the files:

entry: {
  legacy: {
    filename: 'old/legacy.js',
    import: glob.sync(['legacy/*'], {
      absolute: true,
    }),
  },
}

How to tell webpack do not use any wrappers for this bundle. However I need this code to compile through loaders and minification.

I use webpack 5.

2 Answers

For future reference: Setting output.iife to true in your webpack config will also stop webpack from wrapping it and expose all variables to the global scope

Related