The copy-native-resources.ts plugin is designed for UniApp projects built with the unibest framework. It solves the issue where native plugins are not found after packaging by automatically copying local native plugin resources from your project root to the build directory during the Vite writeBundle phase.
Prerequisites
Ensure your native plugins follow the UniApp official specification and are stored in the nativeplugins directory at your project root:
项目根目录/
├── nativeplugins/
│ ├── YourPluginName/
│ │ ├── android/
│ │ ├── ios/
│ │ └── package.json
import { createCopyNativeResourcesPlugin } from './vite-plugins/copy-native-resources'
export default defineConfig({
plugins: [
// ...
createCopyNativeResourcesPlugin(
UNI_PLATFORM === 'app' && VITE_COPY_NATIVE_RES_ENABLE === 'true',
{
verbose: mode === 'development',
},
),
],
})