• Stars
    star
    829
  • Rank 55,018 (Top 2 %)
  • Language EJS
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a better default template for html-webpack-plugin

HTML Webpack Template

Note - Support for this template is lagging Webpack. This currently only supports (old!) webpack v3. I'm looking for contributors who would like to give it some loving upgrades.

This is a template for the webpack plugin html-webpack-plugin. It has a few extra features more than the default template which will hopefully make it less likely that you'll have to create your own index.html file in your webpack project.

Templates for the html-webpack-plugin are implemented using underscore templates (previously, in 2.x, blueimp templates). You can write your own as well.

Legacy version

For the legacy version that works with [email protected], npm install html-webpack-plugin@2.

Installation

Install the template in your project with npm:

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

Basic Usage

To make it work, you need to provide these required parameters:

  • inject: false
  • template: require('html-webpack-template')

And you can provide some other optional parameters:

  • appMountId: The <div> element id on which you plan to mount a JavaScript app.
  • appMountHtmlSnippet: A small snippet of HTML that will be inserted in the <div> element the appMountId is attached to.
  • appMountIds: An array of application element ids.
  • baseHref: Adjust the URL for relative URLs in the document (MDN).
  • devServer: Insert the webpack-dev-server hot reload script at this host:port/path; e.g., http://localhost:3000.
  • googleAnalytics.trackingId: Track usage of your site via Google Analytics.
  • googleAnalytics.pageViewOnLoad: Log a pageview event after the analytics code loads.
  • lang: String identifying your content language
  • links: Array of <link> elements.
    • If an array element is a string, the value is assigned to the href attribute and the rel attribute is set to "stylesheet";
    • If an array element is an object, the object's properties and values are used as the attribute names and values, respectively.
  • meta: Array of objects containing key value pairs to be included as meta tags.
  • mobile: Sets appropriate meta tag for page scaling.
  • inlineManifestWebpackName: For use with inline-manifest-webpack-plugin.
  • scripts: Array of external script imports to include on page.
    • If an array element is a string, the value is assigned to the src attribute and the type attribute is set to "text/javascript";
    • If an array element is an object, the object's properties and values are used as the attribute names and values, respectively.
  • window: Object that defines data you need to bootstrap a JavaScript app.
  • headHtmlSnippet: A small snippet of HTML that will be inserted in the head element.
  • bodyHtmlSnippet: A small snippet of HTML that will be inserted in the body element.

Plus any html-webpack-plugin config options otherwise available.

Example

Here's an example webpack config illustrating how to use these options in your webpack.config.js:

{
  // ...
  plugins: [
    new HtmlWebpackPlugin({
      // Required
      inject: false,
      template: require('html-webpack-template'),
      // template: 'node_modules/html-webpack-template/index.ejs',

      // Optional
      appMountId: 'app',
      appMountHtmlSnippet: '<div class="app-spinner"><i class="fa fa-spinner fa-spin fa-5x" aria-hidden="true"></i></div>',
      headHtmlSnippet: '<style>div.app-spinner {position: fixed;top:50%;left:50%;}</style >',
      bodyHtmlSnippet: '<custom-element></custom-element>',
      baseHref: 'http://example.com/awesome',
      devServer: 'http://localhost:3001',
      googleAnalytics: {
        trackingId: 'UA-XXXX-XX',
        pageViewOnLoad: true
      },
      meta: [
        {
          name: 'description',
          content: 'A better default template for html-webpack-plugin.'
        }
      ],
      mobile: true,
      lang: 'en-US',
      links: [
        'https://fonts.googleapis.com/css?family=Roboto',
        {
          href: '/apple-touch-icon.png',
          rel: 'apple-touch-icon',
          sizes: '180x180'
        },
        {
          href: '/favicon-32x32.png',
          rel: 'icon',
          sizes: '32x32',
          type: 'image/png'
        }
      ],
      inlineManifestWebpackName: 'webpackManifest',
      scripts: [
        'http://example.com/somescript.js',
        {
          src: '/myModule.js',
          type: 'module'
        }
      ],
      title: 'My App',
      window: {
        env: {
          apiHost: 'http://myapi.com/api/v1'
        }
      }

      // And any other config options from html-webpack-plugin:
      // https://github.com/ampedandwired/html-webpack-plugin#configuration
    })
  ]
}

More Repositories

1

svelte-getting-started

Materials for my Svelte: Getting Started course
Svelte
33
star
2

npm-ls-scripts

