warriorjs
warriorjs copied to clipboard
Allow import/require in Player.js for modularity of user code
Originally mentioned in https://github.com/olistic/warriorjs/issues/39, it would be a great improvement to code organization if users like myself could split our code into modules (*.js and *.mjs) that could be loaded into the Player.js file (via import
and/or require
).
It doesn't appear that this is supported at the moment. That means that a lot of code ends up in Player.js. At various times while playing, I've been in the neighborhood of 250 lines.
Hello @JayAndCatchFire and thanks for creating this issue. I'm open to receive a PR that implements this.
I'll be happy to take a crack at it, but I can't guarantee anything forthcoming immediately. So much to do and so little time. So if anyone else sees this ticket and wants to try their hand, please do!
Please comment here if you grab this so I mark it as claimed.
looks like this can be achieved using vm.Module
, but this is an experimental feature. I think this would also have to be feature flagged.
--experimental-vm-modules
is the required nodejs flag
this requires running bin/warrior.js
with node --experimental-vm-modules path/to/node_modules/warrior-cli/bin/warrior.js
Pleasee i need some of this!!!! :)))))
@netzulo you can work around it by importing your code as a string and call eval(code)
I published a tutorial on how this can be achieved using a module bundler here.
@olistic in addition to your module bundler solution, in order to automatically remove the two last lines, you can run:
rollup src/main.js --f cjs | head -n -2 > Player.js
;)
News on this? If a contributor can point me on the right direction I'm available to implement it this weekend