Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow import/require in Player.js for modularity of user code #99

Open
hexpunk opened this issue May 14, 2018 · 9 comments
Open

Allow import/require in Player.js for modularity of user code #99

hexpunk opened this issue May 14, 2018 · 9 comments
Labels
pkg: core Pertaining to @warriorjs/core type: feature A potential feature to be added

Comments

@hexpunk
Copy link

hexpunk commented May 14, 2018

Originally mentioned in #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.

@olistic olistic added pkg: core Pertaining to @warriorjs/core type: feature A potential feature to be added labels May 14, 2018
@olistic
Copy link
Owner

olistic commented May 14, 2018

Hello @jayandcatchfire and thanks for creating this issue. I'm open to receive a PR that implements this.

@hexpunk
Copy link
Author

hexpunk commented May 14, 2018

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!

@olistic olistic changed the title Feature request: Allow import/require for modularity of user code Allow import/require in Player.js for modularity of user code May 14, 2018
@olistic
Copy link
Owner

olistic commented May 14, 2018

Please comment here if you grab this so I mark it as claimed.

@gordon-to
Copy link

gordon-to commented May 15, 2018

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

@netzulo
Copy link

netzulo commented May 17, 2018

Pleasee i need some of this!!!! :)))))

@gordon-to
Copy link

@netzulo you can work around it by importing your code as a string and call eval(code)

@olistic
Copy link
Owner

olistic commented May 18, 2018

I published a tutorial on how this can be achieved using a module bundler here.

@AFaugeras
Copy link

@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
;)

@alexmachina
Copy link

News on this? If a contributor can point me on the right direction I'm available to implement it this weekend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: core Pertaining to @warriorjs/core type: feature A potential feature to be added
Projects
None yet
Development

No branches or pull requests

6 participants