Skip to content
Include HTML Plugin
JavaScript HTML
Branch: master
Clone or download
Latest commit e4f2a57 Jun 26, 2018

README.md

NPM Deps Tests Coverage

Include Plugin

Install

npm i -D posthtml-include

Usage

const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const include = require('include')

const html = readFileSync('index.html')

posthtml([ include({ encoding: 'utf8' }) ])
    .process(html)
    .then((result) => console.log(result.html))

Options

root: Root folder path for include. Default ./

encoding: Default utf-8

addDependencyTo: An object with addDependency() method, taking file path as an argument. Called whenever a file is included. Default null. You can use it for hot-reloading in webpack(posthtml-loader) like this:

posthtml: (webpack) => {
  return [
    require('posthtml-include')({ addDependencyTo: webpack })
  ]
}

Usage

index.html

<html>
<head>
    <title>index.html</title>
</head>
<body>
    <include src="components/button.html"></include>
</body>
</html>

components/button.html

<button class="button"><div class="button__text">Button</div></button>
const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const include = require('include')

const html = readFileSync('index.html')

posthtml([ include({ encoding: 'utf8' }) ])
    .process(html)
    .then((result) => console.log(result.html))
<html>
<head>
  <title>index.html</title>
</head>
<body>
  <button class="button">
    <div class="button__text">Text</div>
  </button>
</body>
</html>

LICENSE

MIT License (MIT)

Copyright (c) PostHTML Ivan Voischev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.