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

@aofl/templating-plugin

v3.14.0

Published

@aofl/templating-plugin creates multiple entry points and automatically generates the route config object for aofl-js applications. It uses a single template file and combines it with partial views, meta tags, title and locale based on annotated routes fi

Downloads

697

Readme

@aofl/templating-plugin

@aofl/templating-plugin creates multiple entry points and automatically generates the route config object for aofl-js applications. It uses a single template file and combines it with partial views, meta tags, title and locale based on annotated routes files to create index.html files for each route. Just create new route components or update current routes and the application will automatically update the routes config during build.

Installation

npm i -D @aofl/@aofl/templating-plugin

Usage

const AofLTemplatingPlugin = require('@aofl/templating-plugin');

...
  plugins: [
    ...
    new AofLTemplatingPlugin({
      template: {
        name: 'main',
        template: path.resolve(__dirname, '..', 'templates', 'main', 'template.ejs'),
        filename: path.join('templates', 'main', 'template.html'),
        ...{ other html-webpack-plugin options }
      },
      routes: {
        mainRoutes: path.join(__dirname, '..', 'routes'),
        pattern: [
          path.join(__dirname, '..', 'routes', 'home', 'index.js')
        ],
        ignore: ['**/__build/**/*', '**/node_modules/**/*']
      }
    }),
    ...
  ]
...

Options

| Name | Type | Default | Description | |-----------|--------|------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------| | template | Object | {} | html-webpack-plugin options plus a name attribute that will be part of the route object. | | routes | Object | {} | Define route entry points. mainRoutes, pattern and optional ignore. | | partials | Object | {} | Used to define static partial templates object where the keys are the partials name and the values are html-webpack-plugin options. | | locale | String | en-US | Default locale for entry points. | | prerender | Object | { timeout: 0, externalServer: false, schema: 'http', host: 'localhost', port: 8090 } | Add timeout in ms on top of the when there are no more than 2 network connections for at least 500 ms. |

template

The template object is used with html-webpack-plugin to generate the html for the entry points. In addition to the html-webpack-plugin options you must specify a name for the template. This attribute will be part of the generated routes config object.

    ...
      new AofLTemplatingPlugin({
        template: {
          name: 'main',
          template: path.resolve(__dirname, '..', 'templates', 'main', 'template.ejs'),
          filename: path.join('templates', 'main', 'template.html'),
          ...htmlWebpackConfig(mode)
        }
        ...

routes

routes is used to find the routes entry files. We can have multiple routes folders but only one of these folders can be the mainRoutes. mainRoutes will be under routes key in the generated routes config. Any other routes-[anything here] folder will be added to the routes configs under [anything here] key. These routes can be used for (A/B testing).

  ...
    routes: {
      mainRoutes: path.join(__dirname, '..', 'routes'),
      pattern: [
        path.join(__dirname, '..', 'routes', 'other', 'index.js'),
        path.join(__dirname, '..', 'routes-a', 'home', 'index.js')
      ],
      ignore: ['**/__build/**/*', '**/node_modules/**/*']
    }
  ...

locale

options.locale specifes the default locale for the application. Each route can specify a locale in the route annotations as explained below.

partials

Static parial templates can be defined using partials key and can be added to template using template variables aoflTemplate:partial:[partial-name]. For Example, header and footer areas. Partials should be html-webpack-plugin options.

// webpack.config.js
...
  partials: {
    header: {
      template: path.join(__dirname, '..', 'js', 'header', 'view.ejs'),
      filename: path.join('js', 'header', 'view.html'),
      ...other-html-webpack-plugin-options
    }
  }
...
<!-- template.ejs -->
...
<body>
  aoflTemplate:partial:header
  ...

prerender

options.prerender allows for customizing the prerender server.

Template Keywords

aoflTemplate:locale

<!DOCTYPE html>
<html lang="aoflTemplate:locale">
  ...

aoflTemplate:title

<html lang="aoflTemplate:locale">
  <head>
    <title>aoflTemplate:title</title>
    ...

aoflTemplate:metaTags

 <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    aoflTemplate:metaTags
    ...

aoflTemplate:parial:[partial-name]

<!-- template.ejs -->
...
<body>
  aoflTemplate:partial:header
  ...

Route Annotation

@aofl/templating plugin generates the routes.config.js file based on comment blocks found in the index.js file of the routes.

/**
 * @route /
 * @title AofL::Home::CN
 * @metaTag {name:"description", content="Our awesome homepage"}
 * @metaTag {name:"viewport", content:"width=device-width, initial-scale=1"}
 * @meta {
 *   debug: false,
 *   template: 'main',
 *   requiresAuthentication: true
 * }
 * @prerender false
 * @locale zh-CN
 */

import template from './template';
import styles from './styles.css';
import AoflElement from '@aofl/web-components/aofl-element';
/**
 * @extends {AoflElement}
 */
class CnZhHomePage extends AoflElement {
  ...

Supported Tags | Name | Type | Description | |------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | @route | String | | | @title | String | Title of the page | | @metaTag | Object | Define a meta tag for the route. Multiple @metaTags can be used on a page. E.g. @metaTag {name:"viewport", content:"width=device-width, initial-scale=1"} | | @meta | Object | Application specific route meta data. | | @locale | String | Route specific locale. This value overrides the locale specified in the config. | | @prerender | String | Specifies whether the page should be pre-rendered during production build. |

example @aofl/unit-testing-plugin/routes.config.js

export default {
  'routes': [
    {
      'resolve': () => import('./routes-cn_zh/home/index.js'),
      'rotation': 'routes',
      'path': '/',
      'dynamic': false,
      'title': 'AofL::Home::CN',
      'meta': {
        'debug': false,
        'template': 'main',
        'requiresAuthentication': true,
      },
      'locale': 'zh-CN',
      'template': 'main'
    },
    {
      'resolve': () => import('./routes-cn_zh/login/index.js'),
      'rotation': 'routes',
      'path': '/login/',
      'dynamic': false,
      'title': 'AofL::Login::CN',
      'locale': 'zh-Cn',
      'template': 'main'
    }
  ],
  'b-test': [
    {
      'resolve': () => import('./routes-b-test/home/index.js'),
      'rotation': 'b-test',
      'path': '/',
      'dynamic': false,
      'title': 'AofL::Home::B',
      'locale': 'zh-CN',
      'template': 'main'
    }
  ]
};