Here was the situation, you’ll forgive the lack of detail as the system I work on is quite proprietary. The system has custom pages where you can put your own html, js, css, etc.. and what have you. Except one problem. The interface was probably built in 2005, takes about 8 centuries to load, and rather than having some kind of folder system, uses SQL-Server TEXT columns to store your code…. Yuck. And once you’ve tasted the fruits of HMR like Webpack’s hot-reloading, all other tooling will taste like ash in the mouth.
So something needed to be done, and I’m love breaking things so naturally I spun up a fresh webpack project. Then I just broke my problem down into it’s most basic parts. I had code which needed to be copied over to some folder to be served, and then the html for the custom page needed to be loaded into the correct row of the correct table. Not as simple as I liked, but now I’ve got my goals for the script to run after the webpack build. Now at the risk of getting dependency crazy, here is what dug me out of my 13 year old development environment.
FS we are all familiar with, it’s Node’s file module for interacting with the disk. And in this case it’s going to grab our generated html file.
Knex, a fantastically versatile query builder, is going to take the contents of that file and push them to our database auto-magically.
CPX will actually watch the files for changes and can be scripted to copy them to the appropriate folder(in this case via the network). CPX supports file globs(thank the Lord), so you just feed it an extension and you’re off to the races.
Now instead of having to navigate through some menu, copy the code from my editor into a form, then submit and refresh. All I have to do is hit refresh, and hot-loading takes care of the rest(side-note: I used this Webpack plugin to run my script after each build)
As I close, here are some comments about this setup. This is NOT a recommended way to develop, were it up to me I’d probably rip the system down and start from scratch with an express app or something. But that’s not the point I’m trying to make here. In developing, sometimes we don’t get to pick our environments, or even where we deploy our code. So it’s awesome that we have a great and active community that develops packages that are not only easy to use, but also make our lives a lot easier. And it always helps to think outside the box too.