From 20b6ded9ba43b8b7d3a925dbb0ba4a3004cd441c Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Fri, 7 Feb 2025 19:29:44 -0500 Subject: [PATCH] more concise version of custom imports using NODE_OPTIONS --- package.json | 2 +- src/pages/docs/pages/server-rendering.md | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0af93298..52ad8819 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "scripts": { "clean": "rimraf public .greenwood storybook-static", - "build": "node --import @greenwood/cli/register ./node_modules/@greenwood/cli/src/index.js build", + "build": "NODE_OPTIONS='--import @greenwood/cli/register' greenwood build", "dev": "greenwood develop", "serve": "npm run clean && npm run build && greenwood serve", "story:dev": "storybook dev -p 6006", diff --git a/src/pages/docs/pages/server-rendering.md b/src/pages/docs/pages/server-rendering.md index d78a8087..a1a94da3 100644 --- a/src/pages/docs/pages/server-rendering.md +++ b/src/pages/docs/pages/server-rendering.md @@ -302,7 +302,7 @@ For request handling, Greenwood will pass a native `Request` object and a Greenw ## Custom Imports -To use custom imports (non JavaScript resources) on the server side for prerendering or SSR use cases, you will need to invoke Greenwood using **NodeJS** from the CLI and pass the `--imports` flag along with the path to Greenwood's provided register function. _**This feature requires NodeJS version `>=21.10.0`**_. +To use custom imports (non JavaScript resources) on the server side for prerendering or SSR use cases, you will need to invoke Greenwood using **NodeJS** from the CLI and pass the [`--import` flag](https://nodejs.org/api/module.html#enabling) to NodeJS along with the path to Greenwood's provided register function. _**This feature requires NodeJS version `>=21.10.0`**_. @@ -328,7 +328,25 @@ Or most commonly as an npm script in your _package.json_ "build": "node --import @greenwood/cli/register ./node_modules/@greenwood/cli/src/index.js build" } } -``` + ``` + + + + + +Alternatively, you can pass `--import` as a `NODE_OPTION`, which doesn't require having to specify the full path to the Greenwood CLI in your _node_modules_. + + + + + + ```json + { + "scripts": { + "build": "NODE_OPTIONS='--import @greenwood/cli/register' greenwood build" + } + } + ```