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

A clean, full ES6 version of EJS, without changing the codebase #656

Open
mercmobily opened this issue Mar 30, 2022 · 8 comments
Open

A clean, full ES6 version of EJS, without changing the codebase #656

mercmobily opened this issue Mar 30, 2022 · 8 comments

Comments

@mercmobily
Copy link

mercmobily commented Mar 30, 2022

It took me a while, but I got there.
I am not submitting a PR because I am still working out kinks, and I would like to talk to you about how to go about it.
The short version: I did it! Have a look here: https://github.com/mobily-enterprises/ejs4b
It converts ejs into ES6 modules. Please note that it DOESN'T minify/etc. the only real changes there are in the fact that some of Node's calls are stubbed. Basically Rollup is doing what Browserify does. I can't say whether it does it "better" or not, but I can tell you they put a lot of work into this.
So... options:

(1) The non-committal way

We keep this as a separate repo. I will set up some kind of hook so that the version us updated automatically (I hate it when things like this stop working after 2, 3 years). Ideally, you'd put a link

(2) The integration way

You can easily take my rollup.config.js and simply add it to your repository. I would call the end result ejs-es.js.
So, you will have 3 files: /lib/ejs.js (node, unminified), /ejs.js (browser, unminified), /ejs-min.js (browser, minified) and the NEW /ejs-es.js (browser, unminified, ES6). The naming makes sense. Also, please note that there is no point in minifying the ES version, since it's meant to be built/included using tooling.

I think people would be happier if you went for (2). However, it depends on you. Please have a look at my repo (which is totally minimal) and let me know which way you want to go.

Thank you!

@mercmobily
Copy link
Author

If you want to go with (2), I will be happy to make a PR which will add the build step for the ES modules version.
I want to add that this could be an opportunity to use Rollup even for /ejs.js version (which currently uses Browsify). I will be happy to do that in the PR too -- as long as you are happy for me to go that way.

Just let me know.

@mde
Copy link
Owner

mde commented Mar 30, 2022

I'm on vacation with the family this week, but I'll take a look at this as soon as I can. I really appreciate all the work you have put into this.

@mercmobily
Copy link
Author

No stress at all. I am glad I could help.

@cyrus-and
Copy link

This would be incredibly useful, and I second @mercmobily about option 2. I'm not a Rollup expert but the integration should be fairly painless. Plus it seems that's the direction where others too are moving towards. For example (and hopefully this could help @mde in the integration, by providing yet another example) Marked seems to do the same, as you can see the marked.esm.js file is pushed to NPM along with the rest.

@mercmobily
Copy link
Author

@mde Matthew, first of all please allow me to re-iterate how much I appreciate you maintaining EJS.
This is not meant to be a pestering message. I just wanted to let you know that I am using solution (2) for my own project, and it works really well. I am quite convinced that it's a good way to go. When you have time (and, whenever that might be), please have a look and test things out to confirm that I got it right :D

Thank you!

@trullock
Copy link

@mercmobily Whats the current status of your fork, still looking good? Does this enable me to do imports inside my .ejs?

@mercmobily
Copy link
Author

I am using https://github.com/mobily-enterprises/ejs4b in production with no issues so far. I am using EJS as of 8 months ago -- I won't upgrade in case things go bad. I am still hoping @mde will give his OK for a PR, and go from there.

@mercmobily
Copy link
Author

Please note that mine is NOT a fork. I take the exact same EJS, and just "repackage" it so that it's an EJS!

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

4 participants