Coder Social home page Coder Social logo

html-webpack-template's Introduction

HTML Webpack Template

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
    })
  ]
}

html-webpack-template's People

Contributors

bebraw avatar brandonboone avatar cameronhimself avatar clementparis016 avatar diegofaria avatar eliperelman avatar hairyrabbit avatar holyfirexx avatar ipanasenko avatar jaketrent avatar joepin avatar jpickwell avatar olistik avatar rafeememon avatar rbose85 avatar renjithgr avatar rowild avatar williamboman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.