question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
AFaugerascommented, May 26, 2018

@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 😉

2reactions
olisticcommented, May 18, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Modularize Code in Vanilla JavaScript using 'import ...
In this blog, we will be covering how to make a Vanilla JavaScript project modular and using the keywords import and export ....
Read more >
Basics of Modular JavaScript. Intended Audience - Medium
So libraries enable languages to not repeat code and delegate functionality and this is similar to what modules gives JavaScript.
Read more >
How To Use Modules in TypeScript | DigitalOcean
Modules are a way to organize your code into smaller, more manageable pieces, allowing programs to import code from different parts of the ......
Read more >
3. Modularizing and Managing JavaScript - O'Reilly
JavaScript modularization is both a discipline and a contract. ... or ensuring your own code is packaged for ease of use and innovation....
Read more >
JavaScript Import Explained - Tutorials - Yax.com
The Javascript 'import' statement: its purpose and how to use it. ... The import statement makes modular code possible in JavaScript (and also,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found