Replies: 2 comments 3 replies
-
There is the ongoing vite-migration migration effort as a first goal, that has a simmilar approach to your suggestion(for more detail look at the vite PR and Braches) |
Beta Was this translation helpful? Give feedback.
-
Hello, please see here: #842 I don't see issues in using Vite, it works fine and it useful for some of the things we also want.
|
Beta Was this translation helpful? Give feedback.
-
I couldn't find any threads in this vein in discussion, so I figured it might be worth bringing up.
I think there are options for incremental rejiggering that might be worth considering. esbuild is a very fast and robust (quasi) spiritual successor to browserify. The scope is much lower than something like Webpack or Vite—it's not really designed to handle asset bundling, &c. Command-line usage is straightforward so there aren't any massive config files, which is nice.
Situation
I was digging around in this repo and an approach stood out that may work. Right now—maintainers know this, obviously, but for the sake of clarity—the code is all laid out like this:
And
index.html
contains a list of every JS source file in the appropriate order for loading. And everything's in the global scope and that all works, and that's great. But as we all know, it's not super-scalable in the long term and makes some fixes/improvements basically impossible (e.g., moving the generation code from the UI thread to web workers to eliminate UI lag issues).So the question becomes 'how do we move things out of the global scope in a way that's both maintainable in the long term and can be migrated piecemeal without needing to do everything all at once'.
Suggestion
So, thought: without modifying the existing project structure, add a
src
directory that contains code that won't be loaded at runtime but instead at bundle/build time. A new file,./src/index.js
is added. This file does one thing: imports stuff from JS modules insrc/**/*.js
and makes it globally available by explicitly assigning it as a property onwindow
instead of implicitly declaring it in the global scope.We add an esbuild script to bundle everything from
src/index.js
intobundle.js
and pull that intoindex.html
via a standard script tag.Now code can be moved into
src
and modified to use the module system, while existing code that uses global references can keep using those global references. And gradually, more and more code can be pulled intosrc
until a given property/function on window is no longer being used globally, at which point it can be removed and we're one property/function closer to getting everything out of the global scope.Issues with this approach
Case study:
probabilityUtils.js
./utils/probabilityUtils.js
to./src/utils/probabilityUtils.js
export
keyword./src/index.js
src/utils/probabilityUtils.js
:Anyway—interested to hear what y'all think. It's obviously a complex problem, but this could be a way (to mix metaphors) to get the ball rolling without rocking the boat.
Beta Was this translation helpful? Give feedback.
All reactions