Git Product home page Git Product logo

html-webpack-static-assets-plugin's Introduction

Install

  npm i --save-dev html-webpack-static-assets-plugin
  yarn add --dev html-webpack-static-assets-plugin

This is an extenstion of HtmlWebpackPlugin (version 4+ required!) . It allows you to extend a list of tags (head and body) created by HtmlWebpackPlugin. Remeber to add it after HtmlWebpackPlugin.

F.E preload fonts with a hashes in filename.

webpack.config.js

const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackStaticAssetsPlugin = require("html-webpack-static-assets-plugin");

module.exports = {
  [...], // Other options
  plugins: [
   new HtmlWebpackPlugin(),
   new HtmlWebpackStaticAssetsPlugin(HtmlWebpackPlugin, {
      headTags: [
        {
          test: /\.woff/,
          tagName: "link",
          rel: "preload",
          as: "font",
          type: "font/[.ext]",
          crossorigin: true
        }
      ]
    }),
  ]
}

This will generate a file index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <link href="your_font_file_name.e233e73e5a234da8c6c66016c0c6c597.woff" rel="preload" as="font" type="font/woff" crossorigin>
    <link href="assets/your_font_file_name_2.47dcabd1d0b56f2718585fc6691c5d9e.woff" rel="preload" as="font" type="font/woff" crossorigin>
  </head>
  <body>
    <script src="index_bundle.js"></script>
  </body>
</html>

Options

name type Default Description
bodyTags array [] A list of tags to be added to the body tag
headTags array [] A list of tags to be added to the head tag

Single Tag Options

It's just an overview. You can add any type of tag attribute.

name type Required Description
test RegExp yes RegExp to search for a files
tagName String yes The name of the tag to be created
rel String no "rel" attribute
as String no "as" attribute
type String no "type" attribute ([.ext] will be converted to a file extension)
crossorigin Boolean no "crossorigin" attribute

html-webpack-static-assets-plugin's People

Contributors

dawgoc avatar dependabot[bot] avatar

Watchers

 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.