All Projects → vinaypuppal → preact-cli-plugin-netlify

vinaypuppal / preact-cli-plugin-netlify

Licence: MIT license
Preact cli plugin for generating h2push headers and redirects rules for netlify

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to preact-cli-plugin-netlify

preact-cli-sw-precache
Preact cli plugin for configuring sw-precache
Stars: ✭ 19 (-24%)
Mutual labels:  preact, preact-cli-plugin
Weather Preactpi
A tiny UI for daily weather forcasts ⛈
Stars: ✭ 13 (-48%)
Mutual labels:  preact, netlify
Portfolio
Expo + Next.js Portfolio
Stars: ✭ 56 (+124%)
Mutual labels:  preact, netlify
preact-cli-plugin-typescript
Adds TypeScript support to preact-cli ⚡
Stars: ✭ 49 (+96%)
Mutual labels:  preact, preact-cli
web
Hugo content for the openshift.tips blog
Stars: ✭ 48 (+92%)
Mutual labels:  netlify
rainbow-explorer
🌈 A 20kb Preact & Redux based Progressive Web App that translates real life color to digital color.
Stars: ✭ 26 (+4%)
Mutual labels:  preact
sroberts.github.io
A landing page for great justice
Stars: ✭ 20 (-20%)
Mutual labels:  netlify
emacs-easy-jekyll
Emacs major mode for managing jekyll
Stars: ✭ 53 (+112%)
Mutual labels:  netlify
rustplatz
(Inoffizielle) Website für das Rust-Projekt von Dhalucard, Bonjwa und RocketBeans
Stars: ✭ 15 (-40%)
Mutual labels:  netlify
gatsby-minimal-portfolio
👔 JAMstack (Gatsby JS) content-focused portfolio blog starter. Features include dark-mode, installable PWA, SEO, code highlighting, form, CI/CD.
Stars: ✭ 36 (+44%)
Mutual labels:  netlify
shopnote
shopnote is a JAMstack application that helps in creating notes with shopping items. This application is built to showcase the JAMstack concept using Fauna, Netlify Serverless Functions and GatsbyJS.
Stars: ✭ 15 (-40%)
Mutual labels:  netlify
battlestax
BattleStax is a stateful JAMStack game that is wholesome fun for the entire crew.
Stars: ✭ 32 (+28%)
Mutual labels:  netlify
MikeRogersIO
The repo for my website
Stars: ✭ 16 (-36%)
Mutual labels:  netlify
maji
Maji is a framework to build great hybrid mobile apps.
Stars: ✭ 18 (-28%)
Mutual labels:  preact
anonymous-web
💬 A PreactJS powered progressive web (chat) application (Not active)
Stars: ✭ 28 (+12%)
Mutual labels:  preact
cvfy
CV generator built with Nuxt.js, TailwindCSS, deployed on Netlify.
Stars: ✭ 165 (+560%)
Mutual labels:  netlify
demo-portfolio
A demo portfolio website
Stars: ✭ 15 (-40%)
Mutual labels:  netlify
merkur
tiny extensible javascript library for front-end microservices
Stars: ✭ 45 (+80%)
Mutual labels:  preact
go-preact-starter
Starter for combining Go and Preact in any web project.
Stars: ✭ 19 (-24%)
Mutual labels:  preact
shopping-list-preact-pouchdb
Shopping List is an Offline First demo Progressive Web App built using Preact and PouchDB.
Stars: ✭ 18 (-28%)
Mutual labels:  preact

preact-cli-plugin-netlify

Preact cli plugin for generating h2push headers and redirect(for SPA) rules for netlify

NPM version XO code style styled with prettier


Netlify has disabled H2 Server Push. Please check issue #11 for more info.


Installation

yarn add preact-cli-plugin-netlify --dev

Alternatively using npm:

npm i preact-cli-plugin-netlify --save-dev

Usage

And include in your project by creating a preact.config.js:

const netlifyPlugin = require('preact-cli-plugin-netlify');

export default function (config) {
  netlifyPlugin(config);
}

Options

Custom redirects

In addition to the generated redirects, you may want to supply your own rewrite rules. In this case, you can pass array of custom redirects to the plugin, such as

export default function(config) {
    netlifyPlugin(config, {
        redirects: [
          '/api/* https://api.example.com/:splat 200',
          '/custom/* https://custom.example.com/ 200'
        ]
    });
}

which generates the following _redirects file:

/api/* https://api.example.com/:splat 200
/custom/* https://custom.example.com/ 200
/* /index.html 200

mutateManifest

This plugin consumes the push-manifest.json created by preact-cli and derive Netlify headers from it. There are cases where you might want to add preloads to a certain route or even add/modify a route(e.g. for dymanic routes you'll need to add a * to the route).

For this use mutateManifest as shown to mutate the JSON and the headers will be generated accordingly.

export default function(config) {
    netlifyPlugin(config, {
        mutateManifest: (routes)  => {
          routes['/'].push(
            // Add additonal assets you want to be preloaded at the index route
          );
          return routes;
        }
    });
}

Brotli compression

Preact-CLI have a flag --brotli which automatically generates brotli compressed assets for all the javascript files. To serve these files using netlify you can use brotli option as shown below.

For more info please check this blog post https://medium.com/@prateekbh/using-brotli-with-preact-cli-3-ca03125b1e2b

  export default function(config, env) {
    netlifyPlugin(config, {
        brotli: env.brotli
    });
}

Which generates below config in _headers file

/*.br
  content-encoding: br

Generated files

This plugin genererates _headers and _redirects files inside build folder

Example of genererated files

# _headers
/*
  Cache-Control: public, max-age=3600, no-cache
  Access-Control-Max-Age: 600
/sw.js
  Cache-Control: private, no-cache
/*.chunk.*.js
  Cache-Control: public, max-age=31536000
/
  Link: </style.4f36e.css>; rel=preload; as=style
  Link: </bundle.10e55.js>; rel=preload; as=script
  Link: </route-home.chunk.47478.js>; rel=preload; as=script
/profile
  Link: </style.4f36e.css>; rel=preload; as=style
  Link: </bundle.10e55.js>; rel=preload; as=script
  Link: </route-profile.chunk.e4eea.js>; rel=preload; as=script
# _redirects
/* /index.html 200

You can verify these rules at netlify playground

Deploying to netlify

  • Install netlify cli
    npm install netlify-cli -g
  • Deploy build folder
    netlify deploy -p build

License

MIT © VinayPuppal

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].