1.1.1 • Published 2 years ago

ejs-prerender v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

ejs-prerender

Usage

This package is typically used as a devDependency. Install by running npm i -D ejs-prerender. It can be used as an npm script like the following:

"build:templates": "ejs-prerender",

and run manually using npx:

npx ejs-prerender

This package utilizes the debug library, so adding DEBUG=ejs-prerender:* to a .env file or the command path (DEBUG=ejs-prerender:* npx ejs-prerender) will enable logging of everything.

Recommended File Structure

The following file structure works out-of-the-box with no customized environment variables.

root
├ components/
│ └ head.ejs
└ pages/
  ├ about/
  │ └ index.ejs
  └ index.ejs

will render as

root
└ public/
  ├ about/
  │ └ index.html
  └ index.html

The components can be simply referenced inside EJS pages as seen below:

<!DOCTYPE html>
<html>
  <head>
    <%- include('head') -%>
  </head>
  <body><h1>INDEX</h1></body>
</html>

Configuration

Environment Variables

OptionEnvironment VariableTypeDefaultDescription
baseDirPEJS_BASE_DIRStringcurrent working directoryBase directory to reference for other relative paths
outputDirPEJS_BUILD_OUTPUT_DIRString'public'Where the completed pages get written
componentsDirPEJS_BUILD_COMPONENTS_DIRString'components'Where components live
pagesDirPEJS_BUILD_PAGES_DIRString'pages'Where pages live
pageExtensionPEJS_BUILD_PAGES_EXTString'ejs'File extension of pages