ejs-serve

Build, watch and serve your EJS templates in your browser.

Usage no npm install needed!

<script type="module">
  import ejsServe from 'https://cdn.skypack.dev/ejs-serve';
</script>

README

ejs-serve

GitHub npm

Build, watch and serve your EJS templates in your browser.

👋 Introduction

ejs-serve is a CLI tool for developing/working with EJS templates.

  • renders your EJS templates with data
  • serves the files to your browser
  • watches for file changes and reloads your browser automatically
  • no extra files in your working directory
  • also watches for changes in your data
  • can be used in conjunction with mjml

🚀 Get started

Install ejs-serve globally via npm:

npm install ejs-serve -g

After that ejs-serve is ready to be used 🎉

📚 Usage

Usage: ejs-serve -f <filename> -d <json string|file> -p <port>        

Build, watch and serve your EJS templates in your browser.

Options:
  -f, --file <path>           path to ejs file
  -d, --data <json>           JSON string or path to json file
  -p, --port <number>         port on which to serve the file (default: 8080)
  -e, --email [boolean]       render file with mjml (default: false)
  -o, --open [local/network]  open file in browser automatically (default: false)
  -v, --version               output the version number
  -h, --help                  display help for command

🛠️ Examples

Render EJS template with data from JSON file and serve it

ejs-serve -f index.ejs -d data.json

Render EJS template with data from JSON string and serve it

ejs-serve -f index.ejs -d '{"message":"Hello World!"}'

Serve on custom port

ejs-serve -f index.ejs -d data.json -p 3000

Automatically open browser

ejs-serve can automatically open the file in the browser. If you use -o it will open the file via its local address (localhost:port). You can use -o network to use the network address.

ejs-serve -f index.ejs -d data.json -p 3000 -o

Generate email with mjml

ejs-serve can be used in conjunction with mjml to render your ejs file with data and generate a reponsive email. Use the -e option to enable this feature and it will run the rendered ejs file through mjml.

ejs-serve -f index.ejs -d data.json -e

Use it in another project

If you want to use ejs-serve for development in another project, add it to your dev dependencies:

npm install ejs-serve --save-dev

And include this command in your package.json

  "scripts": {
    "templates": "ejs-serve -f ./path/to/file.ejs -d '{\"message\":\"Hello!\"}'"
  },

📝 To do

Here is what's currently planned for ejs-serve:

  • render multiple files/whole directory
  • render files and output them to directory

💻 Development

Issues and PRs are very welcome!

  • run yarn lint or npm run lint to use eslint.
  • run yarn example or npm run example to serve the example EJS file

Please check out the contributing guide before you start.

This project adheres to Semantic Versioning. To see differences with previous versions refer to the CHANGELOG.

❔ About

This library was developed by me (@betahuhn) in my free time. If you want to support me:

Donate via PayPal

License

Copyright 2020 Maximilian Schiller

This project is licensed under the MIT License - see the LICENSE file for details.