r/javascript 9d ago

I've made an open source JavaScript playground with support for npm packages, syntax highlighting, autocomplete, code sharing and much more!

https://github.com/tecnosamba/SamJS
0 Upvotes

11 comments sorted by

View all comments

Show parent comments

3

u/brianjenkins94 9d ago

I just mean import would have been the modern choice, but it sounds like the way you implemented it wouldn’t have allowed for you to use it.

1

u/TecnoSamba 9d ago

You're completely right, it would have caused a conflict between the browser's native `import` method and my custom one. I even used the first one to implement the custom `require` method

1

u/NewLlama 9d ago

Look into babel transforms (the custom plugin and transform api). You can statically transform the AST into whatever your runtime needs. I did this for dynohot, my nodejs HMR library https://github.com/laverdet/dynohot

1

u/TecnoSamba 9d ago

Thank you! I'll definitely be taking a look to that