Webpack: do not use webpackBoostrap function wrappers

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.


I found some solutions that could help:

  • https://www.npmjs.com/package/webpack-merge-and-include-globally
  • https://www.npmjs.com/package/webpack-concat-files-plugin

However, they do not fit my needs, so I created another package https://www.npmjs.com/package/webpack-extract-module-to-global