{"_id":"vite-plugin-multipage","_rev":"30-7b8ead9a669975e43222fefd3a113f97","time":{"0.2.2":"2021-08-10T21:52:35.679Z","created":"2021-08-12T04:41:41.729Z","1.0.0":"2021-08-12T04:41:41.897Z","modified":"2022-05-23T08:34:21.991Z"},"name":"vite-plugin-multipage","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"vite-plugin-multipage","description":"Adds multi-page application support to Vite.","version":"1.0.0","main":"index.js","license":"0BSD","scripts":{"format":"prettier --write .","lint":"eslint --fix ."},"devDependencies":{"eslint":"^7.32.0","eslint-config-prettier":"^8.3.0","prettier":"^2.3.2"},"dependencies":{"mime-types":"^2.1.32","shelljs":"^0.8.4","url":"^0.11.0"},"gitHead":"fea779859352be105d70c549e6a9632623458a2d","_id":"vite-plugin-multipage@1.0.0","_nodeVersion":"16.6.1","_npmVersion":"7.20.5","dist":{"integrity":"sha512-S7f6ySPo6EZW/badia/kunwEPfOFnL4RFyYi/OPmrl4Q4UMyKBfjEpFNVOWb2e/9WHmFs19uzPWNmmhPI4Wdsw==","shasum":"7e92675a1e62896b99e347ba76ca2422a8985558","tarball":"https://registry.npmjs.org/vite-plugin-multipage/-/vite-plugin-multipage-1.0.0.tgz","fileCount":5,"unpackedSize":9610,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFKaFCRA9TVsSAnZWagAAR1sP/AiFgC4QW6mV1aFMgI+u\n4nMiN1scAFkIixgUxPoivCy9TyHntdOXyAl8dWS+xx24FdNIgJysiBDtT0O+\nbSCpcWBMcRYM2E9WaOxddi3RB0zDm76/CwB3jac1I/Jtj67A2R60Pc2pU1Eh\ndEOI9mSaPoukfOL9EdWyleKPKKoXAA2dorpsZAWZAWIOGIQsevKfvf9E+o3W\neBqPJ5ZSoeJ21XNjnDcqcKOoqApBN0W6u0qAXM3P70QzESoMJI7jPH9jcSWu\nNrXEETnclIM/jFAtbohHsP/ea2810HvkhXpOQBNMwE5BrPtgAnbp4lZF+V38\ndaCkBPz8zHqqdCIkSS3u9/1TD/yw6KIKJDiU6nl+xblA0JR8hVqHnBRqN1g+\ngEsWh4BxSownpgOnJQbzXANV+Uz56MGoXeUH/b39EMcUie78QsYGt86Lrusf\nFBiCM1/z26bAQmVhpXcascdHVJNjcjtWh1R4uXZoMGGGQD13QiQMaqQslIyI\n6b/F/3kqCPFjCtnKh8EgU1pMvOVaaVTfIpcbp54QFmSc8CU09SKU8jOYHLUn\nEaHNfx8XMWeHY1Twb8+x3Z6bTEUG+Jb9qZ415MycDjOc5f7t0u4Jv3insEDo\nitT2ZFKOjkFqOPM1L0MhH8393flemxZiPZlzhW/TypYEqlV6IljLH8RMvsEn\nTVxS\r\n=G4r6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+wshtvMUNHJ8BCrpauJkN+5UmYoIktOqzhDP4NrJg5AIgJ8ttrg14Gl54PObUM1v7FKO8g/uSjQ/l0aIUoUFCSg8="}]},"_npmUser":{"name":"sleep909","email":"almosttransparentblue@outlook.com"},"directories":{},"maintainers":[{"name":"sleep909","email":"almosttransparentblue@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vite-plugin-multipage_1.0.0_1628743301730_0.6637234398693104"},"_hasShrinkwrap":false}},"maintainers":[{"name":"sleep909","email":"almosttransparentblue@outlook.com"}],"description":"Adds multi-page application support to Vite.","license":"0BSD","readme":"# vite-plugin-multipage\n\n> Adds multi-page application support to Vite.\n\n## Installation & Usage\n\nFirst:\n\n```shell\nnpm i --save-dev vite-plugin-multipage\n```\n\nThen, in `vite.config.js`, something like this:\n\n```javascript\nimport { defineConfig } from \"vite\";\nimport solid from \"vite-plugin-solid\";\nimport multipage from \"vite-plugin-multipage\";\n\nexport default defineConfig({\n  plugins: [\n    solid(),\n    multipage({\n      // This is an optional object, defaults as follows:\n      mimeCheck: true /* mimeCheck: Set the MIME type on each request using\n                         `mime-types.lookup()` */,\n      open: \"/\" /* open: Path to load when starting the server.\n                   May be left empty and not open anything. */,\n      pageDir: \"pages\" /* pageDir: Path to the directory with the pages. */,\n      purgeDir: \"pages\" /* purgeDir: Path to be removed after building.\n                           May be left empty to remove nothing. */,\n      removePageDirs: true /* removePageDirs: Change the final result from\n                               \"./page/index.html\" to \"./page.html\". */,\n      rootPage: \"index.html\" /* rootPage: The entry point into each page. */,\n    }),\n  ],\n\n  resolve: {\n    alias: {\n      \"@\": path.resolve(__dirname, \"./\"),\n    },\n  },\n\n  build: {\n    target: \"esnext\",\n    polyfillDynamicImport: false,\n  },\n});\n```\n\n## What does it do?\n\nThis plugin extends Vite to handle collections of single-page applications.\nBy following a simple and adjustable naming convention, Vite will ultimately\nbundle your collection of pages as:\n\n```\nbuild.outDir: (./dist, by default)\n\n   ./assets/   ./index/index.html   ./pagetwo/index.html ... ./pagetwenty/index.html\n```\n\nThe project directory for the above would maybe look like:\n\n```\n  |--- ./package.json\n  |--- ./vite.config.js\n  |--- ./assets/\n  |--- ./components/\n  |--- ./pages/  # This is set by $pageDir.\n       |--- ./index/\n            |--- ./views/\n            |--- ./index.css\n            |--- ./index.html\n            |--- ./index.jsx\n       |--- ./pagetwo/\n            |--- ./index.css\n            |--- ./index.html # The HTML *must* match $rootPage!\n            |--- ./index.jsx\n       [....]\n       |--- ./pagetwenty/\n            |--- ./index.css\n            |--- ./index.html\n            |--- ./index.jsx\n```\n\nThe contents of `./pagetwo/index.html` would resemble:\n\n```html\n<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <title>example page</title>\n    <link rel=\"icon\" href=\"/assets/favicon.ico\" />\n    <meta charset=\"utf-8\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n  </head>\n  <body>\n    <noscript>you need to enable javascript to run this app</noscript>\n    <div id=\"root\"></div>\n    <script src=\"/pages/pagetwo\" type=\"module\"></script>\n  </body>\n</html>\n```\n\nAnd `./pagetwo/index.jsx`:\n\n```javascript\nimport { render } from \"solid-js/web\";\n\nimport \"./index.css\";\nimport logo from \"@/assets/logo.svg\";\n\nfunction App() {\n  return (\n    <div>\n      <header>\n        <img src={logo} alt=\"logo\" />\n        <p>you are on page 2 :(</p>\n        <a href=\"/pagetwenty\">go to page 20 !</a>\n      </header>\n    </div>\n  );\n}\n\nrender(App, document.getElementById(\"root\"));\n```\n\n## What's the catch?\n\nThere are some small caveats to keep in mind with this setup and it is all\nrelated to path resolving.\n\nHTML files must link to files from the perspective of the project root. The\nonly allowed shortcut is that you may omit the `.jsx` in links and the entire\n`/index.jsx`, such as using `/pages/foo` instead of `/pages/foo/index.jsx`.\n\nJSX files need an `@` alias to point to the project root when linking to\n`./assets/` and similar other files. It is not available from inside HTML.\nOtherwise the linking perspective is from that of the current file directory.\n\nYou have several options when linking between pages from JSX due to link\nrewriting that this plugin does with the Vite server:\n\n- `href=\"/\"` will point to `/pages/index/index.html`.\n- `href=\"/foo\"` will point to `/pages/foo/index.html`.\n- `href=\"/foo.html` will also point to `/pages/foo/index.html`.\n- `href=\"/foo/index.html` will also point to `/pages/foo/index.html`.\n\nWhat convention you select to use will depend on your configuration of\n`removePageDirs` and if you will be doing path or hash based routing:\n\n- Path based routing: `removePageDirs: false`, use `href=\"/foo\"`\n- Hash based routing: `removePageDirs: true`, use `href=\"/foo.html\"`\n- Single page sites: `removePageDirs: true`, use `href=\"/\"`\n\nThis plugin will rewrite `/foo` to `/pages/foo/index.html` to allow for\nin-page path routing libraries to function. You will be responsible for doing\nsimilar in your production server, where `/foo` should be mapped to either\n`/foo/index.html` or `/foo.html` depending on how `removePageDirs` is set.\n\nFinally, the `$purgeDir` directory is removed. This typically will be the same\npath as `$pageDir`, however in the case of `$pageDir` being set to `src/pages`\nyou will likely wish to set `$purgeDir` to `src` rather than `src/pages`. This\nis up to you, depending if you use the `src` prefix directory and if you have\nother directories you would like copied to the final build directory.\n\n## License\n\n0BSD\n","readmeFilename":"README.md"}