@posthtml/esm
ESM Plugin for PostHTML
Last updated 7 years ago by michael-ciniawsky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @posthtml/esm 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.0                                ...           latest (7 years ago)

1 Versions

  • 1.0.0                                ...           7 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |