npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-emit-ejs

v3.1.0

Published

Emit files from ejs with rollup

Downloads

4,667

Readme

rollup-plugin-emit-ejs

test build version

This plugin allows you to emit files from ejs templates to rollup bundle.

It is primarily meant to emit html files since it helps you to link bundled javascripts/stylesheets and includes a basic layout system, but it can deal with any file type.

Unlike rollup-plugin-bundle-html, this plugin uses the emitFile() plugin context method which allow other plugins like rollup-plugin-html-minifier to process the emitted files.

Install

yarn add rollup-plugin-emit-ejs --dev

or

npm install rollup-plugin-emit-ejs -D

Usage

// rollup.config.js

import emitEJS from 'rollup-plugin-emit-ejs'

export default {
  // ...
  plugins: [
    emitEJS({
      src: 'src',
      layout: 'src/layout.html.ejs',
      data: {
        title: 'Hey',
        body: 'Hey Hey Hey'
      }
    })
  ]
}
<!-- src/layout.html.ejs !-->

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title><%= title %></title>
    <% stylesheets.forEach(stylesheet => { %>
      <link rel="stylesheet" href="<%= stylesheet %>">
    <% }) %>
  </head>
  <body>
    <%- content %>
    <% javascripts.forEach(javascript => { %>
      <script src="<%= javascript %>"></script>
    <% }) %>
  </body>
</html>
<!-- src/index.html.ejs !-->

<main>
  <p><%= body %></p>
</main>

This will emit a file named index.html next to the javascript bundle file.

Options

{
  src: string
  dest?: string
  include?: string | string[]
  exclude?: string | string[]
  layout?: string
  extension?: string
  data?: Data
  options?: Options
}

src

Source directory to find ejs templates from.

Required

dest

Relative path from bundle location where to output files from ejs templates.

Default: '.'

include

Glob or array of globs defining which templates to include.

Default: '**/*.ejs'

exclude

Glob or array of globs defining which templates to exclude.

Default: []

Note that the template provided in the layout option is automatically excluded.

layout

Path to an ejs template to use as layout. Skip this option if you don't need layout.

Default: undefined

extension

Extension to append to emitted files (the leading . can be omitted).

Default: undefined

Note that the trailing .ejs extension is automatically removed from template filenames. So this option is useful if you only want to use the .ejs extension in your template filenames, but need to replace it with another extension like .html. Otherwise, you can just stack the output extension directly in the filename (index.html.ejs) and skip this option.

data

Data to pass to ejs.

Default: {}

The following helper variables are forced by the plugin and available in all templates:

  • javascripts: array of relative paths to javascripts
  • stylesheets: array of relative paths to stylesheets

In the layout, an extra content variable is passed containing the content to wrap into the layout. This variable needs to be printed unescaped if you want to use it as html, use the corresponding ejs tag: <%- (See ejs tags)

options

Options to pass to ejs. (See ejs options)

Default: {}

Note that the filename options is forced by the plugin.