How can I configure webpack to include javascript classes that are include via appendChild?

Viewed 63

I have some legacy code that import a bunch of js files using document.createElement('script'). I would like to configure webpack to detect all those files and include them into the bundle. Any suggestions about how can I do this?

The legacy code is importing hundreds of js files this way:

["window.js","eventHandler.js", and several others].forEach(filename => {
  const dom = document.createElement('script');
  dom.type = 'text/javascript';
  dom.src = base_path + filename;
  document.head.appendChild(dom);
});

Is there a way I can automatize webpack to detect this old type of import? I would like to avoid have to write manually all the requires since it is a lot of files.

0 Answers
Related