I've seen some command-line magic on other forums, but I would not recommend that you do any of that.
macOS really is much better in RAM management, than Windows.
In any case, swap memory is always slower than RAM, macOS tries not to use it at all costs.
I say, if you haven't got sufficient amount of RAM, don't mess up with swap, get more RAM. Almost all the Macs can be upgraded. Use resources like everymac.com to see what options do you have with yours.