Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@posthtml/esm

posthtml5.4kMIT1.0.0

ESM Plugin for PostHTML

esm, url, import, include, posthtml, posthtmlplugin

readme

npm node deps tests coverage code style chat

ESM Plugin

⚠️ These plugins are helpers mainly for html-loader to extract URL's and make them separate module request as ES2015 Module Imports and are not intended for general usage with posthtml. Other bundlers targeting ES2015 Modules (e.g Parcel, Rollup) may utilize them aswell, but usage besides webpack is currently untested. Feel free to open an issue if your integration requires changes

Install

npm i -D @posthtml/esm

Usage

const posthtml = require('posthtml')
const { urls, imports } = require('@posthtml/esm')

const html = `
<img src="path/to/url.png">
<import src="path/to/import.html"></import>
`
posthtml([ urls(), imports() ])
  .process(html, { from: './src/index.html' })
  .then((result) => {
    result.html
    result.messages
  })

result.html

<img src="${HTML__URL__0}">
${HTML__IMPORT__0}

result.messages

[
  {
    type: 'import',
    plugin: '@posthtml/esm',
    url: 'path/to/url.png',
    name: `HTML__URL__0`,
    import () {
      return `import ${this.name} from '${this.url}';\n`
    }
  },
  {
    type: 'import',
    plugin: '@posthtml/esm',
    url: 'path/to/import.html',
    name: `HTML__IMPORT__0`,
    import () {
      return `import ${this.name} from '${this.url}';\n`
    }
  }
]

Options

urls

Name Type Default Description
url {RegExp|Function} '' Filter URL's

{RegExp}

urls({
  url: /filter/
})

{Function<{String} -> {Boolean}>}

urls({
  url (url) {
    return /filter/.test(url)
  }
})

imports

Name Type Default Description
import {RegExp|Function} '' Filter Import URL's
template {String} '' Placeholder for HTML Templates

{RegExp}

imports({
  import: /filter/
})

{Function<{String} -> {Boolean}>}

imports({
  import (url) {
    return /filter/.test(url)
  }
})

Maintainer


Michael Ciniawsky

Contributors

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.0 (2018-01-23)

Features

  • import: add import plugin (105bf4e)
  • index: add url && import plugins (992cc9b)
  • url: add url plugin (b7fe4a8)