-
Notifications
You must be signed in to change notification settings - Fork 53
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
Serverless Elder rendering #28
Comments
We could go a step further and try to pre-build and pre-bundle as much of Elder and everything needed for server-side rendering. Less moving parts during runtime is better :) For example hooks and routes still live in the source directory ( simplified const distDir = './___ELDER___/';
const hooksConfig = {
input: 'src/hooks.js',
output: {
format: 'cjs',
exports: 'auto',
dir: distDir,
},
plugins: [
commonjs({ sourceMap: false }),
],
};
const routesConfig = {
input: ['src/routes/*/route.js'],
output: {
format: 'cjs',
exports: 'auto',
dir: path.join(distDir, 'routes/'),
},
plugins: [
multiInput({ relative: 'src/routes/' }),
commonjs({ sourceMap: false }),
],
};
// ...
if (production) {
// production build does bundle splitting, minification, and babel
configs = [...configs, ...templates, ...layouts, hooksConfig, routesConfig]; |
@jbmoelker @decrek I dig it. We've looked at a similar solution internally 👍 before open sourcing it we did EXACTLY what you are doing with
|
I'm also interested in this. Especially the possibility of deploying to something like Cloudflare Workers, Lambda@edge and Akamai EdgeWorkers. |
Same here, I'm on vacation. I'll ask my @voorhoede colleagues if they can help out. |
Hi @nickreese! ! First of all, great work on ElderJS! I have an update on this issue. I managed to get serverless rendering working with Netlify functions and I wanted to share my example. I had to fork Elder to make some small changes in order to get it working so I want to propose some changes to Elder as well.
Next to that, I can not rely on process.cwd() for the root of the project. In order to fix I've added a property to the elder config, which I called These 2 changes give me more flexibility over configuring Elder in different environments.
I think the possibility to do serverless rendering using Elder is pretty awesome! What do you think about the whole approach and how do you feel about passing the configuration to the Elder constructor? |
Oh and here is the link to the working example: https://deploy-preview-1--elderjs-serverless.netlify.app/ |
@decrek Great work, this is exciting.
Disabling writing of only specific pages.
|
So, we know Elder is designed to generate static websites 💯 . However my colleague @decrek and I think Elder could be used very well for partially static and partially dynamic websites. You've already proven Elder can be used as a server in Elderjs/template > src/server.js. So we want to take it one step further and make it serverless.
@decrek has already done some work on this. Dynamic serverless Elder rendering in a lambda function would look something like this:
with
lib/render-elder-page.js
doing the actual rendering:The setup is working locally, but we're still having some issues on Vercel and Netlify. The hardest part in the serverless context is reaching all the relevant source and generated files. The automagic behaviour, mainly inside
getConfig
is making this a bit difficult. The other bit is the use ofprocess.cwd()
throughout the code base. To make Elder more flexible to use, 2 things would help a lot:settings.rootDir
throughout the code base. So for instanceconst srcFolder = path.join(process.cwd(), settings.locations.srcFolder);
would becomeconst srcFolder = path.join(settings.rootDir, settings.srcDir)
.rootDir
could still default toprocess.cwd()
. See Proposal: simplify elder.config.js #27.new Elder(config)
to avoid issues caused by automagic behaviour like cosmiconfig. The automagic behavior can still be used as a default for when no config is passed.The text was updated successfully, but these errors were encountered: