mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.71k stars 846 forks source link

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

Open mercmobily opened 2 years ago

mercmobily commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

cyrus-and commented 2 years ago

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 commented 2 years ago

@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 commented 1 year ago

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

mercmobily commented 1 year ago

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 commented 1 year ago

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