@caspeco/vite-plugin-shell
v0.2.0
Published
Vite plugin that adds the shared RMS HTML (navigation, title, favicons) to index.html
Keywords
Readme
@caspeco/vite-plugin-shell
Vite plugin that adds the shared RMS HTML to the app's index.html: the navigation, title, favicons and theme color, the same in every app.
Setup
npm install --save-dev @caspeco/vite-plugin-shellAdd it to
vite.config.ts:import caspecoShell from "@caspeco/vite-plugin-shell"; export default defineConfig({ plugins: [caspecoShell()], });In
index.html, wrap your app's root element in<caspeco-layout>(written exactly like that, no attributes), and add comments so the next developer knows where the rest comes from:<head> + <!-- @caspeco/vite-plugin-shell adds charset, viewport, title, favicons, theme-color and the navigation here --> <link rel="manifest" href="/manifest.json" /> </head> <body> + <caspeco-layout> + <!-- @caspeco/vite-plugin-shell adds <caspeco-top-bar> and <caspeco-navigation> here --> <div id="root"></div> + </caspeco-layout> <script type="module" src="/src/main.tsx"></script> </body>Delete your own
<meta charset>,<meta name="viewport">,<title>, favicons (<link rel="icon">,<link rel="apple-touch-icon">) and<meta name="theme-color">. The plugin adds its own.
What it adds
The dev server and vite build add this to index.html (vite build writes it to dist/index.html). First in <head>:
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Caspeco</title>
<link rel="stylesheet" href="/shell-assets/navigation/v3/index.css" />
<script type="module" src="/shell-assets/navigation/v3/index.js" blocking="render"></script>
<link rel="icon" type="image/svg+xml" href="/shell-assets/favicon/icon.svg" />
<link rel="icon" type="image/png" sizes="16x16" href="/shell-assets/favicon/favicon-16.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/shell-assets/favicon/favicon-32.png" />
<link rel="icon" type="image/png" sizes="192x192" href="/shell-assets/favicon/icon-192.png" />
<link rel="icon" type="image/png" sizes="512x512" href="/shell-assets/favicon/icon-512.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/shell-assets/favicon/apple-touch-icon.png" />
<meta name="theme-color" content="#fdfdfd" />First in <caspeco-layout>:
<caspeco-top-bar class="casper-ui-theme"></caspeco-top-bar>
<caspeco-navigation class="casper-ui-theme"></caspeco-navigation>- The URLs are on the app's own domain, which serves
/shell-assets/*in every environment. They don't get Vite'sbase. The dev server proxies/shell-assets/*totarget. - Errors: when
index.htmlhas no<caspeco-layout>or has its own title, favicons etc.,vite buildfails and the dev server shows the error instead of the page. - Updates: a new plugin version can change the HTML, see the changelog. Check your app after updating.
Options
| Option | Default | Description |
| --------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| target | "https://rms.dev.caspeco.net" | Where the dev server sends /shell-assets/* requests, e.g. "https://rms.stage.caspeco.net" |
| navigationUrl | "/shell-assets/navigation/v3/" on target | Where the dev server gets the navigation from, e.g. a pull request deploy "https://webcomponents.dev.caspeco.net/<pr-tag>/v3/" |
| allowZoom | true | false adds maximum-scale=1, user-scalable=no to the viewport. Fails WCAG 1.4.4, only for apps that can't do without it |
target and navigationUrl only affect the dev server, the built index.html is the same for every environment.
