-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide platform (and other metadata) when generating configs #3976
Comments
I was going to open an issue about it! It will be really useful for development too : import type { CapacitorConfig } from '@capacitor/cli';
import getInternalIp from "internal-ip";
let server: CapacitorConfig["server"] = {};
if (process.env.CAPACITOR_PLATFORM === "android") {
server.cleartext = true;
server.url = `http://${getInternalIp.v4.sync()}:3000`;
} else if (process.env.CAPACITOR_PLATFORM === "ios") {
server.url = "http://localhost:3000";
}
const config: CapacitorConfig = {
appId: 'pro.clovis.app',
appName: 'Clovis',
android: {
path: 'platforms/android',
},
bundledWebRuntime: false,
ios: {
path: 'platforms/ios'
},
server,
webDir: 'platforms/web',
};
export default config; |
I would appreciate this.
|
Since there are already Personally, I have an app that, for various reasons, has a different id on Android to iOS so I would benefit from |
it's works or not , use process.env in Capacitor File ? |
To retain all data in the web view IndexedDB when updating from Cordova builds, it is necessary to retain the same origin for the app files the Cordova version used. Both the scheme and the hostname are different between iOS and Android, but Capacitor only support changing the scheme natively per platform. As a workaround, the configuration now dynamically parses its own command line arguments to determine the platform that is currently being configured. Until Capacitor exposes the current platform in a documented way (see ionic-team/capacitor#3976), this will have to suffice. This slightly changes the workflow. Now, it is not possible to run "npx cap sync" anymore to sync all platforms. Instead, the platforms must be synced separately, for example using "npx cap sync android" and "npx cap sync ios". For convenience, the command "npm run capsync" is also provided to sync all platforms. Note that the project currently only contains an Android target. The ios target must be added to the "npm run capsync" command once it is part of the repository.
When we run
npx cap sync
withcapacitor.config.{ts,js}
files, we can provide context (e.g. with environment variables) so app developers can differentiate configuration values based on it.For example,
launchShowDuration
can be0
for iOS and3000
for Android:import { CapacitorConfig } from '@capacitor/cli'; const config: CapacitorConfig = { appId: 'com.capacitorjs.testapp', appName: 'capacitor-testapp', webDir: 'build', plugins: { SplashScreen: { + launchShowDuration: process.env.CAPACITOR_PLATFORM === 'ios' ? 0 : 3000, }, }, }; export = config;
An alternative would be to provide
Platform.select()
like React Native (see #3977). Example:The text was updated successfully, but these errors were encountered: