Back to results
phtmlorg/rollup-plugin-phtml(opens in a new tab)
Language: JavaScript
Use pHTML with Rollup
- stars
- 4
- watchers
- 1
- forks
- 0
- open issues
- 0
- Last updated
- 05/17/2019
Language: JavaScript
Use pHTML with Rollup
rollup-plugin-phtml lets you use pHTML with Rollup.
Add rollup-plugin-phtml to your project:
npm install rollup-plugin-phtml --save-dev
Use rollup-plugin-phtml in your Rollup configuration:
// rollup.config.js import phtml from 'rollup-plugin-phtml'; export default { plugins: [ phtml({ /* Plugins */ plugins: [], // Array | Plugin | Function /* Process Options */ processOptions: {} // Object }) ] }
Then you can use HTML files:
import pageHTML from './page.html';
The plugins property determines which pHTML plugins are applied.
phtml({ plugins: require('@phtml/image-alt') })
phtml({ plugins: [ require('@phtml/image-alt'), require('@phtml/image-size')({ intrinsicsize: 'intrinsic' }) ] })
The processOptions property determines which pHTML custom settings are
applied.
phtml({ processOptions: { voidElements: ['path', 'source', 'use'] } })
The inject option allows HTML imports to be injected into the document. By
default, this features is disabled.
phtml({ inject: true })
When true, HTML is injected into <body> if it is available.
// Inject to `<body>` import './page.html'
The HTML string is still available as the default export.
// Inject to `<body>` and also available as `pageHTML` import pageHTML from './page.html'
When a String, HTML is injected into the matching selector, if it is available.
phtml({ inject: 'html > head:first-child' // ↑ the selector is unnecessary verbose for demonstration purposes })
// Inject to `<head>` import './page.html'