handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.81k stars 2.04k forks source link

Allow importing library as ESM #2004

Closed mohd-akram closed 9 months ago

mohd-akram commented 9 months ago

This allows importing the library directly from an ESM, without requiring a build step. One change was required for a test to pass in index.runtime.js - a copy of the runtime module object is made to allow overriding checkRevision (ESMs don't allow modifying import objects). The source-map module is replaced via subpath imports rather than via runtime checking since require is not available in a ESM.

Before creating a pull-request, please check https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md first.

Generally we like to see pull requests that

jaylinski commented 9 months ago

Nice work, I had this on my backlog too. But we won't merge this in 4.x in order to keep it backwards-compatible. Please target the PR at the master-branch.

mohd-akram commented 9 months ago

Yes, I hoped it could be done in 4.x but reached the same conclusion. Will be retargeting and adjusting the PR - it needs some changes most likely - but need to merge the CI and build PRs first.

mohd-akram commented 9 months ago

Rebased on master, but closing for now as it depends on updating the build system, as well as fixing @handlebars/parser's exports (it does not properly provide ESM support as it is missing an exports field in its package.json) for integration tests to pass.