{"_id":"rollup-route-manifest","_rev":"2-3cbbebf39a73878d8340b5a63f5e512f","name":"rollup-route-manifest","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.0":{"version":"0.0.0","name":"rollup-route-manifest","description":"WIP","repository":{"type":"git","url":"git+https://github.com/lukeed/rollup-route-manifest.git"},"module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"scripts":{"build":"bundt","test":"uvu -r esm test"},"engines":{"node":">=8"},"dependencies":{"route-sort":"^1.0.0"},"devDependencies":{"bundt":"1.1.1","esm":"3.2.25","uvu":"0.4.0"},"keywords":["route","manifest","code-split","route-manifest","rollup-plugin","rollup"],"bugs":{"url":"https://github.com/lukeed/rollup-route-manifest/issues"},"homepage":"https://github.com/lukeed/rollup-route-manifest#readme","_id":"rollup-route-manifest@0.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"integrity":"sha512-fl+bK2WazeV9r0B6RXyEAM9FG48ebVWOdP5ckmVDPyckJfU2/iyNU0laOcmo/WFm5XbdiClIAWn9AIufDR9PlQ==","shasum":"185e1456c2a6a3e8cfece64c90ee48844f98d391","tarball":"https://registry.npmjs.org/rollup-route-manifest/-/rollup-route-manifest-0.0.0.tgz","fileCount":4,"unpackedSize":11769,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfoe7hCRA9TVsSAnZWagAANLYQAJEGVI/bo/gxm5qGsB47\njBUq1rAK5trF18sDFux+MkFJaL+s6r5i/KyKB3NpZwmjY0940sMG3JHoR3vK\n7LaZJs1toFloHUOjQTJmz1WLuGOuvNWAf8d3L36sjlud74/qC1APdH+5snan\nfzfH0VDoprq9pO0DFgUIjSAX1Bdec4ku0ZclCscBIjnsbj1oO4POU084LjRc\n+19Bosh9q8Tn2CtrfsOMz5iIbqCvxOC+FXBX2HEAArR0w7PmQfxG9BQeKHE6\nBBd48Hhi03Q1PRXeLNHVNDvm0DpxfS7qQUbG6+uconIBXmhpramYJW+pp+ML\nBlqh3glcWP3m55qsx/cJG5JbMpYqA9yPEPmEJZ6bwlOm360bzD/MZPHILUfe\nwP/4e3+/7qYYBb/8ACHUAG3uVCpud5RlflLob2JRBSUoYRXvIFzXX+fEFHFp\nLpyG6eVtU+N+mKsw8JkQaS72F9vCnBHNT+wJqLRRHqmg5fn9EaqfIEC/MRy3\nJszDSeTs6x385NBj/mv2odLZft7TanoZnUVMzgp2XxRZ/5tw6nIPbLz1wyQq\noS5ehO4hz35Q8uiCBACj/2IFG+ldrhnMOzytpUTo9pJSUTenG4rfgOBa35th\nItK+ph2mAo18sXDzTJjJdu2i40PRpUsifZGUMzSjC/KgXZdLq1yGI3LIliQ3\n7maZ\r\n=/QCg\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCSKG6f9PJFbNR+aDmM6obRU+pfejXacH6hnjwv9VSi5AIhAKIaboFtAU7NlnB6SDiB8UrMp7X72cuKrb7+XtS2AU1I"}]},"directories":{},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-route-manifest_0.0.0_1604447968534_0.052737803594363086"},"_hasShrinkwrap":false},"1.0.0":{"version":"1.0.0","name":"rollup-route-manifest","description":"A Rollup plugin to generate an asset manifest, keyed by route patterns!","repository":{"type":"git","url":"git+https://github.com/lukeed/rollup-route-manifest.git"},"module":"dist/index.mjs","main":"dist/index.js","types":"index.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"scripts":{"build":"bundt","test":"uvu -r esm test -i fixtures"},"engines":{"node":">=8"},"dependencies":{"route-sort":"^1.0.0"},"peerDependencies":{"rollup":">=2.0.0"},"devDependencies":{"bundt":"1.1.1","esm":"3.2.25","klona":"2.0.4","uvu":"0.4.0"},"keywords":["route","manifest","code-split","route-manifest","rollup-plugin","rollup"],"gitHead":"cc117bb9d915f2c76d82da4ce95ab20bd37fbeb8","bugs":{"url":"https://github.com/lukeed/rollup-route-manifest/issues"},"homepage":"https://github.com/lukeed/rollup-route-manifest#readme","_id":"rollup-route-manifest@1.0.0","_nodeVersion":"12.18.4","_npmVersion":"6.14.6","dist":{"integrity":"sha512-3CmcMmCLAzJDUXiO3z6386/Pt8/k9xTZv8gIHyXI8hYGoAInnYdOsFXiGGzQRMy6TXR1jUZme2qbdwjH2nFMjg==","shasum":"74a7e910694583f1206e62e70b478af74a1a7ce8","tarball":"https://registry.npmjs.org/rollup-route-manifest/-/rollup-route-manifest-1.0.0.tgz","fileCount":6,"unpackedSize":22077,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfowTNCRA9TVsSAnZWagAAJSkP/08AaiIOiG1aD+xYY9eI\n0OR/LVuIoJydkpMW66fTZJDTE8uEU2cNa7uICcGIQuYlyxL/BerteLm8r9xY\nIDXxB6QWlyotqNx9rhMyz/iuVmKOKsFKZ0Q+UsfeXxfFYT4aR42zM0O6mcD2\n8dD9svYWGhYSQqKV2WPrhkyWn5LW8MNkLJWuiho06zFH1qZrftaWYoU+hp8q\nxIRwxvbGaI0yGR3mg3oJ64O93PgU90D4JVs4U+oK/bzk33u20ZQPyeNjAOo8\n418MaT7eIgcqFxuuQYrDSOu/7c9JHQt7R/rHPnhLhgM2BD5vbc35FdXtoGMO\n/99Et90D0Af0+5JpH1BUvxjD5lKTfeM/APTffG/8/30Eozrvw7XpcAYvkjZg\noOZcAF3VZ2TJoOjRUftqKiq6gcOQhrdmapGqmeFqZpzxlFCppwxuJtDoVtEi\n99Bx3mBZDWtvU65DAdgx0CgrrwD2GazEzvBPIU5f0yOa0VlIRk4rc53xyhML\nynm9I/KVhU1+Ij22/v5iADA5eH51H8DdnRXD6REzsxyamdplFqzcED3wbJ2v\naZrjWQWUvTGsaV0Fv4DPV+lfeq2qLYyovJ88vulCpRvP9MHA5PZL8oBAeyBl\n/Xw2pfu2Gtv+65SYwa4XxyrFoU3ti0BdZIvCVd59er4VdzrnRNO6tJ7xljnw\nEt9m\r\n=nNrQ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHeQaE7BMhOu/cr46Ph9qWmFj2jWb000R3Awv/uJVTcVAiBST5mCHDMpUX94QwHFFFBOMdXks+v3Qb7I2n7ryCBXrQ=="}]},"_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"directories":{},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rollup-route-manifest_1.0.0_1604519116896_0.15552070605205737"},"_hasShrinkwrap":false}},"time":{"created":"2020-11-03T23:59:28.534Z","0.0.0":"2020-11-03T23:59:28.654Z","modified":"2022-05-16T04:45:38.378Z","1.0.0":"2020-11-04T19:45:17.023Z"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"description":"A Rollup plugin to generate an asset manifest, keyed by route patterns!","homepage":"https://github.com/lukeed/rollup-route-manifest#readme","keywords":["route","manifest","code-split","route-manifest","rollup-plugin","rollup"],"repository":{"type":"git","url":"git+https://github.com/lukeed/rollup-route-manifest.git"},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"https://lukeed.com"},"bugs":{"url":"https://github.com/lukeed/rollup-route-manifest/issues"},"license":"MIT","readme":"# rollup-route-manifest [![CI](https://github.com/lukeed/rollup-route-manifest/workflows/CI/badge.svg)](https://github.com/lukeed/rollup-route-manifest/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/rollup-route-manifest)](https://codecov.io/gh/lukeed/rollup-route-manifest)\n\n> A Rollup plugin to generate an asset manifest, keyed by route patterns!\n\n***The Context***\n\nModern applications (should!) take advantage of route-based code splitting. This enables an application to be compartmentalized into smaller pieces, and to only load those pieces when needed. The common/immediate benefit is that your clients' first page-load requires dramatically less code, which results in a faster experience.\n\n***The Problem***\n\nWhile amazing, this isn't (yet) a perfect solution. The client will need to navigate to other pages!\n\nLet's assume the client checks out the `/blog` page. <br>\nIn most configurations, the blog's assets only start downloading **after** the click has been made. Typically, the main \"entrypoint\" for `/blog` will load, but _only then_ will the additional assets it requires be requested. This cascade of \"oh yeah, we need that too\" can easily get out of hand.\n\nWhat this means is that despite our super speedy, well-optimized application, the client is still waiting for assets. Our application is at the mercy of the client's network connection.\n\nUntil all the assets for `/blog` have loaded, our client may be staring at a loading screen/spinner, or – worse – a split-second flash of the loader.\n\n***The Solution***\n\nWith this plugin, you regain control of your application's assets and how they're loaded. :muscle:\n\nYou are given the knowledge of exactly which files are _going to be requested_ for each route of your application.\n\nIn turn, this means you can preemptively load _all_ the assets for `/blog` _before_ the client clicks – or begin prefetching _everything_ `/blog` needs immediately after the click – skipping the \"oh yeah\"-cascade and decreasing wait time(s).\n\n***Further Reading***\n\n* https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content\n* https://www.smashingmagazine.com/2016/02/preload-what-is-it-good-for/\n* https://w3c.github.io/preload/#x2.link-type-preload\n\n\n## Install\n\n```\n$ npm install rollup-route-manifest --save-dev\n```\n\n\n## Usage\n\n```js\n// rollup.config.js\nimport Manifest from 'rollup-route-manifest';\n\nexport default {\n  // ...\n  plugins: [\n    // ...\n    Manifest({\n      merge: true,\n      minify: true,\n      routes(file) {\n        // Assume all \"routes\" in \"/path/to/src/pages/\" directory\n        file = file.replace('/path/to/src', '').replace(/\\.[tj]sx?$/, '');\n        if (!file.includes('/pages/') return '*'; // commons\n\n        let name = '/' + file.replace('/pages/', '');\n        if (name === '/error') return false; // ignore\n\n        if (name === '/article') return '/blog/:title';\n        return name === '/home' ? '/' : name;\n      }\n    })\n  ]\n}\n```\n\n## Options\n\n#### options.routes\nType: `Function` or `Object`<br>\nRequired: `true`\n\nMap absolute file paths to the URL route patterns that represent them.\n\n> **Important:** This is the **only** required option.\n\nWhen `routes` is a function, it receives absolute paths (`string`) and expects a pattern (string) to be returned. You may return a falsey value to ignore the file, which _will not_ create a new key in the route manifest.\n\n```js\nroute(file) {\n  if (file.includes('/error.js')) return false; // skip\n  if (!file.includes('/routes/')) return '*'; // commons chunk\n  let name = file.replace('/path/to/routes/', '').replace(/\\.[tj]sx?$/, '');\n  if (name === 'article') return '/blog/:slug';\n  return name === 'home' ? '/' : name;\n}\n```\n\nWhen `routes` is an object, its keys must match the abolsute path and its values must be the pattern strings. Any unmatched absolute paths are ignored – as are any falsey values. Ignored files _will not_ create a new key in the route manifest.\n\n```js\nroutes: {\n  '/path/to/src/index.js': '*',\n  '/path/to/routes/home.js': '/',\n  '/path/to/routes/article.js': '/blog/:slug',\n  // falsey and/or no match ~> ignore\n  // '/path/to/routes/error.js': false\n}\n```\n\n\n#### options.assets\nType: `Function` or `Object`\n\nCustomize the `type` or `as` value of an asset by looking at its filename.\n\n> **Important:** You may also return a falsey value to exclude the asset from the manifest.\n\nThe `assets` option receives the assets' filenames, which are used to return a valid [resource \"destination\"](https://fetch.spec.whatwg.org/#concept-request-destination) value. You may also return a falsey value which will _not include_ the asset inside the manifest.\n\nBelow is the default `assets` parser:\n\n```js\nassets(filename) {\n  if (/\\.js$/i.test(filename)) return 'script';\n  if (/\\.(svg|jpe?g|png)$/i.test(filename)) return 'image';\n  if (/\\.(woff2?|otf|ttf|eot)$/i.test(filename)) return 'font';\n  if (/\\.css$/i.test(filename)) return 'style';\n  return false;\n}\n```\n\nWhen `assets` is an object, the assets' filenames are used as key lookups. Unmatched filenames are ignored and not included in the manifest. Because this could get _very_ verbose, the `function`-based approach is strongly recommended.\n\n\n#### options.format\nType: `Function`\n\nCustomize the `Asset` values.\n\nYou may use this function to modify the contents of the route chunks' `Asset` list. This also runs before the `headers` are produced.\n\n> **Important:** The `assets` and `filemap` your `options.headers` function receives are affected by any `options.format` changes.\n\nFor example, if we wanted to drop the `type` information from our `Asset` list:\n\n```js\nformat(assets) {\n  return assets.map(x => x.href);\n}\n```\n\n\n#### options.headers\nType: `true` or `Function`\n\nOptionally include (and customize) a \"headers\" section per manifest entry.\n\n> **Important:** When enabled, the output format of your manifest file will change! See [Manifest Contents](#manifest-contents) for details.\n\nWhen `true`, the default/internal function is used, which produces a [HTTP `Link` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) per pattern, pointing to the pattern's assets.\n\nYou may also provide a function to define your own `Link` header and/or add additional headers per route.<br>\nThis function will receive:\n\n* `assets` – the `Asset[]` files for the current route chunk\n* `pattern` – the current [route pattern](#route-patterns) string\n* `filemap` – the entire manifest file mapping (`{ [pattern]: Asset[] }`)\n\n> **Note:** An `Asset` is defined as `{ type: string, href: string }` shape.\n\n\n#### options.filename\nType: `String` or `false`<br>\nDefault: `rmanifest.json`\n\nThe output filename for the route manifest. <br>\nThis file is written to disk, relative to your Rollup configuration's output directory/file.\n\nWhen a falsey value (eg, `''`, `false`, `null`), no file is emitted.\n\n\n#### options.publicPath\nType: `String`<br>\nDefault: `'/'`\n\nA prefix to append to all `Asset` paths. This affects all files and headers, when enabled.\n\n> **Important:** A `publicPath` must end with a trailing slash.\n\n```js\n// rollup.config.js\nManifest({\n  inline: true,\n  publicPath: '/foobar/'\n  // ...\n})\n\n// in browser:\nconsole.log(window.__rmanifest['/']);\n//=> [\n//=>   { type: 'script', href: '/foobar/index.b0b86791.js' },\n//=>   { type: 'script', href: '/foobar/index.1c5aebde.js' },\n//=>   ...\n//=> ]\n```\n\n\n#### options.merge\nType: `Boolean`<br>\nDefault: `false`\n\nWhen enabled, and when a `\"*\"` chunk exists, the `\"*\"` contents are merged into all other route chunks.\n\n> **Note:** Any headers are merged too, if/when `options.headers` is enabled.\n\nAfter merging, the `\"*\"` chunk is **removed** from the final manifest. This is because its contents are already accounted for, reducing the amount of `route-manifest` (runtime) work.\n\n\n#### options.minify\nType: `Boolean`<br>\nDefault: `false`\n\nMinify the manifest's file contents.\n\n\n#### options.sort\nType: `Boolean`<br>\nDefault: `true`\n\nIf route patterns should be sorted by specificity. By default, this is `true` as to ensure the consumer/runtime (eg, [`route-manifest`](https://github.com/lukeed/route-manifest)) can find the correct entry for a URL path.\n\n> **Note:** See [Specificity](https://github.com/lukeed/route-sort#specificity) from `route-sort` documentation.\n\n\n#### options.inline\nType: `Boolean`<br>\nDefault: `true`\n\nAttempts to inline the manifest file directly into your main entry file (eg; `bundle.xxxxx.js`).<br>When successful, the manifest will be available globally as `window.__rmanifest`.\n\nWhile not required, it is strongly recommended that this option remains enabled so that the manifest contents are available to your Application _immediately_ upon loading. This saves a network request and the trouble of coordinating subsequent prefetches.\n\n> **Note:** A `rmanifest.json` will still be written to disk for easier developer analysis. You must define a falsey `option.filename` to prevent a disk write.\n\n\n## Route Patterns\n\nThe supported route pattern types are:\n\n* static – `/users`\n* named parameters – `/users/:id`\n* nested parameters – `/users/:id/books/:title`\n* optional parameters – `/users/:id?/books/:title?`\n* suffixed parameters – `/movies/:title.mp4`, `/movies/:title.(mp4|mov)`\n* wildcards – `/users/*`\n\n\n## Manifest Contents\n\nThe manifest file contains a JSON object whose keys are the [route patterns](#route-patterns) you've defined for your application via the [`options.routes`](#optionsroutes) mapping.\n\n> **Note:** There will often be a `\"*\"` key, which signifies your common/catch-all route.<br>\nThis typically contains your `bundle.(js|css)` files, and maybe some images that your main stylesheet requires.\n\nEach key will point to an \"Entry\" item whose data type will vary depending on your [`options.headers`](#optionsheaders) configuration. Either way, this Entry will always contain an \"Asset\" array, so let's define that first:\n\n```ts\ninterface Asset {\n  type: string;\n  href: string;\n}\n```\n\nNow, _without_ `options.headers` (default), the manifest pairs patterns directly to its list of Assets:\n\n```ts\ntype Entry = Asset[];\n// keys are `[pattern: string]`\ntype Manifest = Record<string, Entry>;\n\n// Example:\n//=> {\n//=>   \"/\": [\n//=>     { \"type\": \"script\", \"href\": \"/index.abc123.js\" },\n//=>     { \"type\": \"style\", \"href\": \"/index.d10eg4.css\" },\n//=>     // ...\n//=>   ],\n//=>   \"/:slug\": [...]\n//=> }\n```\n\nWith `options.headers` configured, each manifest Entry becomes object containing \"files\" and \"headers\" keys:\n\n```ts\ninterface Entry {\n  files: Asset[];\n  headers: any[]; // you decide its shape\n}\n\n// keys are `[pattern: string]`\ntype Manifest = Record<string, Entry>;\n\n// Example:\n//=> {\n//=>   \"/\": {\n//=>     \"files\": [\n//=>       { \"type\": \"script\", \"href\": \"/index.abc123.js\" },\n//=>       { \"type\": \"style\", \"href\": \"/index.d10eg4.css\" },\n//=>       // ...\n//=>     ],\n//=>     \"headers\": [\n//=>       // you decide\n//=>     ]\n//=>   }\n//=>   \"/:slug\": [...]\n//=> }\n```\n\nLastly, if `options.headers` is `true`, the default function runs, providing you with this format:\n\n```ts\ninterface Header {\n  key: string;\n  value: string;\n}\n\ninterface Entry {\n  files: Asset[];\n  headers: Header[];\n}\n\n// keys are `[pattern: string]`\ntype Manifest = Record<string, Entry>;\n\n// Example:\n//=> {\n//=>   \"/\": {\n//=>     \"files\": [\n//=>       { \"type\": \"script\", \"href\": \"/index.abc123.js\" },\n//=>       { \"type\": \"style\", \"href\": \"/index.d10eg4.css\" },\n//=>       // ...\n//=>     ],\n//=>     \"headers\": [\n//=>       {\n//=>         \"key\": \"Link\",\n//=>         \"value\": \"</index.abc123.js>; rel=preload; as=script; crossorigin=anonymous, ...\"\n//=>       }\n//=>     ]\n//=>   }\n//=>   \"/:slug\": [...]\n//=> }\n```\n\n## Related\n\n* [`webpack-route-manifest`](https://github.com/lukeed/webpack-route-manifest) – The webpack variant of this plugin.\n* [`route-manifest`](https://github.com/lukeed/route-manifest) – A tiny (412B) runtime to retrieve the correct entry from a Route Manifest file.\n* [`route-sort`](https://github.com/lukeed/route-sort) – A tiny (200B) utility to sort route patterns by specificity\n* [`quicklink`](https://github.com/GoogleChromeLabs/quicklink) – A 900B library to achieve faster subsequent page-loads by prefetching in-viewport links during idle time.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","readmeFilename":"readme.md"}