1.2.0 • Published 4 years ago

netlify-push-webpack-plugin v1.2.0

Weekly downloads
222
License
MIT
Repository
github
Last release
4 years ago

NetlifyPushWebpackPlugin

Generate HTTP2 Server Push _headers file for Netlify using HtmlWebpackPlugin.

For use with Webpack 4 and HtmlWebpackPlugin 4

Installation

npm i netlify-push-webpack-plugin

or

yarn add netlify-push-webpack-plugin

Usage

OptionTypeDescription
filenameStringName and path of the generated headers file
headersArrayOther headers to be added to the file (optional)
includeStringOnly include 'css', 'js' or 'all' (default: 'all')

Example

The following config

const HtmlWebpackPlugin = require("html-webpack-plugin");
const NetlifyServerPushPlugin = require("netlify-push-webpack-plugin");

module.exports = {
  plugins: [
    new HtmlWebpackPlugin(),
    new NetlifyServerPushPlugin({
      filename: "_headers",
      headers: [
        "  X-Frame-Options: DENY",
        "  Referrer-Policy: strict-origin-when-cross-origin",
        "/assets/*",
        "  Cache-Control: public, max-age:360000"
      ],
      include: "css"
    })
  ]
};

will result in a headers file looking something like this:

/*
  Link: <bundle.js>; rel=preload; as=script
  Link: <main.css>; rel=preload; as=style
  X-Frame-Options: DENY
  Referrer-Policy: strict-origin-when-cross-origin
/assets/*
  Cache-Control: public, max-age:360000

Testing

Tests are ran using using Ava with the following command:

npm run test
1.2.0

4 years ago

1.1.0

5 years ago

1.0.0

6 years ago