一覧へ戻る
phtmlorg/rollup-plugin-phtml(新しいタブで開きます)
主要言語: JavaScript
Use pHTML with Rollup
- star 数
- 4
- watcher 数
- 1
- fork 数
- 0
- issue 数
- 0
- 最終更新
- 2019/05/17
主要言語: 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'