Install
npm i -D posthtml-load-config
Usage
npm i -S|-D posthtml-plugin posthtml-plugin ...
Install plugins and save them to your package.json
package.json
Create a posthtml
section in package.json
.
Root
|– client
|– public
|
|- package.json
.posthtmlrc
Create a .posthtmlrc
file.
Root
|– client
|– public
|
|-.posthtmlrc
|- package.json
posthtml.config.js
Create a posthtml.config.js
file.
Root
|– client
|– public
|
|- posthtml.config.js
|- package.json
module { return parser: ctxext === '.sml' ? 'posthtml-sugarml' : false from: ctxfrom to: ctxto plugins: 'posthtml-plugin': ctxplugin }
Plugins can be loaded either using an {Object}
or an {Array}
in config.plugins
.
{Object}
module { return ...options plugins: 'posthtml-plugin': ctxplugin }
{Array}
module { return ...options plugins: ctxplugin }
⚠️ When using an Array, make sure to
require()
them.
Options
parser
:
parser: 'posthtml-sugarml'
from
:
from: 'path/to/src/file.sml'
to
:
to: 'path/to/dest/file.html'
render
:
render: 'posthtml-jsx'
Plugins
Options
{} || null
: Plugin loads with defaults.
'posthtml-plugin': {} || null
⚠️
{}
must be an empty object
[Object]
: Plugin loads with given options.
'posthtml-plugin': option: '' option: ''
false
: Plugin will not be loaded.
'posthtml-plugin': false
Order
Plugin order is determined by declaration in the plugins section.
plugins: 'posthtml-plugin': {} // plugins[0] 'posthtml-plugin': {} // plugins[1] 'posthtml-plugin': {} // plugins[2]
Context
When using a function (posthtml.config.js)
, it is possible to pass context to posthtml-load-config
, which will be evaluated while loading your config. By default ctx.env (process.env.NODE_ENV)
and ctx.cwd (process.cwd())
are available.
Examples
posthtml.config.js
module parser: ctxext === '.sml' ? 'posthtml-sugarml' : false from: ctxfrom to: ctxto plugins: posthtml-include: {} posthtml-expressions: locals: ctxlocals htmlnano: ctxenv === 'production' ? {} : false
"scripts":
const posthtml = const posthtmlrc = const sml = const ctx = ext: '.sml'
npm i -D gulp-posthtml
package.json
"scripts":
gulpfile.js
npm i -D html-loader posthtml-loader
package.json
"scripts":
webpack.config.js
module { module: rules: test: /\.html$/ use: 'html-loader' 'posthtml-loader' }
Maintainer
Michael Ciniawsky |