npm

ejs-addon

1.2.0 • Public • Published

ejs-addon

Addon for EJS 2.x and Express 4.x

NPM version npm download David deps

Install

npm i ejs-addon -S

Usage

Explains the usages of ejs-addon, you can view detail usages in example.

layout

layout refers to ejs-mate

  • Declare layout
<!DOCTYPE html>
<head>
    <title>ejs-addon</title>
</head>
<body>
<%- body %>
</body>
  • Use layout
<% layout('default') %>
 
<h1>Title</h1>
  • Working with Express
const app = require('express')();
const engine = require('ejs-addon');
 
app.engine('ejs', engine);
 
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

loader

  • Use loader
<% loader([
  '/path/to/foo.css',
  '/path/to/bar.js'
]) %>
  • Declare placeholder in layout

ejs-addon use <%- css %> and <%- js %>, put them in the right place.

<!DOCTYPE html>
<head>
    <title>ejs-addon</title>
    <%- css %>
</head>
<body>
<%- body %>
<%- js %>
</body>

More about loader

loader support adding prefix for assets.

For example, if you are using CDN for your application in production, follow these steps:

  1. Ensure process.env.NODE_ENV === 'productoin'
  2. Use the following lines of codes in your app.js:
// Pulic folder
app.set('public path', path.join(__dirname, 'public'));
// Declare CDN url pattern
app.set('public pattern', 'http://yourcdn.com/@version/@path');

Things about CDN pattern:

  • @version would be replaced with the file's modified time
  • @path would be replaced with the files relative file path as you declared in loader()

Example

See example

Contribute

Fire an issue

License

The MIT License

Readme

Keywords

Package Sidebar

Install

npm i ejs-addon

Weekly Downloads

76

Version

1.2.0

License

MIT

Last publish

Collaborators

  • fantasyshao