从 Cordova 迁移到 Capacitor
Migrating from Cordova to Capacitor
您好,我决定在我的 Ionic/Angular 项目中从 Cordova 迁移到 Capacitor。我按照说明 https://capacitorjs.com/docs/v2/getting-started/with-ionic
创建了一个新的电容器项目
现在我已经安装了一些插件,您可能会在我附上的屏幕截图中看到。
我将应用程序文件夹从我的 cordova 项目复制粘贴到我的新电容器应用程序文件夹中。
很明显,我收到了模块错误,您可能会在随附的屏幕截图中看到。
我不指望有人能帮我解决这些问题,但是有人可以写信告诉我接下来我应该做什么吗?一一追踪node_modules?我相信任何建议都会对我有所帮助。
这是app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule, Meta } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { IonicStorageModule } from '@ionic/storage';
import { Facebook } from '@capacitor-community/facebook-login';
import { AppData } from './services/app-data/app-data';
import { UserData } from './services/user-data/user-data';
import { TranslateConfigService } from './services/translate/translate.service';
import { LazyLoadImageModule } from 'ng-lazyload-image';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { StreamingMedia, StreamingVideoOptions } from '@ionic-native/streaming-media/ngx';
import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@ionic-native/media-capture/ngx';
import { Media, MediaObject } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
import { Device } from '@ionic-native/device/ngx';
import { FileChooser } from '@ionic-native/file-chooser/ngx';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { NativeGeocoder } from '@ionic-native/native-geocoder/ngx';
import { Share } from '@capacitor/share';
//import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { IOSFilePicker } from '@ionic-native/file-picker/ngx';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { IonMarqueeModule } from "./ion-marquee"
import { FCM } from '@capacitor-community/fcm';
import { GooglePlus } from '@ionic-native/google-plus/ngx';
import { Push } from '@ionic-native/push/ngx';
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFirestoreModule } from "@angular/fire/firestore";
import { environment } from '../environments/environment';
import { UserProfileModalPageModule } from './pages/user-profile-modal/user-profile-modal.module';
import { UserProfilePopoverComponent } from './components/user-profile-popover/user-profile-popover.component';
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { Globalization } from '@ionic-native/globalization/ngx';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
}
@NgModule({
declarations: [AppComponent, UserProfilePopoverComponent],
entryComponents: [UserProfilePopoverComponent],
imports: [
BrowserModule,
IonicModule.forRoot(
{ animated: false }
),
HttpClientModule,
BrowserModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
AppRoutingModule,
LazyLoadImageModule,
IonicStorageModule.forRoot(),
HttpClientModule,
IonMarqueeModule,
//AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
FormsModule,
ReactiveFormsModule,
AngularFirestoreModule,
UserProfileModalPageModule
],
providers: [
StatusBar,
Facebook,
AppData,
UserData,
TranslateConfigService,
SplashScreen,
Camera,
StreamingMedia,
Device,
MediaCapture,
Media,
FileTransfer,
FCM,
Meta,
Globalization,
TranslateService,
Share,
Geolocation,
NativeGeocoder,
IOSFilePicker,
File,
FileChooser,
FileTransfer,
FileTransferObject,
GooglePlus,
Push,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent]
})
export class AppModule { }
看看https://capacitorjs.com/cordova
还有https://ionicframework.com/docs/intro/upgrading-to-ionic-6
您的旧插件只支持cordova,您需要先删除一个旧插件,然后一个一个安装新插件。
# Remove a Cordova plugin
npm uninstall cordova-plugin-name
npx cap sync
# Delete Cordova folders and files
rm config.xml
rm -R platforms/ plugins/
要安装新插件,请参见例如
https://ionicframework.com/docs/native/splash-screen
现在我已经安装了一些插件,您可能会在我附上的屏幕截图中看到。
我将应用程序文件夹从我的 cordova 项目复制粘贴到我的新电容器应用程序文件夹中。
很明显,我收到了模块错误,您可能会在随附的屏幕截图中看到。
我不指望有人能帮我解决这些问题,但是有人可以写信告诉我接下来我应该做什么吗?一一追踪node_modules?我相信任何建议都会对我有所帮助。
这是app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule, Meta } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { IonicStorageModule } from '@ionic/storage';
import { Facebook } from '@capacitor-community/facebook-login';
import { AppData } from './services/app-data/app-data';
import { UserData } from './services/user-data/user-data';
import { TranslateConfigService } from './services/translate/translate.service';
import { LazyLoadImageModule } from 'ng-lazyload-image';
import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
import { StreamingMedia, StreamingVideoOptions } from '@ionic-native/streaming-media/ngx';
import { MediaCapture, MediaFile, CaptureError, CaptureImageOptions } from '@ionic-native/media-capture/ngx';
import { Media, MediaObject } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
import { Device } from '@ionic-native/device/ngx';
import { FileChooser } from '@ionic-native/file-chooser/ngx';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { NativeGeocoder } from '@ionic-native/native-geocoder/ngx';
import { Share } from '@capacitor/share';
//import { SocialSharing } from '@ionic-native/social-sharing/ngx';
import { IOSFilePicker } from '@ionic-native/file-picker/ngx';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { IonMarqueeModule } from "./ion-marquee"
import { FCM } from '@capacitor-community/fcm';
import { GooglePlus } from '@ionic-native/google-plus/ngx';
import { Push } from '@ionic-native/push/ngx';
import { AngularFireModule } from '@angular/fire';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFirestoreModule } from "@angular/fire/firestore";
import { environment } from '../environments/environment';
import { UserProfileModalPageModule } from './pages/user-profile-modal/user-profile-modal.module';
import { UserProfilePopoverComponent } from './components/user-profile-popover/user-profile-popover.component';
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { Globalization } from '@ionic-native/globalization/ngx';
export function HttpLoaderFactory(http: HttpClient) {
return new TranslateHttpLoader(http, "./assets/i18n/", ".json");
}
@NgModule({
declarations: [AppComponent, UserProfilePopoverComponent],
entryComponents: [UserProfilePopoverComponent],
imports: [
BrowserModule,
IonicModule.forRoot(
{ animated: false }
),
HttpClientModule,
BrowserModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
AppRoutingModule,
LazyLoadImageModule,
IonicStorageModule.forRoot(),
HttpClientModule,
IonMarqueeModule,
//AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFireAuthModule,
FormsModule,
ReactiveFormsModule,
AngularFirestoreModule,
UserProfileModalPageModule
],
providers: [
StatusBar,
Facebook,
AppData,
UserData,
TranslateConfigService,
SplashScreen,
Camera,
StreamingMedia,
Device,
MediaCapture,
Media,
FileTransfer,
FCM,
Meta,
Globalization,
TranslateService,
Share,
Geolocation,
NativeGeocoder,
IOSFilePicker,
File,
FileChooser,
FileTransfer,
FileTransferObject,
GooglePlus,
Push,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
bootstrap: [AppComponent]
})
export class AppModule { }
看看https://capacitorjs.com/cordova
还有https://ionicframework.com/docs/intro/upgrading-to-ionic-6
您的旧插件只支持cordova,您需要先删除一个旧插件,然后一个一个安装新插件。
# Remove a Cordova plugin
npm uninstall cordova-plugin-name
npx cap sync
# Delete Cordova folders and files
rm config.xml
rm -R platforms/ plugins/
要安装新插件,请参见例如 https://ionicframework.com/docs/native/splash-screen