Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Autoload Config for PostHTML

License

NotificationsYou must be signed in to change notification settings

posthtml/posthtml-load-config

Repository files navigation

npmnodedepstestscoveragecode stylechat

Load Config

Autoload Config for PostHTML

Install

npm i -D posthtml-load-config

Usage

npm i -S|-D posthtml-plugin posthtml-plugin ...

Install plugins and save them to yourpackage.json

package.json

Create aposthtml section inpackage.json.

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

.posthtmlrc

Create a.posthtmlrc file.

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

posthtml.config.js

Create aposthtml.config.js file.

Root  |– client  |– public  |  |- posthtml.config.js  |- package.json
module.exports=(ctx)=>{return{parser:ctx.ext==='.sml' ?'posthtml-sugarml' :false,from:ctx.from,to:ctx.to,plugins:{'posthtml-plugin':ctx.plugin}}}

Plugins can be loaded either using an{Object} or an{Array} inconfig.plugins.

{Object}
module.exports=(ctx)=>{return{    ...options,plugins:{'posthtml-plugin':ctx.plugin}}}
{Array}
module.exports=(ctx)=>{return{    ...options,plugins:[require('posthtml-plugin')(ctx.plugin)]}}

⚠️ When using an Array, make sure torequire() 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 anempty object

[Object]: Plugin loads with given options.

'posthtml-plugin':{option:'',option:''}

false: Plugin will not be loaded.

'posthtml-plugin':false

Order

Pluginorder 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 toposthtml-load-config, which will be evaluated while loading your config. By defaultctx.env (process.env.NODE_ENV) andctx.cwd (process.cwd()) are available.

Examples

posthtml.config.js

module.exports=(ctx)=>({parser:ctx.ext==='.sml' ?'posthtml-sugarml' :false,from:ctx.from,to:ctx.to,plugins:{posthtml-include:{},posthtml-expressions:{locals:ctx.locals},htmlnano:ctx.env==='production' ?{} :false}})

"scripts": {"build":"NODE_ENV=production node posthtml","start":"NODE_ENV=development node posthtml"}
import{readFileSync}=require('fs')constposthtml=require('posthtml')constposthtmlrc=require('posthtml-load-config')constsml=readFileSync('index.sml','utf8')constctx={ext:'.sml'}posthtmlrc(ctx).then(({ plugins, options})=>{posthtml(plugins).process(sml,options).then((result)=>console.log(result.html))})

npm i -D gulp-posthtml

package.json

"scripts": {"build":"NODE_ENV=production gulp","start":"NODE_ENV=development gulp"}

gulpfile.js

import{task,src,dest}from'gulp'importpluginsfrom'gulp-load-plugins'task('pug',()=>{constctx={locals:{}}returnsrc('src/*.pug').pipe(posthtml(ctx)).pipe(rename({ext:'.html'})).pipe(dest('dest'))})task('sml',()=>{returnsrc('src/*.sml').pipe(posthtml()).pipe(rename({ext:'.html'})).pipe(dest('dest'))})task('html',()=>{returnsrc('src/*.html').pipe(posthtml()).pipe(dest('dest'))})

npm i -D html-loader posthtml-loader

package.json

"scripts": {"build":"NODE_ENV=production webpack","start":"NODE_ENV=development webpack-dev-server"}

webpack.config.js

module.exports=(env)=>{module:{rules:[{test:/\.html$/use:['html-loader','posthtml-loader']}]}}

Maintainer


Michael Ciniawsky

Contributors

About

Autoload Config for PostHTML

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp