JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q29682F
  • License MIT

PostHTML for Express

Package Exports

  • express-posthtml

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-posthtml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm dependencies

Install

(sudo) npm i -S express-posthtml

Usage

Engine

Register PostHTML as View Engine

app.engine('html', require('express-posthtml'))

app.set('views', /* Path to views */)
app.set('view engine', 'html')

Plugins

Global

All Views will be render with this plugin setup, if no local setup provided.

app.set('view options', [ PostHTML Plugins ])
res.render('file')

Local

View specific setup by adding plugins separately to the respective routes. Note that if you have set plugins globally, routes with local setup will not use the global setup by default.

app.set('view options', [])
res.render('file', { plugins: [ PostHTML Plugins ] })

Extend

If views share common plugins (e.g for BEM Support), but view specific additions are necessary, use the extend option. Now the global setup is used and will be extended with the local plugins of the respective route.

app.set('view options', [ PostHTML Global Plugins ])
res.render('file', { plugins: [ PostHTML Local Plugins ], extend: true, })

Example

Plugins

'use strict'

// Plugins
const bem = require('posthtml-bem')
const each = require('posthtml-each')
const include = require('posthtml-include')

// App
const express = require('express')

let app = express()

// App Engine
app.engine('html', require('express-posthtml'))

// Settings
app.set('views', /* Path to views */)
app.set('view engine', 'html')
app.set('view options', [ include(), bem(), ]) // Global Setup

// Global Use
app.get('/', (req, res) => {
    res.render('file')
  })
// Local Use
app.get('/local', (req, res) => {
    res.render('file', { plugins: [ include(), bem({
      elemPrefix: '_',
      modPrefix: '-',
      modDlmtr: '--'})
    ] })
  })
// Extend Use
app.get('/extend', (req, res) => {
    res.render('file', { plugins: [ each() ], extend: true } )
  })  

app.listen(3000, () => {
    console.log('==> Server started')
  }
)

Package

'use strict'

// Package
const html = require('posthtml-package-html')(/* options */)

// Package for local use
const html_local = require('posthtml-package-html')({
  bem: { elemPrefix: '_', modPrefix: '-', modDlmtr: '--'}
})

// App
const express = require('express')

let app = express()

// App Engine
app.engine('html', require('express-posthtml'))

app.set('views', /* Path to views */)
app.set('view engine', 'html')
app.set('view options', html) // Global Setup

// Global Use
app.get('/', (req, res) => {
  res.render('file')
})

// Local Use
app.get('/local', (req, res) => {   
  res.render('file', { plugins: html_local })
})

// Extend Use
app.get('/extend', (req, res) => {   
  res.render('file', { extend: true, plugins: [
    require('posthtml-style-to-file')({ path: './public/styles/style.css' })   
  ] })
})

app.listen(3000, () => {
    console.log('==> Server started')
  }
)