use Document.tsx
as html template.
install
pnpm i vite-plugin-document -D
usage
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import document from 'vite-plugin-document'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), document()],
})
create src/Document.tsx
file, add follow code
import React from 'react'
const Document = () => {
return (
<html lang="en">
<head>
<meta charSet="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
)
}
export default Document
check playground for more details
solidjs
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
import document from 'vite-plugin-document'
// https://vitejs.dev/config/
export default defineConfig({
// ssr: true is required
plugins: [solid({ ssr: true }), document({ solidjs: true })],
})
inline scripts
<script
dangerouslySetInnerHTML={{
__html: `mark('head')`,
}}
/>
options
documentFilepath
Custom Document.tsx
filepath
- type
string
- default
<rootDir>/src/Document.tsx
outDir
In build mode, vite-plugin-document
will bundle <rootDir>/src/Document.tsx
into disk
- type
string
- default
<rootDir>/.vite-document
solidjs
Current framework is solidjs
, when solidjs
is undefined
automatic set to true
if vite-plugin-solid
is found in vite plugins list.
- type
boolean
- default
<automatic detect>
development
-
Setup -
pnpm i
-
Build -
pnpm build
built with