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

html-webpack-template-plugin

v0.7.1

Published

Simplifies creation of HTML files based on template and config file

Downloads

76

Readme

html-webpack-template-plugin

npm

travis appveyor Coverage Status

Simplifies creation of HTML files based on template and config file Edit.

In most MPA(Multi Page App) project, multi page modules share one context, common libraries etc, and under the same webpack build config. Also, every module own its index.html which include its resources with the awesome html-webpack-plugin.

This plugin is an enhancement of html-webpack-plugin. Every module shares one common index.html template, plugin will help it generate its unique index.html by reading its template config.

Installation


Instal the plugin with npm:

$ npm install html-webpack-template-plugin --save-dev

Usage


First create template file and module config file.

Template file parsed by template engine like handlebars or ejs, which support two common template syntax Mustache and Embedded JavaScript.

index.hds

<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  {{{metaTag meta}}}
  <title>{{title}}</title>
</head>
<body>
  {{#if body}}
  {{{body}}}
  {{else}}
  <div id="#app"></app>
  {{/if}}
  {{#each scripts}}
  <script src="{{this}}"></script>
  {{/each}}
</body>
</html>

As mentioned above, every module has own template config file. You can write it by yaml/json.

{{module}}/index.yml

title: 'page2'
body: '<p>This is page2</p>'
stylesheets:
  - 'https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.js'
scripts:
  - 'https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'

More examples under /example folder

const htmlWebpackPlugin = require('html-webpack-plugin')
const htmlTemplatePlugin = require('html-webpack-template-plugin')

var webpackConfig = {
  ...
  plugins: [
    ...
    // All modules htmlWebpackPlugin here
    new html-webpack-template-plugin({
      ...
    })
  ]
}

Configuration


  • root: project root path. Default to process.cwd().
  • engine: handlebars(default) | ejs.
  • template: [required] template file location.
  • variable: Object A map of predefined variables which will be injected into template and can be overwrote by config file.
  • helper: Object A map of view helpers which will be injected into template and can be overwrote by config file.
  • filter: Function A pure function which receives module config and html-webpack-plugin option, return the real config handled by view parser.

Extra options added in htmlWebpackPlugin:

  • disableTemplate: true | false(default).
  • scriptAttribute: Object A map of script attributes will be set

Tips


  • For boolean attribute, you can set collapseBooleanAttributes: true in html-webpack-plugin minify option to remove true/false value.

License


This project is licensed under MIT.