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

Can this library be used in ES without webpack? #72

Open
elgs opened this issue Jul 12, 2021 · 2 comments
Open

Can this library be used in ES without webpack? #72

elgs opened this issue Jul 12, 2021 · 2 comments

Comments

@elgs
Copy link

elgs commented Jul 12, 2021

I don't see any export keyword in the figlet.js. I wonder if you can make a change so we can use it in native ES code? Thanks.

@patorjk
Copy link
Owner

patorjk commented Jul 12, 2021

There is in node-figlet (https://github.com/patorjk/figlet.js/blob/master/lib/node-figlet.js). That's what package.json points to (for the "main" prop). Also, at the bottom of the figlet file, there is an export statement.

What kind of changes are you thinking of? What would be the use case? I'm all for updating the package if it makes it easier for something, as long as it maintains its backward compatibility.

@elgs
Copy link
Author

elgs commented Jul 12, 2021

@patorjk close, but it's an exports statement, as opposed to export.

The story is like this, when nodejs was born, the browsers did not have a module system yet. And suddenly npm created a big ecosystem that potentially could benefit the web dev 10 years ago. However, at the time, in order for browsers to use a 3rd party library, the library has to inject itself into the window scope. Because of this need, webpack and rollup were born. This duo was great 10 years ago, but is bad today. Because back then they enabled npm packages for web devs. But today they allowed fake ES syntax for many npm packages and effectively they hindered the modern browsers from natively loading 3rd party modules, like your package. The root cause is ES doesn't support module.exports syntax, and even worse, webpack allowed to use ES import syntax to load npm packages. This is effectively making webpack a dependency of most of today's web apps, which shouldn't be necessary at all.

The good part of webpack is help to bundle a web app, but the evil part webpack is to hinder the incentive of migrating the old node package system to ES module system, like yours. So that's why you could see lodash and lodash-es co-exist. Good thing is node has started to support ES syntax so that's the start of the death of the require syntax.

So I think it may make sense to create a new file called figlet-es.js which will be usable in modern browsers natively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants