How to deploy Ionic 4 app to Github pages? - ionic-framework

I have a problem deploying Ionic 4 app to Github pages.
I tried follwing a tutorial for uploading Angular app but it does not work. It keeps throwing errors of all kinds.
Does anyone can help?
Thanks a lot.

Here is how to use angular-cli-ghpages with Ionic 4:
Create your Ionic project (ionic start MyApp blank)
Install the plugin: npm i angular-cli-ghpages --save
Connect your project with your github repository.
Navigate in the terminal to your project directory and execute ionic build --prod -- --base-href https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/, what will create the www folder, which is comparable to the dist folder for Angular. It also sets your github page domain as base href in index.html.
Then run the plugin: npx angular-cli-ghpages --dir=www. The flag at the end points to the www folder, where the index.html file is located that will be displayed at https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/. The plugin will create a branch called "gh-pages" in your project that contains all files which are located in your www folder.
As a last step you have to select the "gh-page" branch in the settings of your project (https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/settings) as a source for your github page.
You can also set different branch names if you don't want to use the default "gh-pages" name (also master is possible, but then you should keep the source files in a different branch). Just run the plugin like this: npx angular-cli-ghpages --branch=BRANCH-NAME --dir=www.
Like Gary Großgarten suggested, you can create a script for it which makes it easier. For Ionic it would be: ionic build --prod -- --base-href https://YOUR_GITHUB_USERNAME.github.io/YOUR_PROJECT_NAME/ && npx angular-cli-ghpages --branch=BRANCH-NAME --dir=www
I was looking for a proper solution myself, credits go to Juangui Jordán's blog.

I'm using https://github.com/angular-schule/angular-cli-ghpages to achieve this easily.
Just add
"scripts": {
...
"gh-pages": "ng build --base-href 'https://USERNAME.github.io/REPOSITORY_NAME/' --prod && npx ngh --dir=www/"
...
}
to your package.json.
If you want a costum domain you can add the cname flag
--cname=example.com
to the ngh command.
To build and upload your site run
npm run gh-pages

Just a note: For a gitlab repository (not Github) you can do this:
.gitlab-ci.yml:
pages:
image: node:latest
stage: deploy
script:
- npm install -g ionic cordova
- npm install
# frontend application is served at https://what-digital.gitlab.io/stemba/
# we need to set the basePath to the sub dir
- ionic build --prod -- --base-href="https://what-digital.gitlab.io/gitlab-pages/"
- rm -rf public
- mkdir public
- cp -r www/* public
artifacts:
expire_in: 1 week
paths:
- public
only:
- dev

Related

"flutter channel stable" failed in docker image: cirrusci when publish pages to gitlab

I'm trying to publish my flutter page on gitlab which is the git host of my project. I'm using the ci configure like the following(from this post)
gitlab page CI configure
image: cirrusci/flutter:latest
before_script:
- flutter channel stable
- flutter upgrade
- flutter config --enable-web
- flutter pub get
pages:
stage: deploy
script:
- flutter build web
- cp -r build/web public
artifacts:
paths:
- public
only:
- live
The ci job failed in an error like:
...
$ flutter channel stable
Switching to flutter channel 'stable'...
git: fatal: 'origin/stable' is not a commit and a branch 'stable' cannot be created from it
Switching channels failed with error code 128.
...
What's the problem?
One thing worth to note is my flutter project locate in a subdirectory(ie., my-flutter-dir) of the repository root. Is it the reason? How to configure the CI script in this situation?
I've tried to add a cd my-flutter-dir as the first command in the before_script, but it still result in the same error.
It's turn out being an issue of the docker image. After I removed the flutter channel and flutter upgrade command in the befor_script part, everything is ok now.
Note if you have the flutter project in a subdirectory under the repository root, still you need to add cd you-flutter-dir command in the before_script. Also don't forget to put the .gitlab-ci.yml file in the root of the repository.

Electron run by Capacitor in Ionic 5: console logging and live reload not working

I've used Electron standalone before, and console.log() commands in main.js worked just fine (output to IDE console) and the electron-reload module also worked fine when content changes were detected in the Electron root folder.
I've now started a new Ionic 5 project, and added Electron to the project via Capacitor. Capacitor makes a few necessary changes to Electron (e.g. renaming main.js to index.js etc), I've now also have to start electron via capacitor npx cap open electron.
In doing so, console.log() commands in index.js are now NOT being output to the IDE console, errors are not being output to console, and the electron-reload module now serves a blank page when changes are detected… the only console output that I get is:
$ npx cap open electron
[info] Opening Electron project at ...
Is this a capacitor limitation or what configurations must be done to make this work ?
#ionic/cli#6.10.0
#capacitor/core#2.2.0
electron#8.3.1
also updated electron to latest 9.0.4 - same result.
here are steps to reproduce this:
# install ionic CLI
$ npm install -g #ionic/cli
# create project w/ capacitor
$ ionic start <project name> blank --type=angular --capacitor
# create initial build, needed by cap for electron
$ cd <ionic_project_folder>
$ ionic build
# add electron via cap
$ npx cap add electron
# run electron
$ npx cap open electron
if you enter console.log messages in electron’s index.js, none of them will be logged…
figured it out. Capacitor blocks all log messages by default, but you can run npm run electron:start from within the /electron folder and you'll get all log messages... HTH someone.

How to make a prod build in "Ionic upload" command?

I want to use Ionic deploy service in Ionic cloud.
When I run ionic upload command, a dev build is immediately triggered instead of prod build.
Is it possible to create a --prod build and upload?
One of major reasons is that multiple configurations in my code are bundled with --prod build only.
ionic upload --deploy=dev
[INFO] Running app-scripts build:
[09:55:59] build dev started ...
[09:55:59] clean started ...
[09:55:59] clean finished in 1 ms
You could pipe the npm scripts to run the ionic --prod first and then ionic upload
"scripts":{
"custom-upload":"ionic cordova build --prod | ionic upload"
}
and then run in the terminal
$: npm custom-upload
This will still run the dev build i think but your prod build should be packaged as well. It does not look like you can specify a build type in the ionic upload command, which makes me think that the ionic upload does not upload the production build to ionic view. And if that is that case then you might want to consider changing the configurations setup in a prod build to be set to only be used if not on localhost instead on based on the build.

Ionic2 Build folder structure missing

I'm starting to learn Ionic2, I have created a new project with ionic start myproject --v2 and everything works correctly if I do ionic serve.
The build folder is missing in ionic 2 project folder.
Whenever I am trying to download any existing Ionic2 template in that one also build folder missing.
ionic -v 2.0.0-beta.30
cordova -v 6.2.0
node -v v6.2.1
npm -v 3.9.5
your ionic serve build is under www. The native builds ( from ionic build) are under platform.
A little late but I had the same issue and was able to fix it by installing Gulp :
npm install -g gulp
Then I did gulp build.
This solved my issues and generated the build folder as it was supposed to.
First you need to add support for the platform/s you are working with, by executing from Ionic CLI console:
ionic platform add android
or
ionic platform add ios
And then you should build your project by executing:
ionic build android
or
ionic build ios

How to specify ionic build folder in CLI

I have a ionic app and to build the project in android I use the command
ionic build android
It works fine and i'm able to build the project.
However if I want to specify an external folder in the path like...
ionic d:\Projects\mobile build android
How can I achieve this ?
You can do this. If you have an ionic:build npm script defined it will call that to do the build.
"scripts":{
"ionic:build": "ionic-app-scripts build android --release --prod --wwwDir www --buildDir build"
}
For achieving your goal there is one more way. Instead of passing the path in the ionic commands ( Which is not a valid command ), you can first reach to the path where you want to build ionic application using cd command.
In your case it would be first go to d drive by using
d:
then
cd \Projects\mobile.
After this you can run command
ionic build android