posthtml-load-options
Autoload Options for PostHTML
Last updated 5 years ago by michael-ciniawsky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install posthtml-load-options 
SYNC missed versions from official npm registry.

npm node deps tests coverage code style chat

<img width="140" height="120" title="Load Options" vspace="20" src="https://posthtml.github.io/posthtml-load-options/logo.svg"

Load Options

Autoload Options for PostHTML

Install

npm i -D posthtml-load-options

Usage

package.json

Create a posthtml section in package.json.

Root
  |– client
  |– public
  |
  |- package.json
{
  "dependencies": {
    "posthtml-sugarml": "^1.0.0"
  },
  "posthtml": {
    "parser": "posthtml-sugarss",
    "from": "path/to/src/file.html",
    "to": "path/to/dest/file.html"
  }
}

.posthtmlrc

Create a .posthtmlrc file.

Root
  |– client
  |– public
  |
  |-.posthtmlrc
  |- package.json
{
  "parser": "posthtml-sugarss",
  "from": "path/to/src/file.html",
  "to": "path/to/dest/file.html"
}

posthtml.config.js

Create a posthtml.config.js file.

Root
  |– client
  |– public
  |
  |- posthtml.config.js
  |- package.json
module.exports = (ctx) => {
  return {
    parser: ctx.ext ==='.sml' ? 'posthtml-sugarss' : false,
    from: 'path/to/src/file.html',
    to: 'path/to/dest/file.html'
  }
}

Options

parser:

parser: 'posthtml-sugarss'

from:

from: 'path/to/dest/file.html'

to:

to: 'path/to/dest/file.html'

render:

render: 'posthtml-jsx'

Context

When using a function in (posthtml.config.js), it's possible to pass context to posthtml-load-options, which will be evaluated before loading your options. By default ctx.env (process.env.NODE_ENV) and ctx.cwd (process.cwd()) are available.

Example

posthtml.config.js

export default config = (ctx) => {
  return {
    parser: ctx.ext === '.sml' ? 'posthtml-sugarml' : false,
    from: 'client/index.html',
    to: 'public/index.html'
  }
}

import { dirname } from 'path'
import { readFileSync } from 'fs'

import posthtml from 'posthtml'
import optionsrc from 'posthtml-load-options'

const sml = readFileSync('./client/index.sml', 'utf8')

const ctx = { ext: dirname(sml) }

optionsrc(ctx).then((options) => {
  posthtml()
    .process(sml, options)
    .then((result) => console.log(result.html))
}))

Maintainer


Michael Ciniawsky

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

2 Versions

  • 1.0.0                                ...           5 years ago
  • 1.0.0-alpha                                ...           6 years ago
Maintainers (2)
Downloads
Total 3,296
Today 0
This Week 76
This Month 153
Last Day 3
Last Week 43
Last Month 530
Dependencies (1)
Dev Dependencies (9)
Dependents (1)

Copyright 2014 - 2021 © npmmirror.com |