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
Returning results from a promise within a shortcode #1434
Comments
An update on this: @louh commented over in the terser repo (terser/terser#801 (comment)) about the importance of synchronous minification within templating languages and synchronous code that is core to Eleventy. In the meantime, going to continue exploring the best way to deal with async operations within shortcodes, or find a way to minify my scripts synchronously. |
Have you seen https://www.11ty.dev/docs/quicktips/inline-js/? |
@binyamin, I have. The caveat with that setup is that Nunjucks is the only templating language that supports async operations, so not the most viable solution. I ended up going back to using |
Hello,
I have tried unsubscribing multiple times now. Is there an admin person who
can take me off the email list?
…On Fri, Oct 9, 2020 at 10:06 AM Noel Forte ***@***.***> wrote:
@binyamin <https://github.com/binyamin>, I have. The caveat with that
setup is that Nunjucks is the only templating language that supports async
operations, so not the most viable solution. I ended up going back to using
babel-minify for the time being as I have the option to do sync stuff
with babel, and can cut a few dependencies out of my project. I'll leave
this issue open for a bit in case people want to discuss more.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1434 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHQBN2ABHCKJRWTETVBH5CDSJ47KHANCNFSM4SEAIZ3A>
.
|
@Joel-Torres This is not an email list; it's an issue on GitHub. It looks like GitHub is sending notifications to your email. Log into GitHub, and unsubscribe from whatever you want. |
Going to mark this as closed since my issue was addressed and this appears to now be drifting off topic. |
I'm trying to figure out what the best way is to return the results of an async function to be used as a shortcode. I've come across a few issues on this repository that suggest various ways to do this, but none that appear to match my case exactly— it's probably because of my lack of experience trying to wrap my head around promises, but alas here's what I'm trying to accomplish.
I'm using eleventy in combination with babel and terser to process my javascript files by:
a) using a shortcode that takes the path of a .js file
b) passing that path to a
require
d modulec) the module
exports
a function that returns the transpiled + minified resultExample:
However, when I run
eleventy
the resulting output from the shortcode is always[object Promise]
even though I'veawait
ed the promise to be resolved. What's puzzling is that doing aconsole.log(terserResult.code);
yields the expected code. Am I missing something?Some brief googling took me to this page on Eleventy Shortcodes, and further exploration took me to the deasync package on npm. If possible I'd like to run eleventy without extra dependencies, as well as without needing to rely on specific templates— I'd like my shortcodes to stay as universal as possible for flexibility.
The text was updated successfully, but these errors were encountered: