Include HTML Plugin
JavaScript HTML
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test addDependencyTo option Apr 30, 2016
.editorconfig Release v1.0.0 Sep 26, 2015
.gitignore Release v1.0.0 Sep 26, 2015
.jscsrc Release v1.0.0 Sep 26, 2015
.jshintignore Release v1.0.0 Sep 26, 2015
.jshintrc Release v1.0.0 Sep 26, 2015
.npmignore Release v1.0.0 Sep 26, 2015
LICENSE docs(LICENSE): add Jul 7, 2016
README.md docs(README): change style, update example Jul 7, 2016
index.js addDependencyTo option Apr 30, 2016
package.json 1.1.0 May 4, 2016

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.