DEV Community

Ryan Westlund
Ryan Westlund

Posted on

The solution to Javascript import

6 months ago I wrote Disadvantages of Javascript import, where I bemoaned among other things that if you use exports and imports in your component files, the names are only imported into the files and thus not accessible from devtools. A commenter reminded me of import * as stuff from ... which solved the other problems, but not the main one.

But today I realized that can be easily extended to solve the main problem. I changed my main.js (Webpack entrypoint) to itself import all the utilities as a single object named util, and put only that on the window. No serious concerns about namespace pollution because it's only one name, and I can access all my utilities from devtools now.

Discussion (0)