2.0.1 • Published 5 years ago
vite-plugin-mobile v2.0.1
vite-plugin-mobile
- Serve different modules based on the user agent.
- Build separate bundles for mobile and desktop.
- Easily share modules between them.
import mobile from 'vite-plugin-mobile'
export default {
plugins: [
mobile(),
]
}
Options
mobileRoot: string
The directory containing mobile-only modules.
Defaults to"/src/mobile"desktopRoot: string
The directory containing desktop-only modules.
Defaults to"/src/desktop"mobilePlugins: VitePlugin[]
Vite plugins for the mobile bundle only.
These are called onvite buildonly.
Notes
- Your
vite.config.jsmodule is executed twice (for desktop then mobile). Your config can check ifprocess.env.IS_MOBILEis truthy if it needs to disable certain plugins for the mobile bundle. - "Common chunks" are not generated, so bundles will contain duplicate modules.
- Assets in
public/are shared between bundles. - Your
index.htmlis rendered once per bundle. - The desktop bundle is used by
${outDir}/index.html. - The mobile bundle is used by
${outDir}/index.mobile.html. - In production, your server will need to manually detect which
.htmlpage is appropriate based on theUser-Agentrequest header. You can usewants-mobilefor this.