Skip to content

Commit

Permalink
Documented environmental variables in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcox authored Jan 13, 2024
1 parent a2263dd commit c2f3035
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ plugins: [
]
~~~

## Environment variables
The `pathPrefix` npm script argument from 11ty is passed through as an environment variable using [esbuild's define api](https://esbuild.github.io/api/#define). You can add other environment variables by adding them to the defineEnv const in the `config/build/esbuild.js` script.

~~~js
const defineEnv = {
'process.env.PATHPREFIX': JSON.stringify(pathPrefix),
// Add other environment variables as needed
};
~~~

If you decide to use a client-side router such as [solid router](https://github.com/solidjs/solid-router) you could do the following:

~~~js
const pathPrefix = process.env.PATHPREFIX;
const urlPrefix = pathPrefix ? `/${pathPrefix}` : "";

render(
() => (
<Router>
<Route path={urlPrefix}> {/* solid-js router uses urlPrefix here to set the url path */}
<Route path="/" component={YourComponent} /> {/* The home page route */}
</Route>
</Router>
),
document.getElementById('app')
);
~~~

## Development Scripts

**`npm start`**
Expand Down

0 comments on commit c2f3035

Please sign in to comment.