M
M
maksimLavrenyuk2019-08-15 12:08:32
JavaScript
maksimLavrenyuk, 2019-08-15 12:08:32

How to make webpack friends with legacy code (many global variables)?

Hello!
There is a big project where it was decided to implement webpack. There is a bunch of legacy code that has a lot of global variables. for example:
2 files are connected in html

<script src="example.js"></script>
<script src="dosomething.js"></script>

1) util.js file
function example(num) {
    //...
}
function example1(str) {
    //...
}

function example2(str) {
    //...
}

There can be any number of global functions.
2) dosomething.js file
var exampleNum = 1;
var exampleStr = 'example';

example(exampleNum);
 example1(exampleStr);
example2(exampleStr);

Those. there are many globals, tracking each one and writing an exports example is not possible due to the huge amount of existing code. There is really a lot of code.
Is it possible somehow to combine the scripts required on the pages into 1 file and then access it as window.example(), without searching for exported global variables?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question