### Configure H5 Platform Settings with vite-plugin-uni-manifest
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
This snippet demonstrates how to configure H5 platform-specific settings including routing, development server, map SDKs, and build optimizations using `@uni-helper/vite-plugin-uni-manifest`. It requires the plugin to be installed and configured in your Vite setup. The configuration object directly maps to H5 platform settings within the uni-app manifest.
```typescript
// manifest.config.ts
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
export default defineConfig({
name: 'H5 Web Application',
appid: '__UNI__H5APP',
description: 'Web-based uni-app',
versionName: '1.2.0',
versionCode: 120,
'h5': {
title: 'My Web App',
// Router configuration
router: {
mode: 'history',
base: '/app/'
},
// Development server settings
devServer: {
https: false,
port: 8080,
disableHostCheck: true
},
// Public path for assets
publicPath: '/static/',
// Map SDK configurations
sdkConfigs: {
maps: {
// Tencent Map
qqmap: {
key: 'XXXXX-XXXXX-XXXXX-XXXXX'
},
// Google Maps
google: {
key: 'YOUR_GOOGLE_MAPS_API_KEY'
},
// Amap (Gaode Map)
amap: {
key: 'YOUR_AMAP_KEY',
securityJsCode: 'YOUR_SECURITY_CODE',
serviceHost: 'https://your-proxy-server.com'
},
// Baidu Map
bmap: {
key: 'YOUR_BAIDU_MAP_KEY'
}
}
},
// Async loading configuration
async: {
loading: 'AsyncLoading',
error: 'AsyncError',
delay: 200,
timeout: 60000
},
// Build optimization
optimization: {
prefetch: true,
preload: true,
treeShaking: {
enable: true
}
}
}
})
```
--------------------------------
### Integrate vite-plugin-uni-manifest with Vite Configuration
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
Demonstrates how to integrate the vite-plugin-uni-manifest into your Vite configuration file alongside other plugins like '@dcloudio/vite-plugin-uni'. This setup ensures that the manifest configuration is processed correctly during the build process.
```typescript
// vite.config.ts
import Uni from '@dcloudio/vite-plugin-uni'
import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
UniManifest({
minify: false,
insertFinalNewline: true,
cwd: process.cwd()
}),
Uni()
]
})
```
--------------------------------
### Update Runtime Configuration with vite-plugin-uni-manifest
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
This snippet illustrates how `vite-plugin-uni-manifest` automatically watches for changes in `manifest.config.ts` and regenerates `manifest.json` in real-time during development. No manual intervention is needed after initial setup. The plugin detects changes to app name, version, and mini-program specific settings.
```typescript
// The plugin sets up file watching automatically
// Changes to manifest.config.ts are detected and processed
// manifest.config.ts - make changes here
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
export default defineManifestConfig({
name: 'Updated App Name', // Change detected automatically
versionName: '1.1.0', // manifest.json regenerated
versionCode: 110,
'mp-weixin': {
appid: 'wx1234567890abcdef',
setting: {
urlCheck: false // Hot reload in development
}
}
})
// The generated manifest.json is automatically updated
// No manual intervention required
```
--------------------------------
### Configure Multi-Platform Settings for Uni-App
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
Configure settings for multiple platforms including App Plus, Alipay, Baidu, and HarmonyOS with platform-specific options. This snippet demonstrates how to set up base application info and platform-specific configurations using defineManifestConfig.
```typescript
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
export default defineManifestConfig({
name: 'Cross-Platform App',
appid: '__UNI__ABCDEFG',
description: 'Works on all platforms',
versionName: '2.1.0',
versionCode: 210,
// App Plus (iOS/Android native app) configuration
'app-plus': {
usingComponents: true,
nvueStyleCompiler: 'uni-app',
compilerVersion: 3,
splashscreen: {
alwaysShowBeforeRender: true,
waiting: true,
autoclose: true,
delay: 0
},
distribute: {
android: {
permissions: [
'',
'',
''
]
},
ios: {},
sdkConfigs: {}
}
},
// Alipay Mini Program configuration
'mp-alipay': {
usingComponents: true,
appid: '2021001234567890'
},
// Baidu Mini Program configuration
'mp-baidu': {
usingComponents: true,
appid: '1234567890'
},
// HarmonyOS Application configuration
'app-harmony': {
distribute: {
// HarmonyOS specific distribution settings
}
},
// Statistics configuration
uniStatistics: {
enable: true
}
})
```
--------------------------------
### Initialize Vite Plugin for uni-manifest
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
Initializes the Vite plugin instance for processing TypeScript-based manifest configurations and generating the manifest.json file. It accepts options to control output formatting and directory resolution.
```typescript
import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
UniManifest({
// Minify the output manifest.json (removes whitespace)
minify: false,
// Add newline at end of manifest.json file
insertFinalNewline: true,
// Custom working directory for resolving manifest.config
cwd: process.env.VITE_ROOT_DIR || process.cwd()
})
]
})
```
--------------------------------
### Configure Advanced WeChat Mini Program Settings
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
Configure advanced WeChat Mini Program features including plugins, workers, optimization, and cloud functions. This snippet shows how to set up WeChat-specific configurations like appid, compiler settings, plugins, workers, permissions, and cloud functions.
```typescript
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
export default defineManifestConfig({
name: 'Advanced WeChat Mini Program',
appid: '__UNI__WXAPP',
description: 'WeChat mini program with advanced features',
versionName: '1.5.0',
versionCode: 150,
'mp-weixin': {
appid: 'wx1234567890abcdef',
// Compiler settings
setting: {
es6: true,
enhance: true,
postcss: true,
minified: true,
urlCheck: true,
bigPackageSizeSupport: true,
babelSetting: {
outputPath: '@babel/runtime',
ignore: ['node_modules/**']
}
},
// Plugin configuration
plugins: {
'myPlugin': {
'version': '1.0.0',
'provider': 'wx1234567890'
}
},
// Worker threads configuration
workers: {
path: 'workers',
isSubpackage: false
},
// Required background modes
requiredBackgroundModes: ['audio', 'location'],
// Permission descriptions
permission: {
'scope.userLocation': {
desc: 'Location is used for nearby store search'
},
'scope.userLocationBackground': {
desc: 'Background location for delivery tracking'
}
},
// Navigation to other mini programs
navigateToMiniProgramAppIdList: [
'wx9876543210fedcba',
'wxabcdef1234567890'
],
// Cloud function root directory
cloudfunctionRoot: 'cloudfunctions/',
// Subpackage optimization
optimization: {
subPackages: true
},
// Lazy code loading
lazyCodeLoading: 'requiredComponents',
// Required private info APIs
requiredPrivateInfos: [
'getLocation',
'chooseLocation',
'chooseAddress'
]
}
})
```
--------------------------------
### Define uni-app Manifest Configuration with TypeScript
Source: https://context7.com/uni-helper/vite-plugin-uni-manifest/llms.txt
Provides a type-safe way to define the uni-app manifest configuration using TypeScript, offering IntelliSense support for all uni-app platforms and their specific settings. This function helps in writing robust and maintainable manifest files.
```typescript
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
export default defineManifestConfig({
name: 'My Uni App',
appid: '__UNI__1234567',
description: 'A cross-platform application',
versionName: '1.0.0',
versionCode: '100',
transformPx: false,
// Network timeout configuration
networkTimeout: {
request: 60000,
connectSocket: 60000,
uploadFile: 60000,
downloadFile: 60000
},
// Enable debug mode
debug: true,
// WeChat Mini Program specific config
'mp-weixin': {
appid: 'wx1234567890abcdef',
setting: {
urlCheck: false,
es6: true,
enhance: true,
minified: true,
minifyWXML: true,
minifyWXSS: true,
postcss: true
},
usingComponents: true,
permission: {
'scope.userLocation': {
desc: 'Your location will be used to show nearby stores'
}
}
},
// H5 platform configuration
'h5': {
title: 'My App Title',
router: {
mode: 'history',
base: '/app/'
},
devServer: {
https: false,
port: 3000,
disableHostCheck: true
},
sdkConfigs: {
maps: {
amap: {
key: 'your-amap-key',
securityJsCode: 'your-security-code'
}
}
}
}
})
```
--------------------------------
### Inject Viewport Meta Tag (JavaScript)
Source: https://github.com/uni-helper/vite-plugin-uni-manifest/blob/main/playground/index.html
This JavaScript code checks for CSS support of 'top: env(a)' or 'top: constant(a)' to determine if viewport-fit=cover should be included in the viewport meta tag. It then writes the meta tag directly to the document.
```javascript
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || CSS.supports('top: constant(a)'))
document.write( '')
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.