npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pull-create-html

v2.0.0

Published

Create an html file from js and css file streams

Downloads

17

Readme

pull-create-html

Create an html file from js and css file streams

A stream that produces a html pull-stream file with optional settings such as a title, various meta options, js and css content streams, and a body, etc.

var pull = require('pull-stream')
var { read, write } = require('pull-files')
var bundle = require('pull-bundle-js')
var html = require('pull-create-html')

var js = pull(
  read(__dirname + '/lib/index.js'),
  bundle([ ...transforms ])
)

var css = pull(
  read(__dirname + '/style/**/*.sass'),
  sass()
)

// Create html from meta options + the js and css file streams
pull(
  html('foo.html', {
    // Meta options
    title: 'foo',
    body: '<div clas="app"></div>',
    meta: [
      { name: 'description', content: 'Example' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=0' }
    ]
    // File streams
    js,
    css 
  }),
  write(__dirname + '/out', err => {
    // Finished
  })
)

Install

npm i pull-create-html

Usage

html(path?, options)

Creates an html file from js and css file streams, with several options configure the boilerplate html.

  • js a stream of js files which put in <script>
  • css a stream of css files which get put in <style>
  • lang sets the <html lang=...> attribute. Defaults to en-US
  • title sets the <title>...</title> element
  • body is a string of HTML to put before where the JS is injected. e.g. a mount element for vdom
  • charset sets the <meta charset=...> element. Defaults to utf-8
  • base sets the file.base on the output HTML file
  • scriptAsync lets the JS files load async by setting <script async="true"> in the <head>
  • links Lets you specify <link> as a list of objects
  • meta Lets you specify <meta> as a list of objects

Files in the js/css stream are concatenated together. Allows streaming a directory of plain css files, for example.

pull(
  html('app.html', {
    title: 'Example site',
     
    js: pull(
      read(__dirname + '/lib/index.js'),
      bundle([ ...transforms ])
    ),

    css: pull(
      read(__dirname + '/style/index.sass'),
      sass()
    )
  }),
  write(__dirname + '/out', err => {
    // Finished
  })
)

For using options.links, you specify a list of objects:

links: [
  { href: 'foo.css', type: 'text/css', rel: 'stylesheet' }
  // ...
]

Likewise with options.meta:

meta: [
  { name: 'description', content: 'Foo bar baz!' },
  { name: 'keywords', content: 'example, test, foo, bar' },
  // ...
]

Also see


Maintained by Jamen Marz (See on Twitter and GitHub for questions & updates)