posthtml / posthtml-expressions

Use variables, JS-like expressions, and even markup-powered logic in your HTML.
Other
123 stars 20 forks source link

Refactor to ESM #160

Open cossssmin opened 9 months ago

cossssmin commented 9 months ago

@Scrum I'd like to work on a new major release for posthtml-expressions that would include:

Please let me know if you're OK with this and I'll start work on the PR. Thanks!

Scrum commented 9 months ago

@cossssmin I'm glad you can do it, thank you!

cossssmin commented 9 months ago

Thanks, will get started and let you know when it's ready for review.

Did you have any plans for it? We could add them in this refactor.

Scrum commented 9 months ago

Did you have any plans for it? We could add them in this refactor.

There were a couple of ideas:

cossssmin commented 9 months ago

OK, I'd start on it and when I'm done you could add those maybe? Or do you prefer we launch a major version first and then add those ideas?

Scrum commented 9 months ago

OK, I'd start on it and when I'm done you could add those maybe? Or do you prefer we launch a major version first and then add those ideas?

Rather, as you prefer, these are the best ideas)

cossssmin commented 9 months ago

Could we take this opportunity to think about what options we have for replacing node:vm so that the plugin could be used in a browser environment? Would Function work?

This would be a game-changer for frameworks like Maizzle, you could run the entire PostHTML build chain right in the browser, no serverless/Lambdas needed.

Scrum commented 8 months ago

It is necessary to explore this direction, in the first approximation it looks like vm-browserify

cossssmin commented 8 months ago

I was looking at the Alpine.js evaluator the other day, maybe something like this would be enough?

https://github.com/alpinejs/alpine/blob/main/packages/alpinejs/src/evaluator.js

Didn't know about vm-browserify, looks like it's very popular but it's only for the browser and it creates an <iframe> for each code execution which leads to other issues like web workers not working.

cossssmin commented 8 months ago

This also looks interesting, it uses @babel/parser to parse expressions:

https://github.com/william-yz/ts-expression-evaluator

cossssmin commented 8 months ago

Another idea would be to create an interface and allow for various templating engine adapters. For example, there's LiquidJS that people could use instead of the default engine.