@greenwood/plugin-adapter-netlify
v0.30.2
Published
A Greenwood plugin for supporting Netlify serverless and edge runtimes.
Downloads
404
Maintainers
Readme
@greenwood/plugin-adapter-netlify
Overview
This plugin enables usage of the Netlify platform for hosting a Greenwood application. For more information and complete docs on Greenwood, please visit our website.
This package assumes you already have
@greenwood/cli
installed.
Features
In addition to publishing a project's static assets to the Netlify CDN, this plugin adapts Greenwood API routes and SSR pages into Netlify Serverless functions using their custom build approach.
This plugin will automatically generate a custom _redirects file to correctly map your SSR page and API route URLs to the corresponding Netlify function endpoint (as a rewrite). You can continue to customize your Netlify project using your netlify.toml file as needed.
Note: You can see a working example of this plugin here.
Installation
You can use your favorite JavaScript package manager to install this package.
# npm
$ npm i -D @greenwood/plugin-adapter-netlify
# yarn
$ yarn add @greenwood/plugin-adapter-netlify --dev
# pnpm
$ pnpm add -D @greenwood/plugin-adapter-netlify
You will then want to create a netlify.toml file at the root of your project (or configure it via the Netlify UI), updating each value as needed per your own project's setup.
[build]
publish = "public/"
command = "npm run build" # or yarn, pnpm, etc
[build.processing]
skip_processing = true
[build.environment]
NODE_VERSION = "18.x" # or pin to a specific version, like 18.15.0
Set the AWS_LAMBDA_JS_RUNTIME
environment variable in your Netlify UI to the value of nodejs18.x
.
Usage
Add this plugin to your greenwood.config.js:
import { greenwoodPluginAdapterNetlify } from '@greenwood/plugin-adapter-netlify';
export default {
// ...
plugins: [
greenwoodPluginAdapterNetlify()
]
}
Optionally, your API routes will have access to Netlify's context
object as the second parameter to the handler
function.
For example:
export async function handler(request, context = {}) {
console.log({ request, context });
}
Please see caveats section for more information on this feature. 👇
Netlify CLI / Local Development
This plugin comes with the Netlify CLI as a dependency to support some local development testing for previewing a Netlify build locally. Simply add a script like this to your package.json
{
"serve:netlify": "greenwood build && netlify dev"
}
Then when you run it, you will be able to run and test a production build of your site locally.
Please see caveats section for more information on this feature. 👇
Caveats
- Edge runtime is not supported (yet).
- Netlify CLI / Local Dev
context
object not supported when runninggreenwood develop
commandimport.meta.url
is not supported in the Netlify CLI and in particular causes WCC to break.