{"id":26445155,"url":"https://github.com/vinaypuppal/preact-cli-plugin-netlify","last_synced_at":"2025-03-18T11:15:19.810Z","repository":{"id":26895565,"uuid":"110321954","full_name":"vinaypuppal/preact-cli-plugin-netlify","owner":"vinaypuppal","description":"Preact cli plugin for generating h2push headers and redirects rules for netlify","archived":false,"fork":false,"pushed_at":"2022-12-04T02:55:23.000Z","size":527,"stargazers_count":25,"open_issues_count":9,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T02:23:14.452Z","etag":null,"topics":["netlify","preact","preact-cli","preact-cli-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinaypuppal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-11T05:53:03.000Z","updated_at":"2021-08-12T14:40:01.000Z","dependencies_parsed_at":"2022-07-27T08:52:32.861Z","dependency_job_id":null,"html_url":"https://github.com/vinaypuppal/preact-cli-plugin-netlify","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypuppal%2Fpreact-cli-plugin-netlify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypuppal%2Fpreact-cli-plugin-netlify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypuppal%2Fpreact-cli-plugin-netlify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinaypuppal%2Fpreact-cli-plugin-netlify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinaypuppal","download_url":"https://codeload.github.com/vinaypuppal/preact-cli-plugin-netlify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056430,"owners_count":20390720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["netlify","preact","preact-cli","preact-cli-plugin"],"created_at":"2025-03-18T11:15:19.182Z","updated_at":"2025-03-18T11:15:19.805Z","avatar_url":"https://github.com/vinaypuppal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# preact-cli-plugin-netlify\n\nPreact cli plugin for generating h2push headers and redirect(for SPA) rules for [netlify](https://www.netlify.com/)\n\n[![NPM version](https://img.shields.io/npm/v/preact-cli-plugin-netlify.svg)](https://www.npmjs.com/package/preact-cli-plugin-netlify)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n\n---\n\n**Netlify has disabled H2 Server Push. Please check [issue #11](https://github.com/vinaypuppal/preact-cli-plugin-netlify/issues/11) for more info.**\n\n---\n\n## Installation\n\n```bash\nyarn add preact-cli-plugin-netlify --dev\n```\n\nAlternatively using npm:\n\n```bash\nnpm i preact-cli-plugin-netlify --save-dev\n```\n\n## Usage\n\nAnd include in your project by creating a `preact.config.js`:\n\n```js\nconst netlifyPlugin = require('preact-cli-plugin-netlify');\n\nexport default function (config) {\n  netlifyPlugin(config);\n}\n```\n\n### Options\n\n#### Custom redirects\n\nIn addition to the generated redirects, you may want to supply your\nown rewrite rules. In this case, you can pass array of custom redirects to the plugin, such as\n\n```js\nexport default function(config) {\n    netlifyPlugin(config, {\n        redirects: [\n          '/api/* https://api.example.com/:splat 200',\n          '/custom/* https://custom.example.com/ 200'\n        ]\n    });\n}\n```\n\nwhich generates the following `_redirects` file:\n\n```yml\n/api/* https://api.example.com/:splat 200\n/custom/* https://custom.example.com/ 200\n/* /index.html 200\n```\n\n### mutateManifest\nThis plugin consumes the `push-manifest.json` created by `preact-cli` and derive Netlify headers from it.\nThere 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).\n\nFor this use mutateManifest as shown to mutate the JSON and the headers will be generated accordingly.\n\n```js\nexport default function(config) {\n    netlifyPlugin(config, {\n        mutateManifest: (routes)  =\u003e {\n          routes['/'].push(\n            // Add additonal assets you want to be preloaded at the index route\n          );\n          return routes;\n        }\n    });\n}\n```\n### Brotli compression\n\nPreact-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.\n\u003e For more info please check this blog post https://medium.com/@prateekbh/using-brotli-with-preact-cli-3-ca03125b1e2b\n\n```js\n  export default function(config, env) {\n    netlifyPlugin(config, {\n        brotli: env.brotli\n    });\n}\n```\n\nWhich generates below config in `_headers` file\n\n```yml\n/*.br\n  content-encoding: br\n```\n\n## Generated files\n\nThis plugin genererates `_headers` and `_redirects` files inside build folder\n\n### Example of genererated files\n\n```txt\n# _headers\n/*\n  Cache-Control: public, max-age=3600, no-cache\n  Access-Control-Max-Age: 600\n/sw.js\n  Cache-Control: private, no-cache\n/*.chunk.*.js\n  Cache-Control: public, max-age=31536000\n/\n  Link: \u003c/style.4f36e.css\u003e; rel=preload; as=style\n  Link: \u003c/bundle.10e55.js\u003e; rel=preload; as=script\n  Link: \u003c/route-home.chunk.47478.js\u003e; rel=preload; as=script\n/profile\n  Link: \u003c/style.4f36e.css\u003e; rel=preload; as=style\n  Link: \u003c/bundle.10e55.js\u003e; rel=preload; as=script\n  Link: \u003c/route-profile.chunk.e4eea.js\u003e; rel=preload; as=script\n```\n\n```txt\n# _redirects\n/* /index.html 200\n```\n\nYou can verify these rules at [netlify playground](https://play.netlify.com/)\n\n## Deploying to netlify\n\n- Install netlify cli\n  ```bash\n  npm install netlify-cli -g\n  ```\n- Deploy build folder\n  ```bash\n  netlify deploy -p build\n  ```\n\n## License\n\nMIT © [VinayPuppal](https://www.vinaypuppal.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinaypuppal%2Fpreact-cli-plugin-netlify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinaypuppal%2Fpreact-cli-plugin-netlify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinaypuppal%2Fpreact-cli-plugin-netlify/lists"}