DEV Community

rderik
rderik

Posted on

Bringing an old code base to modern JavaScript

Moving code from an old codebase to modern JavaScript presents interesting challenges. We want to take advantage of minification and modularisation of our code and make use of new and modern techniques. But we wouldn't want to have to rewrite everything before we can see any results.

One of the problems is making sure <script> tags with JavaScript code don't break when we convert them into modules for lack of access. As a temporary solution, we can export the function used by those <script> tags to the window object. Using Webpack to add our exported functions to window would be the same as putting them in the global scope (As they were before). But now we can begin working with each script file and work our way to converting our whole codebase.

If you are interested here are my notes on it:

https://rderik.com/notes/migrating-an-old-javascript-codebase-to-modern-javascript/

Top comments (0)