List runnable npm scripts
JavaScript
26
star
3

react-drift

Styling React Components - Pluralsight course material
JavaScript
20
star
4

react-dnd-text-dragpreview

easy text drag preview for react-dnd
JavaScript
16
star
5

styling-react-components

Course materials for Styling React Components
JavaScript
14
star
6

demo-single-change-handler

JavaScript
13
star
7

tmux-snazzy

Snazzy theme for tmux
9
star
8

redux-react-connect-by-name

JavaScript
9
star
9

demo-electron-directory

Short example on how to communicate from Main to Renderer
JavaScript
8
star
10

react-config

basic react project config
JavaScript
7
star
11

electron-fundamentals

Materials for my Electron Fundamentals course
JavaScript
5
star
12

redux-types

redux action type namespacing
JavaScript
5
star
13

hello-styled-component-primitives

JavaScript
4
star
14

require-i18n-demo

Demo for requirejs i18n functionality
JavaScript
4
star
15

xquery-suez

A bit of MarkLogic xquery code to extract channel info and display
XQuery
3
star
16

react-with-display-name

JavaScript
3
star
17

backbone-intro

Simple BackboneJs project for demo
JavaScript
3
star
18

hello-nightwatch

nightwatch.js demo
JavaScript
3
star
19

combine-google-takeout

collect select bits from google takeout
Shell
3
star
20

electron-course

electron.js pluralsight course landing page
JavaScript
2
star
21

hello-static-site-generator-webpack-plugin

demo of static site with webpack
JavaScript
2
star
22

json-linker

Provides linking compatible with jsonapi
CoffeeScript
2
star
23

react-stint

lib to create timelines
JavaScript
2
star
24

broccoli-ember-emblem

broccoli plugin to compile emblem templates for ember
JavaScript
2
star
25

jquery-safesubmit

jQuery plugin to keep ajax form submission from happening twice
2
star
26

express-validator-errors

Error json serializer for consistent errors when using express-validator
CoffeeScript
2
star
27

dayone-plist-to-markdown

convert dayone .doentry to markdown files
JavaScript
2
star
28

clipmaster-9000-tutorial

Electron toy
JavaScript
2
star
29

react-chart-loading

fun chart loading spinner
JavaScript
2
star
30

demo-scroll-restoration

manually restore scroll position on refresh
JavaScript
2
star
31

express-ls-routes

cli and route to list routes in your express app
CoffeeScript
1
star
32

firesale-tutorial

Electron toy
JavaScript
1
star
33

vault

data api
CSS
1
star
34

templeprep5

lesson slides synced via websockets
HTML
1
star
35

elm-examples

Elm
1
star
36

gowiththeflowtype-materials

Materials for my Flowtype Fundamentals course
1
star
37

d3-preso

JavaScript
1
star
38

daily-bread

daily inspiration
JavaScript
1
star
39

tacbac

JavaScript
1
star
40

algo-wat

JavaScript
1
star
41

rolen

timeline for work log
JavaScript
1
star
42

whitepine

HTML
1
star
43

elm-form-demo

Elm
1
star
44

night-data

Ruby
1
star
45

mormonorgfam

JavaScript
1
star
46

spyquire

require() replacement for a test environment that allows easy spying
JavaScript
1
star
47

reason-kata-map

basic intro to reasonml language
OCaml
1
star
48

svelte-library

Svelte
1
star
49

aprilandjake

aprilandjake.com site code
CoffeeScript
1
star
50

demo-selfreg

simple demo for react views
JavaScript
1
star
51

aprilandjake-data

Ruby
1
star
52

galleria

Python
1
star
53

slackbot-emails

retrieves all user emails in a slack channel
JavaScript
1
star
54

try-tdd

exercise for introducing tdd
JavaScript
1
star
55

rockycode

site code
Python
1
star
56

fizzbreaker

fizzbreaker.com site code
JavaScript
1
star
57

jquery-togglestate

jQuery plugin to connect the state of form elements with other form elements
1
star
58

realcount

JavaScript
1
star
59

hello-ses

JavaScript
1
star
60

react-shell

empty react, postcss, webpack app shell
JavaScript
1
star
61

gratigoose

JavaScript
1
star
62

svelte-with-react

JavaScript
1
star
63

finland

Music catalog and player for the Finns
JavaScript
1
star
64

toppier

JavaScript
1
star
65

annephoto

JavaScript
1
star
66

builtbyjake

Recent projects portfolio
CSS
1
star