This plugin enables usage of the Netlify platform for hosting a Greenwood application.
This package assumes you already have
@greenwood/cli
installed.
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.
You can use your favorite JavaScript package manager to install this package.
examples:
# npm
npm install @greenwood/plugin-adapter-netlify --save-dev
# yarn
yarn add @greenwood/plugin-adapter-netlify --dev
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
.
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. 👇
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. 👇
- Edge runtime is not supported (yet).
- Netlify CLI / Local Dev
-
context
object not supported when runninggreenwood develop
command -
import.meta.url
is not supported in the Netlify CLI and in particular causes WCC to break.
-